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)