【发布时间】:2013-11-15 14:21:31
【问题描述】:
我的应用程序访问相机并拍摄照片,然后将其保存回 sdcard。
问题是图像相当大,大约 1500X2500 像素和 500kb 大小。
我必须将图像上传到服务器。
所以我想编辑图像,但我想以正确的构图编辑图像,即正确的高度:宽度比,这样图像看起来不会很奇怪
我正在使用的代码:
FileInputStream in = new FileInputStream("/mnt/sdcard/DCIM/1302779969138");
BufferedInputStream buf = new BufferedInputStream(in)
Bitmap bm = BitmapFactory.decodeStream(buf);
File isfile = new File(Environment.getExternalStorageDirectory(),"/DCIM/1302779969138");
FileOutputStream fout = new FileOutputStream(isfile);
Bitmap bitmap = null;
bitmap = Bitmap.createScaledBitmap(bm, 350, 350, true);
bitmap.compress(CompressFormat.JPEG, 20, fout);
使用上面的代码,我可以将图像大小调整为 350 X 350,但我希望仅使用宽度作为参数来缩放它,以便相应地调整高度并且图像比例保持不变
另外还提到我是否应该刷新Fileoutputsteam 和inputStream
【问题讨论】:
标签: android image-processing bitmap