扫码关注官方订阅号
请问如何利用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中读取Bitmapbyte[] 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)
PHP学习
技术支持
返回顶部
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"));
var_dump($contents);
为什么这样把一个url的图片读取为二进制,输出$contents为:bool(false)