安卓Bitmap.createBitmap()与-1返回一个位图的高度和宽度 [英] Android Bitmap.createBitmap() returning a bitmap with -1 for height and width

查看:291
本文介绍了安卓Bitmap.createBitmap()与-1返回一个位图的高度和宽度的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

为什么会

Bitmap bmp;
bmp = Bitmap.createBitmap( 100, 100, Config.RGB_565 );

自从返回一个位图-1的高度和宽度?我没有看到这个文档中任何事情。只有看到在<一个href="http://developer.android.com/reference/android/graphics/Bitmap.html#createBitmap%28int,%20int,%20android.graphics.Bitmap.Config%29">documentation

抛出

<一个href="http://developer.android.com/reference/java/lang/IllegalArgumentException.html">IllegalArgumentException如果宽度或高度为&LT; = 0

IllegalArgumentException if the width or height are <= 0

不过,虽然调试在Eclipse中我看到的宽度和高度-1创建后。一切似乎都正确显示。

But while debugging in eclipse I see the width and height are -1 after creation. Everything seems to display correctly.

[更新]

如果我添加一个日志,并获得宽度和高度

If I add a Log and get the width and height

Log.i(logTag, "bmp - (width,height) (" + bmp.getWidth() + "," + bmp.getHeight() + ")");

再来看一下位图的性能,正确的宽度和高度都显示(我假设任何调用read创建后的宽度和高度,然后将更新在Eclipse中的属性,它会显示正确)。

Then look at the properties of the bitmap, the correct width and height are shown (I'm assuming any call to read the width and height after creation would then update the properties in eclipse and it will show correctly).

我想这只是一个调试器的问题?我调试我的旧的Droid。

I guess this is just a debugger issue? I'm debugging on my old Droid.

推荐答案

您在一个情况下,这是一个问题?或者仅仅是好奇,为什么他们是-1?

Are you in a situation where this is an issue? Or merely curious why they are -1?

不管怎样它不是一个调试问题,性能实际上是-1。这仅仅是猜测,但直至位图被用来/绘制的宽度和高度可以是-1,因为它并不重要,并有可能在执行一个优化

Either way it is not a debugger issue, the properties are actually -1. This is just speculation but until the Bitmap is used/drawn the width and height can be -1 because it doesn't matter and is likely an optimization in the implementation.

这篇关于安卓Bitmap.createBitmap()与-1返回一个位图的高度和宽度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆