本文介绍了位图的安卓作物中心的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有位图这是正方形或长方形。我走最短边,做这样的事情:
I have bitmaps which are squares or rectangles. I take the shortest side and do something like this:
int value = 0;
if (bitmap.getHeight() <= bitmap.getWidth()) {
value = bitmap.getHeight();
} else {
value = bitmap.getWidth();
}
Bitmap finalBitmap = null;
finalBitmap = Bitmap.createBitmap(bitmap, 0, 0, value, value);
然后,我用这个缩放到144×144位图:
Then I scale it to a 144 x 144 Bitmap using this:
Bitmap lastBitmap = null;
lastBitmap = Bitmap.createScaledBitmap(finalBitmap, 144, 144, true);
问题是,它作物原始位图的左上角,任何人都具有code裁剪位图的中心?
Problem is that it crops the top left corner of the original bitmap, Anyone has the code to crop the center of the bitmap?
推荐答案
这可以实现用: Bitmap.createBitmap(源,X,Y,宽,高)
if (srcBmp.getWidth() >= srcBmp.getHeight()){
dstBmp = Bitmap.createBitmap(
srcBmp,
srcBmp.getWidth()/2 - srcBmp.getHeight()/2,
0,
srcBmp.getHeight(),
srcBmp.getHeight()
);
}else{
dstBmp = Bitmap.createBitmap(
srcBmp,
0,
srcBmp.getHeight()/2 - srcBmp.getWidth()/2,
srcBmp.getWidth(),
srcBmp.getWidth()
);
}
这篇关于位图的安卓作物中心的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!