android 图片压缩的方法
2012-09-10 08:48
357 查看
BitmapFactory.Options options = new BitmapFactory.Options(); options.inJustDecodeBounds = true; // 获取这个图片的宽和高 Bitmap bitmap = BitmapFactory.decodeFile( mPicCursor.getString(3) , options);// 此时返回bm为空 options.inJustDecodeBounds = false; // 计算缩放比 int be = (int) (options.outHeight / (float) 200); if (be <= 0) be = 1; options.inSampleSize = be; // 重新读入图片,注意这次要把options.inJustDecodeBounds设为false哦 bitmap = BitmapFactory.decodeFile( mPicCursor.getString(3), options); bitmap = Bitmap.createScaledBitmap(bitmap, 150, 160, false);//将图片设定为指定大小 try { FileOutputStream out = new FileOutputStream(mUser .getPhotoUrl()); if (bitmap.compress(Bitmap.CompressFormat.JPEG, 35, out)) { out.flush(); out.close(); } } catch (Exception e) { }
2................................
该方法是从网上copy的,没有尝试
public static String getImageString(String imgFilePath){ Bitmap mBitmap=BitmapFactory.decodeFile(imgFilePath); Matrix matrix = new Matrix(); matrix.postScale(0.5f, 0.5f); Bitmap newBitmap=Bitmap.createBitmap(mBitmap, 0, 0, mBitmap.getWidth(), mBitmap.getHeight(), matrix, true); ByteArrayOutputStream out=new ByteArrayOutputStream(); newBitmap.compress(CompressFormat.JPEG, 100, out); byte []bytes=out.toByteArray(); String imageString=Base64.encodeToString(bytes, Base64.DEFAULT); return imageString; }
相关文章推荐
- Android应用开发中三种常见的图片压缩方法
- Android压缩图片到100K以下并保持不失真的高效方法
- Android压缩图片的几种方法
- android 图片压缩的方法
- Android之获取本地图片并压缩方法
- Android 图片压缩的方法大全
- Android图片压缩和获取压缩后的图片的方法
- Android 图片压缩也即生成缩略图方法
- android图片压缩的3种方法实例
- Android压缩图片到100K以下并保持不失真的高效方法
- android三种图片压缩方法
- Android 比较完美 图片压缩方法
- Android压缩图片到100K以下并保持不失真的高效方法
- Android 图片压缩也即生成缩略图方法
- android中图片压缩以及图片旋转的方法
- android 图片压缩方法
- Android压缩图片到100K以下并保持不失真的高效方法+1
- android调用系统相机的方法,并且解决三星手机遇到的问题,图片旋转、压缩
- android图片压缩方法
- Android一种高效压缩图片的方法