我是android的新手,我正在学习如何使用相机并将图片保存在sqlite数据库中。为此,我将遵循下面的示例https://github.com/sprejjs/MyMemoriesDB
它真的很好,唯一的事情是图片的质量。当你打开相机,它看起来很好,但当你保存它,看起来很糟糕,失去了很多质量。如何使用该示例来提高质量?
发布于 2018-10-19 05:10:41
如果查看库的代码,就会发现内存有一个构造函数:
public Memory(String title, Bitmap image) {
this.title = title;
this.image = bitmapToString(resizeBitmap(image));
}请注意,此构造函数调用
resizeBitmap(图像)
如果您查看该代码,您将看到:
public static Bitmap resizeBitmap(Bitmap bitmap) {
int width = bitmap.getWidth();
int height = bitmap.getHeight();
float scaleWidth = PREFERRED_WIDTH / width;
float scaleHeight = PREFERRED_HEIGHT / height;
Matrix matrix = new Matrix();
matrix.postScale(scaleWidth, scaleHeight);
Bitmap resizedBitmap = Bitmap.createBitmap(
bitmap, 0, 0, width, height, matrix, false);
bitmap.recycle();
return resizedBitmap;
}在将图像转换为Base64之前,代码实际上将图像调整为250/250。
private static final float PREFERRED_WIDTH = 250;
private static final float PREFERRED_HEIGHT = 250;只需将其更改为文件顶部所需的内容,或完全删除调整大小的调用即可。
https://stackoverflow.com/questions/52883701
复制相似问题