本例介紹了Bitmap中定義的建立Mutable Bitmap的幾個靜態函數
[java]
// these three are initialized with colors[]
mBitmaps[0] = Bitmap.createBitmap(colors, 0, STRIDE, WIDTH, HEIGHT,
Bitmap.Config.ARGB_8888);
mBitmaps[1] = Bitmap.createBitmap(colors, 0, STRIDE, WIDTH, HEIGHT,
Bitmap.Config.RGB_565);
mBitmaps[2] = Bitmap.createBitmap(colors, 0, STRIDE, WIDTH, HEIGHT,
Bitmap.Config.ARGB_4444);
// these three will have their colors set later
mBitmaps[3] = Bitmap.createBitmap(WIDTH, HEIGHT,
Bitmap.Config.ARGB_8888);
mBitmaps[4] = Bitmap.createBitmap(WIDTH, HEIGHT,
Bitmap.Config.RGB_565);
mBitmaps[5] = Bitmap.createBitmap(WIDTH, HEIGHT,
Bitmap.Config.ARGB_4444);
// these three are initialized with colors[]
mBitmaps[0] = Bitmap.createBitmap(colors, 0, STRIDE, WIDTH, HEIGHT,
Bitmap.Config.ARGB_8888);
mBitmaps[1] = Bitmap.createBitmap(colors, 0, STRIDE, WIDTH, HEIGHT,
Bitmap.Config.RGB_565);
mBitmaps[2] = Bitmap.createBitmap(colors, 0, STRIDE, WIDTH, HEIGHT,
Bitmap.Config.ARGB_4444);
// these three will have their colors set later
mBitmaps[3] = Bitmap.createBitmap(WIDTH, HEIGHT,
Bitmap.Config.ARGB_8888);
mBitmaps[4] = Bitmap.createBitmap(WIDTH, HEIGHT,
Bitmap.Config.RGB_565);
mBitmaps[5] = Bitmap.createBitmap(WIDTH, HEIGHT,
Bitmap.Config.ARGB_4444);和使用compress來產生PNG或是JPEG格式的映像:
[java]
for (int i = 0; i < mBitmaps.length; i++) {
mJPEG[i] = codec(mBitmaps[i], Bitmap.CompressFormat.JPEG, 80);
mPNG[i] = codec(mBitmaps[i], Bitmap.CompressFormat.PNG, 0);
}
...
private static Bitmap codec(Bitmap src, Bitmap.CompressFormat format,
int quality) {
ByteArrayOutputStream os = new ByteArrayOutputStream();
src.compress(format, quality, os);
byte[] array = os.toByteArray();
return BitmapFactory.decodeByteArray(array, 0, array.length);
}
作者:mapdigit