Java - Bitmap 轉 Base64 String

摘要:Java - Bitmap 轉 Base64 String

      
    public static String getBase64(Bitmap srcBmp01) {
        Bitmap srcBmp02;
        String encoded = "";
        if(srcBmp01 !=null){
            double scale = (double) srcBmp01.getWidth() / 200; 
            int width = (int) ((double) srcBmp01.getWidth() / scale);
            int height = (int) ((double) srcBmp01.getHeight() / scale);
            srcBmp02 = null;
            srcBmp02 = Bitmap.createScaledBitmap(srcBmp01, width, height, false);
            ByteArrayOutputStream baos = new ByteArrayOutputStream();
            srcBmp02.compress(Bitmap.CompressFormat.JPEG, 60, baos);
            byte[] bmByteArary = baos.toByteArray();
            encoded = Base64.encode(bmByteArary);
        }
        
        return encoded;
    }

http://kobjects.sourceforge.net/utils/