Hello,
I want to store image in sqlite database.
I tried to store it using BLOB and String, in both cases it store the
image and can retrieve it but when  i convert it to Bitmap using
BitmapFactory.decodeByteArray(...) it return null.
Below is my code please have a look and suggest me where i m making
mistake.

public class imagesql extends Activity {
    /** Called when the activity is first created. */

        Bitmap bi=null;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);

        InputStream in=this.getResources().openRawResource
(R.drawable.dig);
        bi  = BitmapFactory.decodeStream(in);
        Log.i("bitmap1",""+bi);
        ImageView iv1=(ImageView)findViewById(R.id.img1);
        iv1.setImageBitmap(bi);


        String str= convertBitmapToString(bi);
        Log.i("image string",str);
        myDB a=new myDB(this);
        a.open();
        a.insertTag(str);

        Cursor c=a.fetchData(myDB.TABLE_NAME_TAG,new String[]
{myDB.KEY_TAG_IMG},null,null);
        startManagingCursor(c);
        int rc=c.getCount();

        ImageView iv;
        c.moveToFirst();

        if(rc!=0)
        {
                String s=c.getString(0);
                Log.i("cursor string image",s);
                Bitmap bitmap=getBitMapFromString(s);
                Log.i("bitmap2",""+bitmap);
                 iv=(ImageView)findViewById(R.id.img);
                 iv.setImageBitmap(bitmap);
        }
    }

    public static String convertBitmapToString(Bitmap src)
    {
    ByteArrayOutputStream os=new ByteArrayOutputStream();
    src.compress(android.graphics.Bitmap.CompressFormat.PNG, 100,
(OutputStream) os);
    return os.toString();
    }

    public static Bitmap getBitMapFromString(String src)
    {
        Log.i("b=",""+src.getBytes().length);//returns 12111 as a length.
    return BitmapFactory.decodeByteArray(src.getBytes(),0,src.getBytes
().length);
    }

}

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to