97干视频,99国产精品懂色,亚洲精品99久久久久中文字幕,伊人五月丁香综合AⅤ,国产精品成人免费999

  您的位置:華清遠(yuǎn)見(jiàn)教育科技集團(tuán) >> 新聞動(dòng)態(tài) >> Android資料 >> Android應(yīng)用開(kāi)發(fā)中圖片的處理  
 
Android應(yīng)用開(kāi)發(fā)中圖片的處理
分享到:

在Android程序中往往需要對(duì)圖片進(jìn)行處理,也就是將圖片解析為字節(jié)數(shù)組,讀取字節(jié)數(shù)組轉(zhuǎn)換成圖片,圖片Bitmap 和Drawable 的轉(zhuǎn)換,下邊寫(xiě)了3個(gè)方法去實(shí)現(xiàn)這寫(xiě)轉(zhuǎn)換

//bitmap 和 drawable的轉(zhuǎn)換

public static Bitmap drawableToBitmap(Drawable drawable){
    int width = drawable.getIntrinsicWidth();
    int height = drawable.getIntrinsicHeight();
    Bitmap bitmap = Bitmap.createBitmap(width, height,
    drawable.getOpacity() != PixelFormat.OPAQUE ? Bitmap.Config.ARGB_8888 : Bitmap.Config.RGB_565);
    Canvas canvas = new Canvas(bitmap);
    drawable.setBounds(0,0,width,height);
    drawable.draw(canvas);
    return bitmap;
    }

//bitmap和byte[]的轉(zhuǎn)換

public byte[] getBitmapByte(Bitmap bitmap){
    ByteArrayOutputStream out = new ByteArrayOutputStream();
    bitmap.compress(Bitmap.CompressFormat.JPEG, 100, out);
    try {
        out.flush();
        out.close();
    } catch (IOException e) {
        e.printStackTrace();
        }
    return out.toByteArray();
    }

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

 更多相關(guān)文章

·在Android中使用WindowManager實(shí)現(xiàn)懸浮窗口
·Android底層字符傳遞給上層應(yīng)用舉例
·Android幀動(dòng)畫(huà)實(shí)例詳解
·Android 控件動(dòng)畫(huà)效果的實(shí)現(xiàn)
·Android中的四種補(bǔ)間動(dòng)畫(huà)