android - 什么是具有高质量和高宽比的最佳图像缩放器(如电报或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() 会降低质量
请帮帮我
谢谢
解决方案
最好的质量和更小的尺寸。
这条线是答案
options.inPreferredConfig = Bitmap.Config.ARGB_8888;
推荐阅读
- python - Python3:与玩家碰撞时从动态数组中删除敌人
- c++ - 在 C++ 中使用开始时间和持续时间计算活动任务
- javascript - Electron ipcRenderer message between two windows doesn't work
- python - ta-lib MACD 函数在封闭的 100 个数字示例上计算错误
- python - 无法理解此 Python 代码的工作原理
- odoo - 当其他模块中的复选框为真时,如何使产品名称不可见?
- google-app-maker - How to get Google UserId from active user session in App Maker?
- r - 以年而不是天为 x 轴的生存图
- javascript - JavaScript 在每个 php 输出中工作,而不是在特定的点击结果中工作
- kendo-ui - 向网格行选择添加淡入/淡出