1. 程式人生 > >Bitmap對圖像的處理

Bitmap對圖像的處理

apply getwidth 查看源 cto 保存圖像 nbsp andro 構造 mod

---恢復內容開始---

Bitmap:是android中重要的圖像處理工具類,通過bitmap可以對圖像進行剪切、旋轉、縮放等操作,同時還可以指定格式和壓縮質量保存圖像文件。

1.對象的構造:查看源碼可知,Bitmap內部有一個私有構造器,即不對外提供new實例,從構造器註釋以及createBitmap看出,Bitmap僅有nativeCreate實例通過jni的調用完成對象的使用.另外可以通過BitmapFactory jni的方式進行實例化對象的創建.

2.縮放圖片:Matrix與Bitmap的使用
主要思路:創建一個Martix對象,用Bitmap.createBitmap產生一個Bitmap對象,並替換原ImageView的bitmap。


scaleFactor = 0.9
int width = Math.round(textureView.getWidth() * scaleFactor);
int height = Math.round(textureView.getHeight() * scaleFactor);
Bitmap bitmap = textureView.getBitmap(width, height);//相對於原來縮小了0.1
// TODO: Figure out why only have to apply the transform in landscape mode
if (width > height) {
bitmap =
Bitmap.createBitmap(
bitmap,
0,
0,
bitmap.getWidth(),
bitmap.getHeight(),
textureView.getTransform(null),
true);
}

blurredImageView.setImageBitmap(bitmap);

---恢復內容結束---

Bitmap對圖像的處理