Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

How to Increase JPG file size?

I'm getting byte image data from native camera, takePicture and pictureCallBack. And using opencv libraries for rotating, croping and resising. I'm using Bitmap.ComptressFormat and FileExportStream to save image. Everything work fine. But It have to create jpg file size grather than 20KB but sometimes it's getting smaller than 20KB. I also add exif datas but it's doest't give target file size values.

Is there any way to increase file size? I tried imwrite but it give smallest results. I couldn't success to find save jpg without compression.

PictureCallback myPictureCallback_JPG = new PictureCallback(){
    @Override
    public void onPictureTaken(byte[] data, Camera camera) {

        File pictureFile = getJpgFile();

       data = cropImage2(data);

        try {
            FileOutputStream fos = new FileOutputStream(pictureFile);
            fos.write(data);
            fos.close();

            addEXIFData(pictureFile);

        } catch (FileNotFoundException e) {
            Log.d("Method.PictureCallBack", "File not found: " + e.getMessage());
        } catch (IOException e) {
            Log.d("Method.PictureCallBack", "Error accessing file: " + e.getMessage());
        }

public byte[] cropImage (byte[] data) {
        Mat lastMat = new Mat();

        Mat mat1_img = Imgcodecs.imdecode(new MatOfByte(data), Imgcodecs.CV_LOAD_IMAGE_UNCHANGED);

        Mat mat2_rotated = new Mat();

        Core.flip(mat1_img.t(), mat2_rotated, 1);

        Mat mat3_cropped = new Mat(mat2_rotated, cropRect);

        Imgproc.resize(mat3_cropped, lastMat, cropSize);

        Imgproc.cvtColor(lastMat, lastMat, Imgproc.COLOR_BGR2RGB,1);
        Bitmap bitmapImg = Bitmap.createBitmap(lastMat.cols(), lastMat.rows(),Bitmap.Config.ARGB_8888);
        Utils.matToBitmap(lastMat, bitmapImg);

        ByteArrayOutputStream bos = new ByteArrayOutputStream();

        bitmapImg.compress(Bitmap.CompressFormat.JPEG, 100, bos);

        return bos.toByteArray();
    }