Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/196.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/7/image/5.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 使用Base64将位图设置为字符串。你怎么能修好它?_Android_Image_Base64_Encode - Fatal编程技术网

Android 使用Base64将位图设置为字符串。你怎么能修好它?

Android 使用Base64将位图设置为字符串。你怎么能修好它?,android,image,base64,encode,Android,Image,Base64,Encode,Base64.encode不想接受参数“image”,我也不知道如何解决这个问题。我以前从未用过Base64 Bitmap bm = BitmapFactory.decodeStream(this.getContentResolver().openInputStream(uri)); ByteArrayOutputStream baos = new ByteArrayOutputStream(); bm.comp

Base64.encode不想接受参数“image”,我也不知道如何解决这个问题。我以前从未用过Base64

Bitmap bm = BitmapFactory.decodeStream(this.getContentResolver().openInputStream(uri));
                    ByteArrayOutputStream baos = new ByteArrayOutputStream();  
                    bm.compress(Bitmap.CompressFormat.JPEG, 100, baos); //bm is the bitmap object   
                    byte[] image = baos.toByteArray();

                    String encodedImage = Base64.encode(image);

编辑:我使用Base64的外部包,它至少接受两个参数。可能尝试
Base64.encode(image,Base64.DEFAULT)

“Base64类型中的方法encode(ByteBuffer,ByteBuffer)不适用于参数(byte[],String)”“我尝试转换为ByteBuffer,但仍然存在一个问题……看起来很简单,但我像个傻瓜一样被卡住了。没有方法编码(ByteBuffer,ByteBuffer)在android.util.Base64上。你确定使用的是android Base64实现吗?我下载了一个Base64包,为所有版本的android制作了一个应用程序。Android.util.Base64仅在2.2版本的Android之后才可用。也许你应该更新你的原始问题,让人们知道你使用的是什么Base64软件包。真遗憾,我看错了文档…答案是encodeBytes。可能是重复的