Found a very easy way to store images in sqllite[SOLVED]

Put your problem here if it does not fit any of the other categories.

Found a very easy way to store images in sqllite[SOLVED]

Postby rahul_mawkins » Fri Apr 04, 2008 8:37 pm

I am again wondering if I spend the whole night fig something out or I did created something meaning full
Since cursor dont give you anyway to retrive BLOG then I tried storing image as String

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


}

The reverse is

public static Bitmap getBitMapFromString(String src)
{
return BitmapFactory.decodeByteArray(src.getBytes(),0,src.getBytes().length);

}

If some of you are struggling or have a better way please add in here

cheers
RM
rahul_mawkins
Developer
Developer
 
Posts: 34
Joined: Wed Feb 27, 2008 4:09 am

Top

Postby NithinG » Mon May 12, 2008 11:43 am

Hi
can you tell me.. Is there any way to compress an object and save it to SQlite database. The problem is i am havin an object of very bigsize. So im not able to store and retrieve it.

Reply as soon as possible.

Thanks and regards,

NithinG
NithinG
Developer
Developer
 
Posts: 36
Joined: Wed Feb 27, 2008 6:24 am

Postby rahul_mawkins » Wed May 14, 2008 2:02 am

Bro I am not sure how to compress an object but yah they have given a way to compress the bitmaps

How about you serialize the object by implementing serializable/externalizable interface. In serializable method try converting everything into string and store it in database

Let me know if it works else I dont mind doing more research for you
cheers
RM
rahul_mawkins
Developer
Developer
 
Posts: 34
Joined: Wed Feb 27, 2008 4:09 am

Postby NithinG » Wed May 14, 2008 5:39 am

ya tats wat i did. i used serialization and all.. but again the string tat it'll create is of very big size.. it wont store tat much big sized object
NithinG
Developer
Developer
 
Posts: 36
Joined: Wed Feb 27, 2008 6:24 am

Postby chris » Thu May 15, 2008 10:02 pm

then , maybee you should wonder if you really need to store the data into the DB.
Why not save the path to the file in the DB and store the file on the filesystem ?

also , i would encode the data in base 64 before inserting it as a string into the database (depending from the database , encoding type ,... you might need this or not)

cheers
chris
Junior Developer
Junior Developer
 
Posts: 18
Joined: Sat Feb 02, 2008 4:39 pm

Top

Return to Other Coding-Problems

Who is online

Users browsing this forum: No registered users and 17 guests