Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/wordpress/13.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
Java Base64.encodeToString()在Android中不工作_Java_Android_Encode - Fatal编程技术网

Java Base64.encodeToString()在Android中不工作

Java Base64.encodeToString()在Android中不工作,java,android,encode,Java,Android,Encode,我有一个位图,现在我想把它转换成imageUri或字符串, 我在这里使用这段代码,但它只是不工作,而不是返回imageUri,返回一个长的随机文本 这是我的密码: ByteArrayOutputStream baos = new ByteArrayOutputStream(); saveBitmap.compress(Bitmap.CompressFormat.JPEG, 75, baos); String path

我有一个位图,现在我想把它转换成imageUri或字符串, 我在这里使用这段代码,但它只是不工作,而不是返回imageUri,返回一个长的随机文本

这是我的密码:

ByteArrayOutputStream baos = new ByteArrayOutputStream();
                    saveBitmap.compress(Bitmap.CompressFormat.JPEG, 75, baos);
                    String path = Base64.encodeToString(baos.toByteArray(),Base64.DEFAULT);

这就是我得到的:

Base64.encodeToString将字节数组编码为字符串。这不是你的uri。这是Base64中的图像/位图。您可以使用合适的Base64.decode返回字节数组

要获取uri,可以使用其他一些选项,包括
Uri.fromFilenew Fileyour_file_路径

Base64.encodeToString将字节数组编码为字符串。这不是你的uri。这是Base64中的图像/位图。您可以使用合适的Base64.decode返回字节数组

要获取uri,可以使用其他一些选项,包括
Uri.fromFilenew Fileyour_file_路径

试试下面的方法,应该是可行的

byte[] data = convert image in byte.
String base64 = Base64.encodeToString(data, Base64.DEFAULT);


byte[] data = Base64.decode(base64, Base64.DEFAULT);
String text = new String(data, "UTF-8");

试试下面的方法,应该是工作

byte[] data = convert image in byte.
String base64 = Base64.encodeToString(data, Base64.DEFAULT);


byte[] data = Base64.decode(base64, Base64.DEFAULT);
String text = new String(data, "UTF-8");

对不起,伙计们,我以为Base64.encodeToString会将imagePath返回给我,但我错了。不管怎样,我找到了解决办法

这是我使用的代码

ByteArrayOutputStream baos = new ByteArrayOutputStream();
                    saveBitmap.compress(Bitmap.CompressFormat.JPEG, 75, baos);
                    String path = MediaStore.Images.Media.insertImage(getContentResolver(),saveBitmap,"Title",null);

对不起,伙计们,我以为Base64.encodeToString会将imagePath返回给我,但我错了。不管怎样,我找到了解决办法

这是我使用的代码

ByteArrayOutputStream baos = new ByteArrayOutputStream();
                    saveBitmap.compress(Bitmap.CompressFormat.JPEG, 75, baos);
                    String path = MediaStore.Images.Media.insertImage(getContentResolver(),saveBitmap,"Title",null);
使用Base64.NO\u WRAP代替Base64.DEFAULT

使用Base64.NO\u WRAP代替Base64.DEFAULT


这是图像的base64编码版本。你为什么期望一个imageUri?我如何从位图中获取图像uri…你能告诉我吗?这是你图像的base64编码版本。为什么你期望一个imageUri?我如何从位图中获取图像uri…你能告诉我吗?请注意,我没有文件路径,我只有一个位图…无论如何,我得到了解决方案,请看我的答案。感谢您的努力…感谢您提供的信息请注意,我没有文件路径,我只有一个位图…不管怎样,我得到了解决方案,请参阅我的答案。感谢你的努力谢谢你通知我