Reducing the photo size

Asked

Viewed 401 times

0

I am recording the photos taken by my application in the sqlite database, know that it is not much recommended more need to transfer these photos to a central database that unifies all data of all applications.

The way I am reducing and recording in 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 gets the photo taken on time in the Onactivityresult method. After that I write to the bank passing the variable "bal".

The problem is time to fetch 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 this error is returning because of the size of the cursor that have at most 2MB.

Am I compacting the image wrong? Or is the way I’m getting the photo in 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 select does not return the error mentioned above. I count your help.

  • 1

    I did some research on and I think your problem is exactly what you said: your cursor data probably exceeds 2MB. The way you search is right, otherwise another error should be shown.

  • 1

    @Perozzo Hello as you go, thank you for responding and sorry for the delay of my return. The problem was exactly that I was able to solve diminished the size of the image. I just still don’t know how to score as solved here at Stackoverflow...rsrsrs. Thanks again for the reply. Strong Hug.

  • Buenas! No problem. I believe that since you have reached a solution yourself, you can delete the question, or answer your own question by putting your solution and then mark it as an answer. Hug.

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.