gpt4 book ai didi

android - 无法打开从 base64 解码的 Intent 中的图像

转载 作者:行者123 更新时间:2023-11-30 00:22:51 32 4
gpt4 key购买 nike

我正在发送通过 Intent 从 base64 解码的图像,但外部应用程序无法读取该图像。我想这与转换有关。这就是我转换和发送图像的方式:

public void onDownloadStart(String url, String userAgent, String contentDisposition, String mimetype, long contentLength) {


if(isStoragePermissionGranted()){
try {
if(url != null) {
FileOutputStream fos;
fos = context.openFileOutput("img.png", Context.MODE_PRIVATE);
System.out.println(url);
byte[] decodedStr = Base64.decode(url, Base64.NO_WRAP);
fos.write(decodedStr);

Intent sendIntent = new Intent();
sendIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
sendIntent.setAction(Intent.ACTION_SEND);
File imagePath = new File(String.valueOf(context.getFilesDir()));
File newFile = new File(imagePath, "img.png");
sendIntent.putExtra(Intent.EXTRA_STREAM, FileProvider.getUriForFile(context, context.getApplicationContext().getPackageName() + ".FileProvider", newFile));
sendIntent.setType("image/png");

getContext().startActivity(sendIntent);
fos.flush();
fos.close();
// Toast.makeText(context.getApplicationContext(), "Downloading File...", Toast.LENGTH_LONG).show();
}
} catch (IOException e) {
e.printStackTrace();
}
}

我得到的 base64 看起来像这样(我无法将其转换为在线转换器上的图像,但如果我删除最后一个字符,我可以看到图像顶部的一点点):

data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAArgAAAIACAYAAABpWR83AAAgAElEQVR4Xux9B3xU15X+ESBUEEIVgbpAgCq9V9tg3B1jO3FLcUnsuCa2s7v/TeJksym7yaa6pttOcY2Nu8G4UYzpVRIgCUmAJBCqSEIFUf7nvNGM5o3KtPdm3sz7bn6s1tJr99x7v3vud8/5bsjdf3j+AqHAArAALAALwAKwACwAC8ACQWKBkLv/8Dd2cMXHDeF/+Ak7oB9gHAAHgAPAAeAAcAA4ENg4wA4uGNwgWaygGrAALAALwAKwACwAC8ACQtvewwzuBWZuQ/h/+Ak7oB9gHAAHgAPAAeAAcAA4EPA4cPfvmcENY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UFNxhcC/mOOLxzDx3nzlLr23ZrWJoI8JCqVDkxThZLTw0VPUdorpwiBnj0hqWKNOZIcfzwSSASTA2k4D2QfsAp4HTwAHf4gAzuC8xg+u/4wunsiSYaNCKn7qnsppKjp2wHde7guNf+xjc/apjfMWx/dKimYr2bA0nf+3me53VQxLMuvifXGdVUbDG4A52fKEcNpHAyWJ9DO7Ax/wlsxM8lhUb5Fphdy1HEJOi6rCD2Wkcj4jjEZ31T/zdfziE8YnxifGH8QccCDIcUBhcjZeWV80uULbuW5nFXLubNXCHeH48a+ZeNiNPTkOgihMNtKW00na97aheVlxQVBQcnnMdHwcs72lmJYP3RcnAjXosyZughEqc5bjZVz5jZnaQpdV18wr5HWG975C6OBeYFIkyCYEYzXJjAprv7yoh0cR15/tceQ+eB2oc/cT5eMQ4wTjBOME4AQ6YDwd0YXCXM/Oax

我尝试使用 Base64.NO_PADING 但这没有帮助。这个 base64 有什么问题?

感谢您的帮助和时间!

最佳答案

您需要删除"data:image/png;base64,":

String imageB64 = url.substring(22);
byte[] decodedStr = Base64.decode(imageB64, Base64.NO_WRAP);

关于android - 无法打开从 base64 解码的 Intent 中的图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45964794/

32 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com