简体   繁体   中英

Crop an image using rectangular box of selected area?

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

something in lines of

在此处输入图片说明

but you would control the corners with your fingers

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

some changes in the button action

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



    }

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM