简体   繁体   中英

Android Image Compression Without Res Change

I am looking for a solution that I found here for IOS for an android application. I have developed IOS applications and was just wondering if anyone had some insight on how to achieve this similar goal in android.

I am trying to just compress the image before uploading it to the server. I do not need the resolution to go down, and 200 kb or up to 400 kb should be fine and keep things looking alright for a phone. If anyone can take a look as at least give me a direction. I figured I would ask this before diving into some more complicated ways to do it that I have read into. If there was something as easy as it was in IOS then that would be better.

Thank you.

try

Bitmap original = BitmapFactory.decodeStream(getAssets().open("1024x768.jpg"));
ByteArrayOutputStream out = new ByteArrayOutputStream();
original.compress(Bitmap.CompressFormat.PNG, 100, out);
Bitmap decoded = BitmapFactory.decodeStream(new ByteArrayInputStream(out.toByteArray()));

from How to make Bitmap compress without change the bitmap size?

使用Bitmap.Compress(CompressFormat格式,int quality,OutputStream流)使用Bitmap.CompressFormat.JPEG并将质量设置为小于100.使用不同的质量值,直到您在大小和质量之间取得适当的平衡。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM