ORM LITE problems in saving columns bytes

Posted on

Question :

My user app can use the camera to take a photo and need to save it in the database.
To save to the database I convert the image to an array of bytes, however I noticed a problem in this process when the camera resolution is high (4: 3 16 MB) does not work and when I get smaller as 16: 9 (6 MB ) it works.
I’m using ORMLite to save and it does not return any error exception when the camera is in high resolution, does anyone know what it can be?

        Bitmap photo = null;
        File file = new File(mCurrentPhotoPath);
        photo = MediaStore.Images.Media.getBitmap(
        ByteArrayOutputStream stream = new ByteArrayOutputStream();
        photo.compress(Bitmap.CompressFormat.JPEG, 100, stream);
        bytesImage = stream.toByteArray();

        CheckListPendente CheckListPendente2 = new CheckListPendente();
        CheckListResposta resposta = new CheckListResposta();
        if (bytesImage != null) {
        checkListDao = CheckListRespostaDao(helper.getConnectionSource());


Answer :

Well I searched for this method


And I ended up finding some articles about it, the bad thing is that most of them are in English (I do not know if you can read “good”, but it’s worth a look and understand)

LINK 1: link

LINK 2: link

LINK 3: link

LINK 4: link

Well what can I say,

photo.compress(Bitmap.CompressFormat.JPEG, 100, stream);

This your line is compressing the image to the JPEG format, and in its second method parameter:

compress(<1 parâmetro>,<2 parâmetro>,<3 parâmetro>)

Indicates the compression type being 0 maximum and 100 minimum / near zero ( SEE LINK 2 )
(in MB / KB..etc) ( VIEW LINK 1 and 3 ) )

What I recommend doing is

1 – convert all images to a standard resolution

2 – do the necessary processing (in this case convert the image to an array of bytes)

3 – Be Happy

NOTE: I will not go into code because I do not handle ORMLite so much, but I believe that with a little time and dedication you can do it alone, it is worth taking a look at link 2 because there it does a resolution conversion / sequencing.

OBS2: Link 4 shows how to compress the image in the smallest possible way, thinking of code and file / variable size would be smaller values (which would not break the memory limit in the application, it’s worth a look)


Leave a Reply

Your email address will not be published. Required fields are marked *