Android编程之图片相关代码集锦

2019-12-10 19:53:55王振洲
  • if (y >= (height - shadow_height)) {   alpha = alpha + 0x1F000000;  
  • }   }  
  • // invert effect   Bitmap bm = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);  
  • for (int y = 0; y < height; y++) {   bm.setPixels(pixels, y * width, width, 0, height - y - 1, width, 1);  
  • }   return Bitmap.createBitmap(bm, 0, 0, width, shadow_height);  
  • }  

    9.保存图片到SDCard:

     

     
    1. /**   * @param imagePath 图片保存路径  
    2. * @param bm 被保存的bitmap对象   */ 
    3. public static void saveImgToLocal(String imagePath, Bitmap bm) {   if (bm == null || imagePath == null || "".equals(imagePath)) {  
    4. return;   }  
    5. File f = new File(imagePath);   if (f.exists()) {  
    6. return;   } else {  
    7. try {   File parentFile = f.getParentFile();  
    8. if (!parentFile.exists()) {   parentFile.mkdirs();  
    9. }   f.createNewFile();  
    10. FileOutputStream fos;   fos = new FileOutputStream(f);  
    11. bm.compress(Bitmap.CompressFormat.PNG, 100, fos);   fos.close();