热门标签 | HotTags
当前位置:  开发笔记 > 编程语言 > 正文

画布。绘制位图(位图,null,RectF,null)不绘制-canvas.drawBitmap(bitmap,null,RectF,null)notdrawing

Imtryingtogetabitmapimagetobedrawnonmycanvasinmyandroidproject.Ivebeenatitfor

I'm trying to get a bitmap image to be drawn on my canvas in my android project. I've been at it for over two days now and just can't seem to figure it out. I attached the code where the function's being called.

我试图在我的android项目的画布上画一个位图图像。我已经做了两天多了,似乎就是搞不清楚。我附加了调用函数的代码。

private void drawLogo(Canvas canvas)
{
    Paint test = new Paint();
    test.setColor(Color.RED);
    test.setStrokeWidth(4);
    test.setStyle(Style.FILL_AND_STROKE);

    //Here was my problem
    //Changed to --> new RectF(scale_x, scale_y, 5*scale_x, 5*scale_y) and works now
    RectF logoSize = new RectF(scale_x, 5*scale_y, 5*scale_x, scale_y);

    Bitmap logoBitmap = getImageMap().get("LOGO");

    canvas.drawRect(logoSize, test);

    canvas.drawBitmap( logoBitmap, null, logoSize, null );
}

The canvas.drawRect( RectF, Paint ) method draws the rectangle correctly, but the bitmap does not show up at all. Any insight would be greatly appreciated, thanks in advance.

画布上。绘制矩形(RectF, Paint)方法正确绘制矩形,但是位图根本不显示。如有任何见解,我们将不胜感激,谢谢。

EDIT: I added code from my getImageMap() method as requested. It basically just returns all the images in my assets/images/ folder as a Map, so I can easily pull any image I want from the folder.

编辑:我按照要求添加了getImageMap()方法中的代码。它基本上只返回我的资产/图像/文件夹中的所有图像作为映射,因此我可以轻松地从文件夹中提取任何图像。

private Map getImageMap()
{
    if (imageMap == null)
    {
        imageMap = new HashMap();
        try
        {
            String[] files = getContext().getAssets().list("images");

            for (String imageName : files)
            {
                // Construct a BitMap from an asset
                Bitmap bitmap = BitmapFactory.decodeStream(
                    getContext().getAssets().open("images/" + imageName));
                imageMap.put(imageName.replaceFirst("\\..*", ""), bitmap);
            }
        }
        catch (IOException e) {Log.e("assets/images/ is empty", "IOException", e);}
    }
    return imageMap;
}

EDIT2: I found my misstake, I updated it in the code. I just wanna thank those who gave me speedy feedback, I appreciate it.

EDIT2:我发现了我的错误,我在代码中更新了它。我只是想感谢那些给我快速反馈的人,我很感激。

1 个解决方案

#1


0  

Try something simple:

尝试一些简单:

canvas.drawBitmap(logoBitmap, logoSize.left, logoSize.top, null);

Regards.

的问候。


推荐阅读
author-avatar
CK92_474
这个家伙很懒,什么也没留下!
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有