How to Store Pictures/voices in SQLite Databases

Source: Internet
Author: User
How can I use the blob type of sqlite to store image audio files. It is known that the image or voice url is received. Can the image or voice be stored in the sqlite database through the received url to be stored in the sqlite database. Thank you. How can I use the blob type of sqlite to store image audio files.
It is known that the image or voice url is received. Can the image or voice be stored in the sqlite database through the received url to be stored in the sqlite database.
Thank you.

Reply content:

How can I use the blob type of sqlite to store image audio files.
It is known that the image or voice url is received. Can the image or voice be stored in the sqlite database through the received url to be stored in the sqlite database.
Thank you.

1. HttpConnect obtains image data;

2. Convert image data to binary data and write it to the database
ContentValues values = new ContentValues ();
Final ByteArrayOutputStream OS = new ByteArrayOutputStream ();
Bmp. compress (Bitmap. CompressFormat. PNG, 100, OS );
Values. put ("express_img", OS. toByteArray ());
Values. put ("express_name", "zf ");
Values. put ("express_no", "zf ");
GetContentResolver (). insert ("express", values );

3. Read Bitmap from SQLite
Byte [] in = cur. getBlob (cur. getColumnIndex ("express_img "));
Bmpout = BitmapFactory. decodeByteArray (in, 0, in. length );

4. display on ImageView

ImageView imageView = (ImageView) view. findViewById (R. id. img );
ByteArrayInputStream stream = new ByteArrayInputStream (cur. getBlob (cur. getColumnIndex ("express_img ")));
ImageView. setImageDrawable (Drawable. createFromStream (stream, "img "));

    $url = "http://....../logo.png";    $handle = fopen($url,"rb");    $contents = fread($handle,filesize($url));

Var_dump ($ contents );
Why do I read a url image as a binary image and output $ contents as: bool (false)

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.