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

2019-12-10 19:53:55王振洲
  • height_tmp /= 2;   scale *= 2;  
  • }   BitmapFactory.Options o2 = new BitmapFactory.Options();  
  • o2.inSampleSize = scale;   Bitmap bmp = BitmapFactory.decodeFile(url, o2);  
  • return bmp;   }  

    8.获得图片的倒影,同时倒影渐变效果:

     

     
    1. /**   * @param bitmap 图片源  
    2. * @return 处理后的图片Bitmap对象   */ 
    3. public static Bitmap createMirro(Bitmap bitmap) {   int width = bitmap.getWidth();  
    4. int height = bitmap.getHeight();   int shadow_height = 15;  
    5. int[] pixels = new int[width * height];   bitmap.getPixels(pixels, 0, width, 0, 0, width, height);  
    6. // shadow effect   int alpha = 0x00000000;  
    7. for (int y = 0; y < height; y++) {   for (int x = 0; x < width; x++) {  
    8. int index = y * width + x;   int r = (pixels[index] >> 16) & 0xff;  
    9. int g = (pixels[index] >> 8) & 0xff;   int b = pixels[index] & 0xff;  
    10. pixels[index] = alpha | (r << 16) | (g << 8) | b;   }