Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/google-maps/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 将Drawable转换为BLOB数据类型sqlite问题_Android_Google Maps - Fatal编程技术网

Android 将Drawable转换为BLOB数据类型sqlite问题

Android 将Drawable转换为BLOB数据类型sqlite问题,android,google-maps,Android,Google Maps,在这里,我附加了代码,其中将图像存储在Drawable中,并使用BLOB数据类型传递到数据库 我尝试了这个,它可以正确地存储,但不能显示图像 Insall_app_db i1 = new Insall_app_db(); i1.createDatabse(DB, getBaseContext()); i1.createTable(tableName, getBaseContext()); BitmapDrawable bitDw = ((BitmapDrawable) icon); Bitma

在这里,我附加了代码,其中将图像存储在Drawable中,并使用BLOB数据类型传递到数据库

我尝试了这个,它可以正确地存储,但不能显示图像

Insall_app_db i1 = new Insall_app_db();
i1.createDatabse(DB, getBaseContext());
i1.createTable(tableName, getBaseContext());

BitmapDrawable bitDw = ((BitmapDrawable) icon);
Bitmap bitmap = bitDw.getBitmap();
ByteArrayOutputStream stream = new ByteArrayOutputStream();

bitmap.compress(Bitmap.CompressFormat.JPEG, 100, stream);
byte[] imageInByte = stream.toByteArray();
String iconStr = imageInByte.toString();
i1.insertDataUser(tableName,appid,appname2,pname, versionName, versionCode,iconStr, long_date);
int appid = i1.GetUserData(getBaseContext(), tableName);

System.out.println("-------------------------------");
byte[] imaaa = iconStr.getBytes();

Bitmap aaa = convertByteArrayToBitmap(imaaa);

LayoutInflater li = getLayoutInflater();
v = li.inflate(R.layout.icon,null);
TextView tv = (TextView)v.findViewById(R.id.icon_text);
tv.setText(i1.app_name);
ImageView iv = (ImageView)v.findViewById(R.id.icon_image);
iv.setImageResource(R.drawable.icon);
Bitmap bitmap2 = ((BitmapDrawable)icon).getBitmap();
iv.setImageBitmap(aaa);

还有其他解决方案吗?

为了从sqlite数据库获取图像,我使用了以下方法:

 ByteArrayOutputStream baos = new ByteArrayOutputStream();
 byte[] data=cur.getBlob(cur.getColumnIndex("img"));
 baos.write(data);
 InputStream is = database.getImageStream(someId);
 Bitmap img = BitmapFactory.decodeStream(is);
然后,要显示我用于执行以下操作的图像:

 ByteArrayOutputStream baos = new ByteArrayOutputStream();
 byte[] data=cur.getBlob(cur.getColumnIndex("img"));
 baos.write(data);
 InputStream is = database.getImageStream(someId);
 Bitmap img = BitmapFactory.decodeStream(is);
下面的代码显示了如何将图像保存到BLOB字段中

ByteArrayOutputStream bos = new ByteArrayOutputStream();      
image.compress(CompressFormat.PNG, 100, bos); 
byte[] bytes = bos.toByteArray(); 
可以使用将字节添加到sqlite

 initialValues.put("<fieldname>", bytes); //ofcourse <fieldname> is of type BLOB
initialValues.put(“,字节)//当然是BLOB类型

如何使用BLOB数据类型在数据库中存储BAO?Drawable icon=p.applicationInfo.loadIcon(getPackageManager());水滴;如何将图标存储到Blob中?ByteArrayOutputStream bos=new ByteArrayOutputStream();this.image.compress(CompressFormat.PNG,100,bos);byte[]bytes=bos.toByteArray();可以使用initialValues.put(“,bytes”)将字节添加到sqlite中//当然是BLOB类型