2011-03-03 57 views
0

Base64.encode不想采用参数“图像”,我不知道如何弄清楚。我以前从未使用过Base64。使用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/

+0

可能重复的[如何将图像转换为Base64字符串?](http://stackoverflow.com/questions/4830711/how-to-convert-a-image-into-base64-string) – 2012-07-09 10:20:22

回答

2

Base64 encode的外部包需要至少两个参数。也许尝试Base64.encode(image, Base64.DEFAULT)

+0

“Base64类型中的方法编码(ByteBuffer,ByteBuffer)不适用于参数(byte [],String)”我试图转换为ByteBuffer,但仍然存在问题......它看起来很简单,但我很卡住像一个noob。 – user420574 2011-03-03 23:54:22

+0

android.util.Base64上没有方法编码(ByteBuffer,ByteBuffer)。你确定你使用的是Android Base64实现吗? – Drew 2011-03-04 00:01:15

+0

我下载了一个Base64软件包,为Android的所有版本创建应用程序。 Android.util.Base64仅在2.2版本的android之后可用。 – user420574 2011-03-04 00:06:15