Using SQLite to access image resources

Source: Internet
Author: User

In the past few days, the android icon is stored in the database due to issues related to the entire database.

Intent and bitmap objects are stored.

Storage intent:

There is a touri method in intent to convert intent to string type data, and then you can save intent as text type data into the database. The conversion type is as follows:

# Intent; Component = com. Android. Settings/. settings; End

Retrieve intent:

To obtain the intent, first use the getstring method of cursor to obtain the value in the database, and then call the parseuri method of intent to convert the string type to the intent type.

Next, let's talk about database access to image information.

Storage image: bitmap

Private byte [] geticondata (Bitmap bitmap ){

Int size = bitmap. getwidth () * bitmap. getheight () * 4;

Bytearrayoutputstream out = new bytearrayoutputstream (size );

Try {

Bitmap. Compress (bitmap. compressformat. PNG, 100, out );

Out. Close ();

} Catch (ioexception e ){

E. printstacktrace ();

}

Return out. tobytearray ();

}

Get image:

Bitmap geticonfromcursor (cursor C, int iconindex ){

Byte [] DATA = C. getblob (iconindex );

Try {

Return bitmapfactory. decodebytearray (data, 0, Data. Length );

} Catch (exception e ){

Return NULL;

}

}

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.