Android 图片的处理方法 更新中
2014-08-20 09:33
183 查看
// 压缩图片大小 public static Bitmap compressImage(Bitmap image) { ByteArrayOutputStream baos = new ByteArrayOutputStream(); image.compress(Bitmap.CompressFormat.JPEG, 100, baos);// 将压缩的图片存到baos中 // >100kb go on compress int option = 100; while (baos.toByteArray().length / 1024 > 100) { baos.reset(); image.compress(Bitmap.CompressFormat.JPEG, option, baos); option -= 10; } ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray());// 把压缩后的数据baos存放到ByteArrayInputStream中 Bitmap bitmap = BitmapFactory.decodeStream(bais, null, null);// 把ByteArrayInputStream数据生成图片 return bitmap; } /** * 将彩色图转换为灰度图 * @param img 位图 * @return 返回转换好的位图 */ public Bitmap convertGreyImg(Bitmap img) { int width = img.getWidth(); //获取位图的宽 int height = img.getHeight(); //获取位图的高 int []pixels = new int[width * height]; //通过位图的大小创建像素点数组 img.getPixels(pixels, 0, width, 0, 0, width, height); int alpha = 0xFF << 24; for(int i = 0; i < height; i++) { for(int j = 0; j < width; j++) { int grey = pixels[width * i + j]; int red = ((grey & 0x00FF0000 ) >> 16); int green = ((grey & 0x0000FF00) >> 8); int blue = (grey & 0x000000FF); grey = (int)((float) red * 0.3 + (float)green * 0.59 + (float)blue * 0.11); grey = alpha | (grey << 16) | (grey << 8) | grey; pixels[width * i + j] = grey; } } Bitmap result = Bitmap.createBitmap(width, height, Config.RGB_565); result.setPixels(pixels, 0, width, 0, 0, width, height); return result; }
public static Bitmap decodeFile (String pathName)
Added in API level 1Decode a file path into a bitmap. If the specified file name is null, or cannot be decoded into a bitmap, the function returns null.
Parameters
pathName | complete path name for the file to be decoded. |
---|
the resulting decoded bitmap, or null if it could not be decoded.
/** * 放大缩小图片 */ public static Bitmap zoomBitmap(Bitmap bitmap, int w, int h) { int width = bitmap.getWidth(); int height = bitmap.getHeight(); Matrix matrix = new Matrix(); float scaleWidht = ((float) w / width); float scaleHeight = ((float) h / height); matrix.postScale(scaleWidht, scaleHeight); Bitmap newbmp = Bitmap.createBitmap(bitmap, 0, 0, width, height, matrix, true); return newbmp; }
相关文章推荐
- android Matrix处理图片原理及方法整理
- Android下图片处理的的一些方法
- android图片处理方法
- Android下图片处理的的一些方法
- Android处理图片OOM的若干方法小结
- Android下图片处理的的一些方法
- Android处理图片OOM的若干方法小结
- Android处理图片OOM的若干方法小结
- android三步处理图片缓存的方法
- Android下图片处理的的一些方法
- Android图片处理的的一些方法 - ORIETech
- Android下图片处理的的一些方法
- Android --- 图片处理的方法
- Android下图片处理的的一些方法
- Android --- 图片处理的方法
- Android的Bitmap处理大图片解决方法
- Android的Btimap处理大图片解决方法
- android图片处理方法
- Android 图片处理方法大全
- Android处理图片OOM的若干方法小结