如何使用四个(x,y)坐标裁剪图像 [英] How to crop the image using four (x,y) coordinates

查看:319
本文介绍了如何使用四个(x,y)坐标裁剪图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的应用程序中,我将使用四个(x,y)坐标来裁剪图像,并且还需要在另一个活动屏幕中显示裁剪后的图像.例如,在下图中,我要裁剪白色图层本身.因此任何人都可以提供解决方案以在我的项目中完成这项技术.

In my application ,I am going to crop the image using four (x,y) coordinates and also I need to show the cropped image in another activity screen. For example, In the below image, i want to crop the white layer itself. so any one provide the solution to accomplish this technique in my project.

推荐答案

使用Bitmap类的实例,可以使用Bitmap.creatBitmap();.方法传递原始图像x y(对于左上角),然后传递宽度和高度.

Using an instance of the Bitmap class, you can use the Bitmap.creatBitmap(); method passing the original image x y (for the top left corner) and then width and height.

请参阅此处的文档.

在您的原始示例中为:

Bitmap newBitmap=Bitmap.createBitmap(oldBitmap,10,20,70,80);


编辑

Bitmap类还允许您访问像素int表示颜色的数组.如果您知道要根据每个点的坐标进行裁剪的形状.您可以遍历数组,并将形状之外的alpha设置为全屏.


Edit

The Bitmap class also allows you to access an array of pixel int's representing color. if you know the shape you want to crop in terms of co-ordinates of each point. you could iterate through the array and set alpha to full on the ones that are outside your shape.

这篇关于如何使用四个(x,y)坐标裁剪图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆