Android 中的裁剪图片
我已经尝试这个有一段时间了,我想从位图
创建壁纸。假设所需的壁纸尺寸为 320x480,源图像尺寸为 2048x2048。
我不确定“裁剪适合”是否是正确的术语,但我想要实现的是获得与所需壁纸尺寸(320x480)具有相同比例的图片的大部分。
因此,在这种情况下,我想从源 Bitmap 中获取 2048x1365 或(准确地说是 1365.333...),并将其缩小到 320x480。
我尝试过的技术是:
1)首先将位图裁剪为2048x1365
bm = Bitmap.createBitmap(bm, xOffset, yOffset, 2048, 1365);
2)将其缩小到320x480,
bm = Bitmap.createScaledBitmap(bm, 320, 480, false);
这会产生OutOfMemory错误。
有什么办法可以实现这一点吗?
问候,
德祖尔
I've been trying this for some time, I would like to create a wallpaper from a Bitmap
. Let's say the desired wallpaper size is 320x480, and the source image size is 2048x2048.
I'm not sure whether crop-to-fit is the right term, but what I would like to achieve is to get most part of the picture that has the equal ratio as the desired wallpaper size (320x480).
So in this case, I would like to get 2048x1365 or (1365.333... to be exact) from the source Bitmap
, and scale it down to 320x480.
The technique that I have tried is:
1) Crop the Bitmap into 2048x1365 first
bm = Bitmap.createBitmap(bm, xOffset, yOffset, 2048, 1365);
2) Scale it down to 320x480
bm = Bitmap.createScaledBitmap(bm, 320, 480, false);
which produced OutOfMemory error.
Is there any way to achieve this?
Regards,
dezull
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
感谢开源,我从Android Gallery源代码中找到了答案 这里在第230行:-D
Thanks to open source, I found the answer from Android Gallery source code here at line 230 :-D
我知道这是一个非常晚的回复,但也许是这样的:
I know this is an incredibly late reply, but something like this maybe:
这是一个可以帮助您大部分实现目标的答案:
如何在 Android 中裁剪图像?
here is an answer that gets you most of the way there:
How to crop an image in android?