Heim >Backend-Entwicklung >PHP-Tutorial >SQLite数据库如何存储图片/语音

SQLite数据库如何存储图片/语音

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOriginal
2016-06-06 20:23:482127Durchsuche

请问如何利用sqlite的blob类型存储图片语音文件。
已知目前接收到的是一个图片或者语音的url地址,能否在存入sqlite数据库的时候把图片或者语音通过接收到的url地址存储到sqlite数据库中。
谢谢。

回复内容:

请问如何利用sqlite的blob类型存储图片语音文件。
已知目前接收到的是一个图片或者语音的url地址,能否在存入sqlite数据库的时候把图片或者语音通过接收到的url地址存储到sqlite数据库中。
谢谢。

1、HttpConnect获取图片数据;

2、将图像数据转换二进制写入数据库
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、从SQLite中读取Bitmap
byte[] in=cur.getBlob(cur.getColumnIndex("express_img"));
bmpout=BitmapFactory.decodeByteArray(in,0,in.length);

4、 显示在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"));

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

var_dump($contents);
为什么这样把一个url的图片读取为二进制,输出$contents为:bool(false)

Stellungnahme:
Der Inhalt dieses Artikels wird freiwillig von Internetnutzern beigesteuert und das Urheberrecht liegt beim ursprünglichen Autor. Diese Website übernimmt keine entsprechende rechtliche Verantwortung. Wenn Sie Inhalte finden, bei denen der Verdacht eines Plagiats oder einer Rechtsverletzung besteht, wenden Sie sich bitte an admin@php.cn