Android Bitmap图片压缩,图片倒影
2014-08-01 23:38
465 查看
/** * 图片倒影 * * @param originalBitmap 原始图片 * @return 带倒影图片 */ public static Bitmap createReflectedImage(Bitmap originalBitmap, boolean isAppStart) { int refectionGap; if (isAppStart) { refectionGap = 0; } else { refectionGap = 4; } int width = originalBitmap.getWidth(); int height = originalBitmap.getHeight(); Matrix matrix = new Matrix(); matrix.preScale(1, -1);//x轴变为原来的1倍,y轴变为原来的-1倍 Bitmap reflectionBitmap = Bitmap.createBitmap(originalBitmap, 0, height >> 1, width, height >> 1, matrix, false); Bitmap withReflectionBitmap = Bitmap.createBitmap(width, (height + (height >> 1) + refectionGap), Bitmap.Config.ARGB_8888); Canvas canvas = new Canvas(withReflectionBitmap); //画原始图片 canvas.drawBitmap(originalBitmap, 0, 0, null); //画间隔 Paint defaultPaint = new Paint(); canvas.drawRect(0, height, width, height + refectionGap, defaultPaint); //画倒影 canvas.drawBitmap(reflectionBitmap, 0, height + refectionGap, null); //实现倒影 Paint paint = new Paint(); LinearGradient shader = new LinearGradient(0, originalBitmap.getHeight(), 0, withReflectionBitmap.getHeight() + 4, 0x70ffffff, 0x00ffffff, Shader.TileMode.MIRROR); paint.setShader(shader); paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.DST_IN)); canvas.drawRect(0, height, width, withReflectionBitmap.getHeight(), paint); reflectionBitmap.recycle(); originalBitmap.recycle(); return withReflectionBitmap; } /** * 获取压缩比率 * * @param options * @param reqWidth 目标宽度 * @param reqHeight 目标高度 * @return 压缩比率 */ private static int calculateInSampleSize(BitmapFactory.Options options, int reqWidth, int reqHeight) { int height = options.outHeight; int width = options.outWidth; int inSampleSize = 1; if (height > reqHeight || width > reqWidth) { int heightRatio = Math.round((float) height / (float) reqHeight); int widthRatio = Math.round((float) width / (float) reqWidth); inSampleSize = heightRatio < widthRatio ? heightRatio : widthRatio; } return inSampleSize; } /** * 对图片进行压缩 * * @param mResources Resources * @param imageId 图片资源ID * @param reqWidth 目标宽度 * @param reqHeight 目标高度 * @return bitmap */ public static Bitmap decodeSampleBitmapFromResource(Resources mResources, int imageId, int reqWidth, int reqHeight) { BitmapFactory.Options options = new BitmapFactory.Options(); options.inJustDecodeBounds = true; BitmapFactory.decodeResource(mResources, imageId, options); options.inSampleSize = calculateInSampleSize(options, reqWidth, reqHeight); options.inJustDecodeBounds = false; return BitmapFactory.decodeResource(mResources, imageId, options); }
相关文章推荐
- Android编程之Bitmap图片压缩大小
- [Android] bitmap/drawable/byte的转换和获取圆角/倒影图片
- android图片压缩质量参数Bitmap.Config RGB_565等的含义
- android图片压缩质量参数Bitmap.Config RGB_565等的含义
- android图片压缩质量参数Bitmap.Config RGB_565 ARGB_8888
- android 图片倒影 bitmap与drawable的转换 把图片处理成指定大小 图片圆角处理 dip转换成px
- android处理图片工具类,图片压缩,把图片互换转换成base64和bitmap
- android图片压缩质量参数Bitmap.Config RGB_565等的含义
- Android应用开发之图片(Bitmap)压缩(二)---------质量压缩
- android 压缩图片bitmap
- Android BitmapFactory 图片压缩
- Android中几种图像特效处理的小技巧,比如圆角,倒影,还有就是图片缩放,Drawable转化为Bitmap,Bitmap转化为Drawable等等
- android bitmap图片压缩,打时间水印。
- android bitmap压缩图片
- Android关于ListView显示SD卡上的Bitmap的图片(图片压缩之后)
- 图片压缩android bitmap compress(图片压缩)
- Android BitmapFactory图片压缩处理(大位图二次采样压缩处理)
- Android 压缩网络上的图片BitmapFactory.decodeStream()返回为空的问题
- Android编程之Bitmap图片压缩大小
- 使用BitmapFactory压缩图片大小解决android解析图片OOM错误