【问题标题】:Bitmap to String using Base64. How can fix it?使用 Base64 到字符串的位图。如何解决?
【发布时间】:2011-03-03 23:43:14
【问题描述】:

Base64.encode 不想接受参数“图像”,我不知道如何弄清楚。我以前从未使用过 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的外部包http://iharder.sourceforge.net/current/java/base64/

【问题讨论】:

标签: android image base64 encode


【解决方案1】:

Base64 encode 至少需要两个参数。或许可以试试Base64.encode(image, Base64.DEFAULT)

【讨论】:

  • "Base64 类型中的方法 encode(ByteBuffer, ByteBuffer) 不适用于参数 (byte[], String)" 我尝试转换为 ByteBuffer 但还是有问题...这看起来很简单,但我像个菜鸟一样卡住了。
  • android.util.Base64 上没有方法 encode(ByteBuffer, ByteBuffer)。你确定你使用的是android Base64实现吗?
  • 我下载了一个 Base64 包来制作适用于所有 Android 版本的应用程序。 Android.util.Base64 仅在android 2.2 版本之后可用。
  • 也许你应该更新你原来的问题,让人们知道你正在使用什么 Base64 包。
  • 真丢脸,我看错了文档……答案是 encodeBytes。
猜你喜欢
  • 2017-01-05
  • 2012-03-02
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2015-05-15
  • 1970-01-01
相关资源
最近更新 更多