简体   繁体   English

使用BitmapFactory的原始大小位图

[英]Original size bitmap using BitmapFactory decodeByteArray

How can I construct original sized bitmap from byte-array? 如何从字节数组构造原始大小的位图?

    byte[] imageAsBytes = Base64.decode(b64.getBytes(), Base64.DEFAULT);
    BitmapFactory.Options options = new BitmapFactory.Options();
    options.inScaled = false;
    options.inSampleSize = 1;
    return BitmapFactory.decodeByteArray(imageAsBytes, 0, imageAsBytes.length, options);

The problem is that created bitmap is couple of times smaller (cca 3 times) than original ... 问题是创建的位图比原始位图小两倍(cca 3倍)。

Use: 采用:

BitmapFactory.Options opt = new BitmapFactory.Options();
opt.inDensity = DisplayMetrics.DENSITY_DEFAULT;
opt.inTargetDensity = DisplayMetrics.DENSITY_DEFAULT;
opt.inScaled = false;

According to the documentation it should work with opt.inScaled=false only but this is Android after all... I've been using that code for many years now and it works perfectly for me. 根据文档,它仅应与opt.inScaled = false一起使用,但这毕竟是Android。我已经使用该代码很多年了,并且对我来说非常合适。

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

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