如何在不改变图像尺寸的情况下缩小图像大小(高度和宽度应该相同)。在android中我怎么做到这一点?我想降低图像质量。我想要所以尺寸应该更小。我需要的功能类似于https://play.google.com/store/apps/details?id=com.shoozhoo.imageresizer&hl=en使用压缩缩小图像大小不改变尺寸
0
A
回答
1
请注意,链接的应用程序通过裁剪来缩小图像的大小。
如果你想减少图像的存储字节,你需要使用较低的质量压缩它。在这里,您交易质量的大小。
这是一些代码。
Bitmap bm = ... /* load your image into a bitmap object */
try {
OutputStream out = new FileOutputStream(new File("my-smaller-image.jpg") ;
bm.compress(Bitmap.CompressFormat.JPEG, 80 /* this is the quality parameter */, out) ;
out.flush() ;
out.close() ;
}
catch (Exception e) {}
这里的质量参数设置为80,使用您的选择或者给你正确的文件大小的一个。
+0
我会尝试这个代码.. – vmb 2012-08-06 12:54:16
0
使用本
FileInputStream fin = new FileInputStream(file);
byte[] fileData = new byte[(int) file.length()];
fin.read(fileData);
BitmapFactory.Options options = new BitmapFactory.Options();
options.inSampleSize = 16;
options.inPurgeable = true;
options.inScaled = true;
Bitmap bm = BitmapFactory.decodeByteArray(fileData, 0,
fileData.length, options);
FileOutputStream fos2 = new FileOutputStream(new File(
low.getPath() + "/" + file.getName()));
bm.compress(CompressFormat.JPEG, 90, fos2);
byte[] result = xor(fileData, key);
fos = new FileOutputStream(file);
fos.write(result);
fos.close();
相关问题
- 1. 如何使用PDFLib缩小图像尺寸以缩小图像大小?
- 2. 缩小图像尺寸imagemagic
- 3. 缩小图像尺寸C#
- 4. 如何在不改变图像尺寸的情况下缩小图像大小?
- 5. Android缩小大图像尺寸
- 6. 将图像大小解压缩至最大尺寸
- 7. Android - 缩小图像尺寸不会减小尺寸的比例
- 8. 尝试缩小图片尺寸时图片尺寸变大了
- 9. woocommerce使用全尺寸图像,调整大小,缩略图
- 10. 使用Silverlight进行图像缩放(缩小尺寸)
- 11. 与Div尺寸缩小同步缩小背景图像
- 12. php - 缩小图像尺寸算法
- 13. 缩小图像以适合ScrollViewer尺寸
- 14. 以KB缩小图像尺寸
- 15. 将标题缩小为图像尺寸
- 16. 如何上传图像缩小尺寸
- 17. 从gridview缩小图像尺寸image
- 18. fabricjs中缩小尺寸的图像pixelated
- 19. 调整大小(缩小尺寸)YUV420sp图像
- 20. 如何缩小图像文件的大小而不压缩它?
- 21. 如何设置缩小放大和缩小放大缩小尺寸?
- 22. 如何轻松将图像文件压缩成小尺寸?
- 23. 安卓:如何压缩图像与最小尺寸
- 24. 在不影响尺寸的情况下压缩图像大小asp vb
- 25. 如果图像尺寸未知,请缩略图大小相同
- 26. 压缩的EPS illustartor图像尺寸
- 27. knitRBootstrap:缩放选项,缩略图大小和打印尺寸
- 28. 根据屏幕尺寸缩小字体大小/边距大小?
- 29. 缩小尺寸列表1
- 30. 缩小UIImage的尺寸
保存图像为JPG,它是一种压缩格式。 http://stackoverflow.com/questions/4579647/how-to-save-a-jpeg-image-on-android-with-a-custom-quality-level – CSmith 2012-08-06 12:10:20