fritz
fritz

Reputation: 111

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 ...

Upvotes: 0

Views: 952

Answers (1)

Emanuel Moecklin
Emanuel Moecklin

Reputation: 28856

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.

Upvotes: 1

Related Questions