Android 图像编解码

Android 图像编解码,android,json,encoding,decoding,Android,Json,Encoding,Decoding,我想使用json将图像插入“MYSQL”数据库,并将插入的图像检索到“ImageView”中。我完成了编码和插入图像,但无法进行解码,并将图像设置为“ImageView” //Encoding the imageView Bitmap bitmap = BitmapFactory.decodeResource(getResources(),R.id.imageVieweditprofileuserphoto); BitmapDrawable drawabl

我想使用json将图像插入“MYSQL”数据库,并将插入的图像检索到“ImageView”中。我完成了编码和插入图像,但无法进行解码,并将图像设置为“ImageView”

    //Encoding the imageView
        Bitmap bitmap = BitmapFactory.decodeResource(getResources(),R.id.imageVieweditprofileuserphoto);
        BitmapDrawable drawable = (BitmapDrawable) imageofuser.getDrawable();
        bitmap = drawable.getBitmap();
        ByteArrayOutputStream stream = new ByteArrayOutputStream();
        bitmap.compress(Bitmap.CompressFormat.PNG,90, stream); //compress to which format you want.
        byte [] byte_arr = stream.toByteArray();
        String image_str= Base64.encodeToString(byte_arr, 1);

//Image after encoding at server side(Database MySql)
        iVBORw0KGgoAAAANSUhEUgAAAGAAAABgCAIAAABt+uBvAAAAA3NCSVQICAjb4U/gAAAQPElEQVR4
        nO1c6W9cR3Kv6u735s0Mh4dFUjy0luUj9lo+13YQJIGdYAUs8ilAPuRPyJ+XAPFugBjYrLO2s+s1
        1rZsyxJ18BDP4XDueWcflQ/9ZjjiIUp8b0jCqx9IDTVHv+rfVFVXV1c9rFar8AzHg523ABcdzwg6
        Ac8IOgHPCDoBzwg6Ac8IOgHP

//Decoding the imageView
         imageofuser=(ImageView)view.findViewById(R.id.imageVieweditprofileuserphoto);
         byte[] imagefromserver=Base64.decode(Utility.userimage, Base64.NO_WRAP);
         Bitmap bmp=BitmapFactory.decodeByteArray(imagefromserver, 0, imagefromserver.length);
         imageofuser.setImageBitmap(bmp);

您可以在服务器中创建文件夹并将图像放入该文件夹。然后获取图像url并将其作为字符串添加到表中。然后将其转换为JSON,然后将其转换为位图并设置为imageView背景。我想从gallery或通过camera拾取图像为什么要在此处添加数据库部件?我想从gallery或通过camera拾取图像,然后再次将该图像插入数据库将该图像检索到imageView我之前尝试过这样做。但这很难。我将图像url或路径放入db,然后通过url检索图像。