Android 位图裁剪中心

编程入门 行业动态 更新时间:2024-10-28 03:19:48
本文介绍了Android 位图裁剪中心的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我有正方形或矩形的位图.我采取最短的一边做这样的事情:

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 x 144 位图:

Then I scale it to a 144 x 144 Bitmap using this:

Bitmap lastBitmap = null; lastBitmap = Bitmap.createScaledBitmap(finalBitmap, 144, 144, true);

问题是它裁剪了原始位图的左上角,有人有裁剪位图中心的代码吗?

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(source, x, y, width, height)

This can be achieved with: Bitmap.createBitmap(source, x, y, width, height)

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() ); }

更多推荐

Android 位图裁剪中心

本文发布于:2023-08-02 03:42:50,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1274329.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:位图   中心   Android

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!