简体   繁体   English

bmpFactoryOptions不起作用,不知道为什么

[英]bmpFactoryOptions don't work, no idea why

I use the following code to get a Blob back from my SQLite database and get back a bitmap. 我使用以下代码从我的SQLite数据库中获取Blob并获取位图。 My problem is that the reconstructed bitmap is larger than the original picture (input). 我的问题是,重构的位图大于原始图片(输入)。 It seems that my BitmapFactory.Options isn't working, but I have no idea what is wrong, nor am I getting an error. 看来我的BitmapFactory.Options无法正常工作,但我不知道出了什么问题,也没有收到错误。 What is wrong with this code? 此代码有什么问题?

byte[] blob = contact.getMP();
ByteArrayInputStream inputStream = new ByteArrayInputStream(blob);
BitmapFactory.Options bmpFactoryOptions = new BitmapFactory.Options();
bmpFactoryOptions.inPreferredConfig = Bitmap.Config.ARGB_8888;
bmpFactoryOptions.inScaled = false;
bmpFactoryOptions.outHeight = 240;
bmpFactoryOptions.outWidth = 320;
Bitmap bitmap = BitmapFactory.decodeStream(inputStream, null, bmpFactoryOptions);


try {
FileOutputStream out = new FileOutputStream("mnt/sdcard/test5.png");                            bitmap.compress(Bitmap.CompressFormat.PNG, 100, out);
} catch (Exception e) {
e.printStackTrace();
}

When I check the output my 320 x 240 picture is 427 x 320. I don't want to use Bitmap.createScaledBitmap because it messes up the quality. 当我检查输出时,我的320 x 240图片为427 x320。我不想使用Bitmap.createScaledBitmap,因为它会破坏质量。

你必须传递给decodeStream才能工作

Bitmap bitmap = BitmapFactory.decodeStream(inputStream, null, bmpFactoryOptions);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM