首页 > 解决方案 > 什么是具有高质量和高宽比的最佳图像缩放器(如电报或whatsapp 或...)?

问题描述

我想在不损失质量和纵横比的情况下调整图像大小并使用以下代码:

String filePath = "/sdcard/download/0.jpg";

BitmapFactory.Options Options = new BitmapFactory.Options();
Options.inSampleSize = 4;
Options.inJustDecodeBounds = false;

Bitmap bmp = BitmapFactory.decodeFile(filePath, Options);

int newWidht = 600;
int originalWidth = Options.outWidth;
int originalHeight = Options.outHeight;
float AspectRatio = (float)originalWidth / originalHeight;
float tempnewHeight = newWidht/ AspectRatio;
int  newHeight = (int)tempnewHeight;

Bitmap resized = Bitmap.createScaledBitmap(bmp, newWidth, newHeight, false);

ContextWrapper cw = new ContextWrapper(getApplicationContext());
File mypath=new File("/sdcard/download/","1.jpg");
FileOutputStream fos = null;

fos = new FileOutputStream(mypath);
resized.compress(Bitmap.CompressFormat.JPEG, 100, fos);
fos.close();

但是这种方法会降低质量或不能很好地解决问题,而且我保存的图片非常糟糕并且会孵化。
我看到一些关于此的帖子,但找不到解决方案。
我认为 Bitmap.createScaledBitmap() 会降低质量

请帮帮我
谢谢

标签: android

解决方案


最好的质量和更小的尺寸。
这条线是答案

options.inPreferredConfig = Bitmap.Config.ARGB_8888;

推荐阅读