如何在不改變圖像尺寸的情況下縮小圖像大小(高度和寬度應該相同)。在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