您的位置:首页 > 移动开发 > Android开发

关于Android开发过程中,createImage的一些总结。

2010-12-26 13:19 731 查看
今天在Android开发过程中,在改原来在WTK上写过的底层方法,发现Android里面createImage(Android里面叫createBitmap)创建的时候无法像WTK里面一样直接创建ARGB数组

WTK方法如下

createRGBImage(int[] rgb, int width, int height, boolean processAlpha)
//Creates an immutable image from a sequence of ARGB values, specified as 0xAARRGGBB.


而Android的BitmapFactory倒是有一个

decodeByteArray(byte[] data, int offset, int length, BitmapFactory.Options  opts)
//Decode an immutable bitmap from the specified byte array.


单这一方式,经过我一上午的试验,发现只能创建相应压缩格式的图片,比如PNG,JPEG等,于是决定跟踪写一个接口。

流程大概是这样的。

1.先创建一张,指定大小的空图

2.之后通过setPixels将相应的数组贴进去,setPixels的第一个参数刚好是个int型,表示ARGB的数值。

于是就解决啦。

在实际的调试过程中,我下断点跟踪Bitmap相关变量,发现里面有个参数mHeight和mWidth一直为-1,我以为图片没有创建出来,其实并不是,在内部他已经创建出来了,只需再次调用bm.getHeight()这个值就出来啦。

更正,Android里面本身带类似于WTK22里面的API,只是当时我调试时未知原因导致崩溃,所以没调出来。

static Bitmap   	 createBitmap(int[] colors, int offset, int stride, int width, int height, Bitmap.Config  config)
Returns a immutable bitmap with the specified width and height, with each pixel value set to the corresponding value in the colors array.


此方法即可
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: