使用选定区域的矩形框裁剪图像?

3
我正在寻找一个好的教程或示例代码,展示如何从 iPhone 相机中裁剪图像。希望能够像这个图片一样,但你可以用手指控制四个角落。非常感谢任何帮助,因为我已经尝试了许多方法,但没有得到结果。

同样的问题没有答案 http://stackoverflow.com/questions/2754618/how-to-crop-an-image-using-rectangale-overlay-and-touch-on-iphone - Marios
你尝试了什么?你尝试的方法有什么问题? - rob mayoff
我尝试了这个,可以看看这个链接:http://stackoverflow.com/questions/8238464/croping-an-uiimage-using-frame-to-cut - Marios
这可能会对您有所帮助: https://github.com/jberlana/JBCroppableView - RayofHope
无法运行该文件 RayofHope。 - Marios
1个回答

6
-(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];



    }

@ceacare,它运行良好。 我在粘贴到这里之前已经测试过了。并且每个人都可以在这里提供帮助,但无法根据您的要求完整地完成项目。 - Anil Kothari
好的,好的,我能理解 Anil,我只是对这个开发新手。 - Marios

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接