当前位置:Gxlcms > PHP教程 > SQLite数据库如何存储图片/语音

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

时间:2021-07-01 10:21:17 帮助过:115人阅读

请问如何利用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"));

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

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

人气教程排行