当前位置:操作系统 > 安卓/Android >>

Android ApiDemos示例解析(62):Graphics->CreateBitmap

本例介绍了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
 
补充:移动开发 , Android ,
CopyRight © 2022 站长资源库 编程知识问答 zzzyk.com All Rights Reserved
部分文章来自网络,