使用所选区域的矩形框裁剪图像? [英] Crop an image using rectangular box of selected area?

查看:185
本文介绍了使用所选区域的矩形框裁剪图像?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在寻找一个很好的教程或示例代码,它将显示如何裁剪从iphone相机拍摄的图像

I am looking for a good tutorial or sample code, that would show how to crop an image taking from iphone camera

但你会用你的手指控制角落

but you would control the corners with your fingers

任何提示将是非常appericated,因为我尝试了很多方式,但没有得到一个结果。

any tip would be greatly appericated, as i tried in many way but didn't get a result.

推荐答案

按钮操作中的一些更改

-(IBAction) cropImage:(id) sender{


        // Create rectangle that represents a cropped image  
        // from the middle of the existing image

    float xCo,yCo;

    float width=bottomCornerPoint.x-topCornerPoint.x;

    float height=bottomCornerPoint.y-topCornerPoint.y;


    if(width<0)

    width=-width;


    if(height<0)

        height=-height;


    if(topCornerPoint.x <bottomCornerPoint.x)

    {

    xCo=topCornerPoint.x;

    }

    else 
    {
            xCo=bottomCornerPoint.x;
        }


        if(topCornerPoint.y <bottomCornerPoint.y)

    {

            yCo=topCornerPoint.y;

        }


    else {

            yCo=bottomCornerPoint.y;

        }


        CGRect rect = CGRectMake(xCo,yCo,width,height);

        // Create bitmap image from original image data,
        // using rectangle to specify desired crop area

        UIImage *image = [UIImage imageNamed:@"abc.png"];


        CGImageRef imageRef = CGImageCreateWithImageInRect([image CGImage], rect);

        UIImage *img = [UIImage imageWithCGImage:imageRef]; 

        CGImageRelease(imageRef);


        // Create and show the new image from bitmap data

        imageView = [[UIImageView alloc] initWithImage:img];

        [imageView setFrame:CGRectMake(110, 600, width, height)];

        imageView.image=img;

        [[self view] addSubview:imageView];

        [imageView release];



    }

这篇关于使用所选区域的矩形框裁剪图像?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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