문제

I have a drawing application. I need the application to recover from minimization (clicking back until the application minimizes). As i understood from several forums the best way and the simplest to do it is by saving the bitmap to a local temporary folder, and on open the bitmap from it. What i didn't find is any tutorial or examples how can it be done.

Can you please suggest some good tutorial on this issue or maybe in case you have done such a thing before post your solution to this issue.

Thanks,

도움이 되었습니까?

해결책

Better to use Android SharePreference to Store Image Bitmap.

Save Image Bitmap.

public boolean saveImage(Context context, Bitmap realImage) 
{
    Editor editor = context.getSharedPreferences(KEY, Context.MODE_PRIVATE).edit();

    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    realImage.compress(Bitmap.CompressFormat.JPEG, 100, baos);   
    byte[] b = baos.toByteArray(); 

    String encodedImage = Base64.encodeToString(b, Base64.DEFAULT);

    editor.putString("FacebookImage", encodedImage);
    return editor.commit();
}

Get Image Bitmap

 public Bitmap getImageBitmap(Context context)
    {
         Bitmap bitmap = null;
         SharedPreferences savedSession = context.getSharedPreferences(KEY, Context.MODE_PRIVATE);
         String saveimage=savedSession.getString("FacebookImage", "");
         if( !saveimage.equalsIgnoreCase("") ){
                byte[] b = Base64.decode(saveimage, Base64.DEFAULT);
                 bitmap = BitmapFactory.decodeByteArray(b, 0, b.length);
            }
        return bitmap;
    }

After get Image bitmap show it image view or other view.

Thanks

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top