日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

android imageview 获取bitmap缩放大小,android – Imageview缩放方法“centercrop”作为代码...

發布時間:2023/12/9 编程问答 26 豆豆
生活随笔 收集整理的這篇文章主要介紹了 android imageview 获取bitmap缩放大小,android – Imageview缩放方法“centercrop”作为代码... 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

我試圖找出當它縮放圖像時,

android正在做什么,特別是“centercrop”類型.所以要找到答案,我搜索了

ImageView源代碼,并找到它為

here.

所以我試過的是這段代碼:

public Bitmap buildBluredBoxBackground () {

int [] screenSize = Utilities.getScreenSize(mainActivityContext); //screensize[0] = x and [1] is y

Matrix mDrawMatrix = new Matrix();

Bitmap bitmap = ((BitmapDrawable)fullscreenViewHolder.imageViewArt.getDrawable()).getBitmap();

float scale;

float dx = 0, dy = 0;

if (bitmap.getWidth() * screenSize[1] > screenSize[0] * bitmap.getHeight()) {

scale = (float) screenSize[1] / (float) bitmap.getHeight();

dx = (screenSize[0] - bitmap.getWidth() * scale) * 0.5f;

} else {

scale = (float) screenSize[0] / (float) bitmap.getWidth();

dy = (screenSize[1] - bitmap.getHeight() * scale) * 0.5f;

}

mDrawMatrix.setScale(scale, scale);

mDrawMatrix.postTranslate(Math.round(dx), Math.round(dy));

result = Bitmap.createBitmap(bitmap,0,0,bitmap.getWidth(),bitmap.getHeight(),mDrawMatrix,true);

... //Some processing work

return result;

}

但是它并沒有給我相同的結果.我究竟做錯了什么 ?

舉個例子:

原始圖片

原始ImageView中心裁剪

試用代碼

編輯:

ImageView的XML

android:layout_width="match_parent"

android:layout_height="match_parent"

android:layout_alignParentLeft="true"

android:layout_alignParentRight="true"

android:layout_alignParentTop="true">

android:layout_width="match_parent"

android:layout_height="match_parent"

android:id="@+id/imageViewFullscreenArt"/>

android:layout_width="match_parent"

android:layout_height="match_parent"

android:id="@+id/imageViewFullscreenArtBluredBox"/>

所以我的ImageView是全屏的.這就是為什么Im使用screenSize來處理它.

代碼如何應用它

Bitmap bluredBoxBackground = buildBluredBoxBackground();

imageViewBluredBox.setImageDrawable(new BitmapDrawable(getResources(),bluredBoxBackground));

詳細說明:

我只是試圖獲得與ImageView.setScaleType(ScaleType.CENTER_CROP)相同的效果.所以我的代碼應該像原來的setScaleType方法一樣.為什么我需要它作為代碼?因為在我的情況下,我無法獲取我的ImageView的繪圖,但我必須處理&以某種方式編輯它

總結

以上是生活随笔為你收集整理的android imageview 获取bitmap缩放大小,android – Imageview缩放方法“centercrop”作为代码...的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。