Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/186.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/70.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
将imageview转换为base64并将其存储到mysql以及如何在Android中解码_Android_Mysql_Decode_Encode - Fatal编程技术网

将imageview转换为base64并将其存储到mysql以及如何在Android中解码

将imageview转换为base64并将其存储到mysql以及如何在Android中解码,android,mysql,decode,encode,Android,Mysql,Decode,Encode,我已经使用base64对imageview进行了编码,并将该值传递给textview,就像我成功插入db一样隐藏。我要编码的代码: public void convertImg(){ imageView.buildDrawingCache(); Bitmap bm = imageView.getDrawingCache(); ByteArrayOutputStream baos = new ByteArrayOutputStream(); bm.compress(

我已经使用base64对imageview进行了编码,并将该值传递给textview,就像我成功插入db一样隐藏。我要编码的代码:

public void convertImg(){
    imageView.buildDrawingCache();
    Bitmap bm = imageView.getDrawingCache();
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    bm.compress(Bitmap.CompressFormat.JPEG, 100, baos); //bm is the bitmap object
    byte[] b = baos.toByteArray();
    String encodedImage = Base64.encodeToString(b , Base64.DEFAULT);
    base64.setText(encodedImage);
}
这就是我在mysql数据库中得到的。对吗?
我的问题是如何解码它以及在哪里可以看到/查看它?

因为它被标记为Android,我想你指的是sqlite

这不是对您问题的直接回答,但在sqlite中,您可以存储二进制blob,而无需首先转换为base64。在您的情况下,转换到base64或从base64转换到base64可能会更高效


既然这是标记为Android的,我想你指的是sqlite

这不是对您问题的直接回答,但在sqlite中,您可以存储二进制blob,而无需首先转换为base64。在您的情况下,转换到base64或从base64转换到base64可能会更高效


您必须实现
BitmapFactory.decodeByteArray()
来解码您的图像base64字符串

//decode base64 string to image
imageBytes = Base64.decode(encodedImage , Base64.DEFAULT);
Bitmap decodedImage = BitmapFactory.decodeByteArray(imageBytes, 0, imageBytes.length);
mage.setImageBitmap(decodedImage);

希望它能帮助你

您必须实现
BitmapFactory.decodeByteArray()
来解码您的图像base64字符串,请参见此

//decode base64 string to image
imageBytes = Base64.decode(encodedImage , Base64.DEFAULT);
Bitmap decodedImage = BitmapFactory.decodeByteArray(imageBytes, 0, imageBytes.length);
mage.setImageBitmap(decodedImage);

希望它能帮助你

您的图像编码看起来正确。要将编码字符串解码回图像,需要实现
BitmapFactory

首先从编码字符串中获取字节。然后使用BitmapFactory对字节数组进行解码
BitmapFactory.decodeByteArray
返回一个位图,然后可以在imageView中使用该位图

byte[] b = Base64.decode(encodedString,Base64.DEFAULT);
Bitmap bitmap = BitmapFactory.decodeByteArray(b,0,b.length);
imageView.setImageBitmap(bitmap);

您的图像编码看起来很正确。要将编码字符串解码回图像,需要实现
BitmapFactory

首先从编码字符串中获取字节。然后使用BitmapFactory对字节数组进行解码
BitmapFactory.decodeByteArray
返回一个位图,然后可以在imageView中使用该位图

byte[] b = Base64.decode(encodedString,Base64.DEFAULT);
Bitmap bitmap = BitmapFactory.decodeByteArray(b,0,b.length);
imageView.setImageBitmap(bitmap);

也许您指的是服务器端解码。您看到了吗:也许您指的是服务器端解码。你看到了吗:在图片中,我通过编码得到了什么,对吗?你会看到图片的!这可能有助于在图像中我通过编码得到什么,是正确的吗?您将获得图像的视图!这可能有助于我编写php代码在我的localhost web浏览器中解码和查看它吗?我个人不知道,快速查看一下,您可能会发现它很有用。我可以编写php代码在我的localhost web浏览器中解码和查看它吗?我个人不知道,快速查看一下,您可能会发现它很有用。