Convert to Bitmap

527 views
Skip to first unread message

rafaK

unread,
Oct 27, 2011, 9:53:13 PM10/27/11
to zxing
Hi,
In Android I'm using zxing project/source code to create a new
application. I changed the code in the class DecodeHandler to save
the image as a Bitmap but I think on this process I'm losing quality.
Anybody know another way to do that?


private void decode(byte[] data, int width, int height) throws
IOException {
long start = System.currentTimeMillis();
Result rawResult = null;
PlanarYUVLuminanceSource source =
CameraManager.get().buildLuminanceSource(data, width, height);
BinaryBitmap bitmap = new BinaryBitmap(new
HybridBinarizer(source));


try {

BitmapFactory.Options opt = new BitmapFactory.Options();
opt.inDither = true;
opt.inPreferredConfig = Bitmap.Config.ARGB_8888;

//Bitmap bmp = BitmapFactory.decodeByteArray(data, 0 ,
data.length, opt);

YuvImage yuvimage=new YuvImage(data, ImageFormat.NV21, width,
height, null);
ByteArrayOutputStream baos = new ByteArrayOutputStream();
yuvimage.compressToJpeg(new Rect(0, 0, width, height), 100,
baos);
byte[] jdata = baos.toByteArray();

// Convert to Bitmap
Bitmap bmp = BitmapFactory.decodeByteArray(jdata, 0,
jdata.length);
...............

Thanks,
Rafael.

Sean Owen

unread,
Oct 28, 2011, 10:55:58 AM10/28/11
to zx...@googlegroups.com
I don't think you've specified a question -- what is 'losing quality' and what are you trying to achieve?
Reply all
Reply to author
Forward
0 new messages