Android 将图像URI调整为100k
我正在从URI检索图像。但它需要花费太多的时间来加载。我的平均文件大小是500k。如何将其减少到10万:Android 将图像URI调整为100k,android,android-imageview,android-image,Android,Android Imageview,Android Image,我正在从URI检索图像。但它需要花费太多的时间来加载。我的平均文件大小是500k。如何将其减少到10万: // Here is the code where I am displaying image URI // The retrieval of URI using Picasso public void setImage(final Context context, final String image) { final ImageView postImage = (Imag
// Here is the code where I am displaying image URI
// The retrieval of URI using Picasso
public void setImage(final Context context, final String image) {
final ImageView postImage = (ImageView) mView.findViewById(R.id.allPostImage);
with(context).load(image).networkPolicy(NetworkPolicy.OFFLINE).into(postImage, new Callback() {
@Override
public void onSuccess() {
}
@Override
public void onError() {
Picasso.with(context).load(image).into(postImage);
}
});
}
使用此选项压缩图像大小
使用此选项压缩图像大小。访问此链接。您当然可以在下载图像后将其缩小或进一步压缩,但下载所需的时间与下载所需的时间相同。您希望调整原始源映像在服务器上的大小。真的没有其他解决方案。我认为它不在服务器上。它在设备本身上。因为setImageUri()不会下载它。请访问此链接。您当然可以在下载后将图像缩小或进一步压缩,但下载所需的时间与下载所需的时间相同。您希望调整原始源映像在服务器上的大小。真的没有其他解决方案。我认为它不在服务器上。它在设备本身上。因为setImageUri()不会下载它。png文件的大小将大于原始jpg文件。位图不受影响,为原始大小。将png替换为jpeg,将100替换为50,这不会更改位图的任何内容。为什么要加载jpg,转换成位图,然后再转换成jpg?对那个字节数组什么也不做?50会使jpg文件变小,质量不好,但位图仍然相同。同时将100更改为50,会减小大小。png文件的大小将大于原始jpg文件。位图不受影响,为原始大小。将png替换为jpeg,将100替换为50,这不会更改位图的任何内容。为什么要加载jpg,转换成位图,然后再转换成jpg?对那个字节数组什么也不做?50会使jpg文件变小,质量不好,但位图仍然相同。同时将100更改为50,会减小大小。
Uri imageUri = imageReturnedIntent.getData();
InputStream imageStream = null;
try {
imageStream = getContentResolver().openInputStream(
imageUri);
} catch (FileNotFoundException e) {
e.printStackTrace();
}
Bitmap bmp = BitmapFactory.decodeStream(imageStream);
ByteArrayOutputStream stream = new ByteArrayOutputStream();
bmp.compress(Bitmap.CompressFormat.JPEG, 50, stream);
imageview.setImageBitmap(bmp);
byte[] byteArray = stream.toByteArray();
try {
stream.close();
stream = null;
} catch (IOException e) {
e.printStackTrace();
}