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();
}
I'm not sure that your question is relative to opencv. But If you want to increase jpeg file size add noise to image
The image format Jpeg is lossy, there is no way to save an image in Jpeg without compression. You can use PNG image format for lossless compression.
Yes you right @LBerger. The question maybe is not all about opencv. But opencv libraries can make manipulation on image. I dont know maybe I can
to increase file. I added opencv library and all works fine. Just I need an example.
@Eduardo I now JPEG compressed image. But I need to have a little bit bigger jpeg file size. I edited the jpeg file in MSPaint, Photoshop etc. MSPaint save it smallest, but Photoshop can save bigger size if I chouse "add color profile" option.
I added exifdatas but this's not enough.
why on earth do you need a larger filesize ?
My app generate jpeg for special web application. The web application ask static resolution and at least 20KB file size. If jpeg file smaller than 20KB you cant upload the jpeg file. For the reason I need to generate fixed resolution and bigger than 20KB on earth.
you can add compression params to imwrite (try to set it to 0)
I tried to the all jpeg params: "JPEG_CHROMA_QUALITY, IMWRITE_JPEG_LUMA_QUALITY, IMWRITE_JPEG_OPTIMIZE, IMWRITE_JPEG_PROGRESSIVE, IMWRITE_JPEG_QUALITY, IMWRITE_JPEG_RST_INTERVAL"