Bitmap,String,Byte相互変換


1.bitmap回転string
<span style="font-size:18px;"><strong>/**  
	     *  string  
	     *   
	     * @param bitmap  
	     * @return  
	     */  
	    public static String convertIconToString(Bitmap bitmap)  
	    {  
	        ByteArrayOutputStream baos = new ByteArrayOutputStream();// outputstream  
	        bitmap.compress(CompressFormat.PNG, 100, baos);  
	        byte[] appicon = baos.toByteArray();//  byte   
	        return Base64.encode(appicon);
	        
    }</strong></span>

2.bitmap回転byte
/**
	 * 
	 * @param bitmap byte
	 * @return
	 */
	 public  static byte[] Bitmap2Bytes(Bitmap bm) {
         ByteArrayOutputStream baos = new ByteArrayOutputStream();
         bm.compress(Bitmap.CompressFormat.PNG, 100, baos);
         return baos.toByteArray();
    }

3.string
転成
bitmap
/**
 * string bitmap
 * 
 * @param st
 */
public static Bitmap convertStringToIcon(String st) {
	// OutputStream out;
	Bitmap bitmap = null;
	try {
		// out = new FileOutputStream("/sdcard/aa.jpg");
		byte[] bitmapArray;
		bitmapArray = Base64.decode(st);
		bitmap = BitmapFactory.decodeByteArray(bitmapArray, 0,
				bitmapArray.length);
		// bitmap.compress(Bitmap.CompressFormat.PNG, 100, out);
		return bitmap;
	} catch (Exception e) {
		return null;
	}
}

4.
byte
ターン
bitmap
/**
 * 
 * @param byte bitmap
 * @return
 */

public Bitmap Bytes2Bimap(byte[] b) {
	if (b.length != 0) {
		return BitmapFactory.decodeByteArray(b, 0, b.length);
	} else {
		return null;
	}
}