android– 如何远程读取Base64编码图像文件

android– 如何远程读取Base64编码图像文件,第1张

概述我有一个图像文件,我使用Base64编码上传到服务器(通过转换为字符串).服务器将该字符串存储在文本文件中,并将该URL提供给该文本文件.任何人都可以指导我,如何远程从该文本文件中获取编码的字符串?解决方法:使用它来解码/编码(只有Java方式)publicstaticBufferedImagedecodeTo

我有一个图像文件,我使用Base64编码上传到服务器(通过转换为字符串).
服务器将该字符串存储在文本文件中,并将该URL提供给该文本文件.

任何人都可以指导我,如何远程从该文本文件中获取编码的字符串?

解决方法:

使用它来解码/编码(只有Java方式)

public static BufferedImage decodetoImage(String imageString) {    BufferedImage image = null;    byte[] imageByte;    try {        BASE64Decoder decoder = new BASE64Decoder();        imageByte = decoder.decodeBuffer(imageString);        ByteArrayinputStream bis = new ByteArrayinputStream(imageByte);        image = ImageIO.read(bis);        bis.close();    } catch (Exception e) {        e.printstacktrace();    }    return image;}public static String encodetoString(BufferedImage image, String type) {    String imageString = null;    ByteArrayOutputStream bos = new ByteArrayOutputStream();    try {        ImageIO.write(image, type, bos);        byte[] imageBytes = bos.toByteArray();        BASE64Encoder encoder = new BASE64Encoder();        imageString = encoder.encode(imageBytes);        bos.close();    } catch (IOException e) {        e.printstacktrace();    }    return imageString;}

希望它有所帮助

更新

AndroID的方式

从Base64字符串使用获取图像

byte[] decodedString = Base64.decode(encodedImage, Base64.DEFAulT);Bitmap decodedByte = BitmapFactory.decodeByteArray(decodedString, 0, decodedString.length);

UPDATE2

要从服务器读取文本文件,请使用:

try {    URL url = new URL("example.com/example.txt");    BufferedReader in = new BufferedReader(new inputStreamReader(url.openStream()));    String str;    while ((str = in.readline()) != null) {        // str is one line of text; readline() strips the newline character(s)    }    in.close();} catch (MalformedURLException e) {} catch (IOException e) {}

下次尝试问正确.

总结

以上是内存溢出为你收集整理的android – 如何远程读取Base64编码图像文件全部内容,希望文章能够帮你解决android – 如何远程读取Base64编码图像文件所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/web/1106577.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-28
下一篇 2022-05-28

发表评论

登录后才能评论

评论列表(0条)

保存