WEB开发网
开发学院手机开发Android 开发 Android中Bitmap Drawable Byte之间的转化 阅读

Android中Bitmap Drawable Byte之间的转化

 2010-08-17 11:03:00 来源:WEB开发网   
核心提示:Java代码1. Bitmap 转化为 byteByteArrayOutputStream out = new ByteArrayOutputStream();bitmap.compress(Bitmap.CompressFormat.PNG, 100, out);byte[] array= out.toByteArr

Java代码

1. Bitmap 转化为 byte

ByteArrayOutputStream out = new ByteArrayOutputStream();

bitmap.compress(Bitmap.CompressFormat.PNG, 100, out);

byte[] array= out.toByteArray();

2. byte转化为bitmap

final ContentResolver contentResolver = context.getContentResolver();

final PackageManager manager = context.getPackageManager();

final Cursor c = contentResolver.query(uri, null, null, null, null);

final int icon3DIndex = c.getColumnIndexOrThrow(ColumnName);

byte[] data = c.getBlob(icon3DIndex);

Bitmap bitmap = BitmapFactory.decodeByteArray(data, 0, data.length);

3. bitmap转化为Drawable

Drawable drawable = new FastBitmapDrawable(bitmap);

...

4. Drawable转化为bitmap

a. BitmapDrawable, FastBitmapDrawable直接用getBitmap

b. 其他类型的Drawable用Canvas画到一个bitmap上

Canvas canvas = new Canvas(bitmap)

drawable.draw(canvas);

Tags:Android Bitmap Drawable

编辑录入:coldstar [复制链接] [打 印]
赞助商链接