简体   繁体   中英

Cropping rectangular area from bitmao using YuvImage produces strange result

I have attempted to crop image from a Bitmap using YuvImage like this:

        Bitmap bitmap=params[0];
        ByteArrayOutputStream bos=new ByteArrayOutputStream();
        bitmap.compress(Bitmap.CompressFormat.JPEG, 100, bos);
        byte[] data=bos.toByteArray();
        //bos=null;
        YuvImage yuvImage=new YuvImage(data, ImageFormat.NV21, bitmap.getWidth(), bitmap.getHeight(),null);
        bos=new ByteArrayOutputStream();
        boolean isCropped=yuvImage.compressToJpeg(rect, 100, bos);
        if(isCropped)
            data=bos.toByteArray();
        bitmap=BitmapFactory.decodeByteArray(data, 0, data.length);
        return bitmap;

This causes the resulting image 奇怪又可怕...就像一台旧的黑白电视

Is there an alternate approach in order to crop and save the image without using the Intent .

您将Bitmap.CompressFormat.JPEG视为ImageFormat.NV21,这不应该是真的。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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