2011-03-03 19 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