本文介绍了y +高度在Android中必须为< = bitmap.height()的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想创建另一个位图,但是每次尝试都会崩溃,这是错误消息

I want to create a bitmap form another but for each try it's a crash, this the error message

这是我尝试创建的地方:

This is where i try the creation :

public void saveBitmap(){
    Bitmap bitmapToSave = Bitmap.createBitmap(view.getWidth(),view.getHeight(), Bitmap.Config.ARGB_8888);
    Canvas canvas = new Canvas(bitmapToSave);
    view.draw(canvas);

    int width = bitmapToSave.getWidth();
    int height = bitmapToSave.getHeight();
    System.out.println("view : "+view.getWidth());
    System.out.println("view : "+view.getHeight());
    System.out.println("btmp Width : "+width);
    System.out.println("btmp Height : "+height);

    Bitmap result = Bitmap.createBitmap(bitmapToSave, 0, view.getTop(), view.getWidth(), view.getWidth());
    SaveImage(result);
}

感谢您的帮助:D

这是我的日志猫:

> System.out﹕ view : 480
System.out﹕ view : 480
System.out﹕ btmp Width : 480
System.out﹕ btmp Height : 480

推荐答案

尝试

Bitmap result = Bitmap.createBitmap(bitmapToSave, 0, 0, view.getWidth(), view.getHeight());

我认为问题是view.getTop是一个大于0的值.所以view.GetTop + view.getHeight()不小于bitmap.height.

I think the issue is view.getTop is a value greater than 0. So view.GetTop + view.getHeight() is not less than bitmap.height.

这篇关于y +高度在Android中必须为< = bitmap.height()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-29 22:22