How SQLite database stores Pictures/voice

Source: Internet
Author: User
How can I use SQLite blob type to store picture voice files.
It is known that the current received is a picture or voice of the URL address, can be stored in the SQLite database when the image or voice through the received URL to the address of the SQLite database.
Thank you.

Reply content:

How can I use SQLite blob type to store picture voice files.
It is known that the current received is a picture or voice of the URL address, can be stored in the SQLite database when the image or voice through the received URL to the address of the SQLite database.
Thank you.

1, httpconnect obtain picture data;

2. Transform the image data into a binary system to write to the database
Contentvalues values = new Contentvalues ();
Final Bytearrayoutputstream os = new Bytearrayoutputstream ();
Bmp.compress (Bitmap.CompressFormat.PNG, MB, 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, displayed on the 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 picture of a URL as a binary with output $contents: 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.