[英]How to compress and resize a bitmap?
In my application I want crop image from gallery
, after cropped convert to base64 and send to server.在我的应用程序中,我想要从gallery
裁剪图像,裁剪后转换为base64并发送到服务器。
Before convert to base64 first convert image to bitmap
.在转换为base64之前先将图像转换为bitmap
。
I want after convert to bitmap first compress and resize this bitmap
then convert to base64 and sent to server.我想在转换为位图后首先压缩并调整此bitmap
大小,然后转换为base64并发送到服务器。
I want 10% compressed and set size 1000*1000 to bitmap
.我想要10% 压缩并将大小 1000*1000设置为bitmap
。
For crop image I use this library : https://github.com/jdamcd/android-crop对于裁剪图像,我使用这个库: https : //github.com/jdamcd/android-crop
My codes:我的代码:
private void handleCrop(int resultCode, Intent result) throws IOException {
if (resultCode == RESULT_OK) {
if (result != null) {
Uri imageUri = Crop.getOutput(result);
Bitmap bitmap = MediaStore.Images.Media.getBitmap(this.getContentResolver(), imageUri);
//TODO : Here first compress and resize bitmap
base64String = ImageConvertBase64.convert(bitmap);
}
}
before this line i should compress and resize bitmap :在此行之前,我应该压缩和调整位图大小:
base64String = ImageConvertBase64.convert(bitmap);
How can i it?我怎么能i am amateur and really need your help, please help me我是业余爱好者,真的需要你的帮助,请帮帮我
Use below code for the compress and resize(Set size and compression ration according to your requirement):使用以下代码进行压缩和调整大小(根据您的要求设置大小和压缩比):
Bitmap resized = Bitmap.createScaledBitmap(yourBitmap,(int)(yourBitmap.getWidth()*0.8), (int)(yourBitmap.getHeight()*0.8), true);
resized.compress(Bitmap.CompressFormat.JPEG,90,outStream);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.