Android中Bitmap常見操作(一.理論)

來源:互聯網
上載者:User

//利用BitmapFactory產生Bitmap
//注意該方法只是產生了Bitmap,所以傳回值都是一個Bitmap
//並沒有涉及到對於Bitmap對象的操作,比如將其旋轉,壓縮
//以下為常用的四種方式:
//1 依據檔案路徑產生Bitmap
//該方法也是擷取縮圖的方法之一
//擷取縮圖的另外一種方法是直接調用類方法
//重點是傳入參數opts
//ThumbnailUtils.extractThumbnail();
//可以這麼理解:既然是得到縮率圖,其實也就是產生一個
//新的Bitmap,所以當然該調用BitmapFactory.decodeFile()方法.
Bitmap bitmap1=BitmapFactory.decodeFile(pathName, opts);
//2 從本地資源中產生Bitmap
Bitmap bitmap2=BitmapFactory.decodeResource(res, id);
//3 從輸入資料流中產生Bitmap
Bitmap bitmap3=BitmapFactory.decodeStream(inputStream);
//4 從位元組數組中產生Bitmap
Bitmap bitmap4=BitmapFactory.decodeByteArray(data, offset, length);

//產生Bitmap後對於該Bitmap的操作小結如下:
//1 壓縮Bitmap的寬和高,將Bitmap旋轉和傾斜
//  等操作調用的都是類方法Bitmap.createBitmap()方法.其中matrix參數很重要
Bitmap bitmap5=Bitmap.createBitmap(rawBitmap, x, y, width, height, matrix, filter);
//2 儲存Bitmap到檔案.調用的是Bitmap的對象方法
bitmap5.compress(format, quality, os);

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.