Reducing the size of the photo

1

I'm recording the photos taken by my application in the sqlite database, I know it's not very recommended anymore, I need to transfer these photos to a central database that unifies all data in all applications.

The way I'm reducing and writing to the sqlite database is this way:

 Bitmap bitmap = (App.bitmap);
 MemoryStream stream = new MemoryStream();
 bitmap.Compress(Bitmap.CompressFormat.Jpeg, 100, stream);
 byte[] ba = stream.ToArray();
 string bal = Base64.EncodeToString(ba, Base64.Default);

App.bitmap is that you receive the snapshot photo in the OnActivityResult method. After that, I record in the bank, passing the variable "bal".

The problem is the time to get this image, in my select I get the following error:

Java.Lang.IllegalStateException: Couldn't read row 0, col 0 from CursorWindow. Make sure the Cursor is initialized correctly before accessing data from it.

Searching the internet for this error is returning because of the size of the cursor that have a maximum of 2MB.

Am I compressing the image the wrong way? Or is the way I'm getting the photo in the select wrong?

My select is as follows:

  private void MostraFoto()
    {
        players = new ArrayList();
        clslogin abrir = new clslogin();

        //ultimoatend();
        var path = System.IO.Path.Combine(System.Environment.GetFolderPath(System.Environment.SpecialFolder.Personal), abrir.Nome_banco);
        _connection = new SQLiteConnection(new SQLitePlatformAndroid(), path);
        sqldb = SQLiteDatabase.OpenDatabase(path, null, DatabaseOpenFlags.OpenReadwrite);

        sqldb = SQLiteDatabase.OpenOrCreateDatabase(path, null);


        Android.Database.ICursor sqldb_cursor = null;
        sqldb_query = @"select foto,descricao from  foto
        where lugar_id = '"+abrir.Id_lugar+"' and pessoa_id = '"+abrir.Id_pessoa+"'";
        sqldb_cursor = sqldb.RawQuery(sqldb_query, null);

        if (!(sqldb_cursor != null))
        {

        }

        if (sqldb_cursor.MoveToFirst())
        {   
             foto = (sqldb_cursor.GetString(0));
            descricao = (sqldb_cursor.GetString(1));
        }
    }

Without fetching the photo, the select does not return the error quoted above. I'm counting on your help.

    
asked by anonymous 06.07.2017 / 21:11

0 answers