【问题标题】:Crop an image using rectangular box of selected area?使用选定区域的矩形框裁剪图像?
【发布时间】:2012-01-05 08:53:01
【问题描述】:

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

一些东西

但你会用手指控制角落

任何提示都会非常有用,因为我尝试了很多方法但没有得到结果。

【问题讨论】:

标签: objective-c ios cocoa-touch crop


【解决方案1】:

按钮操作的一些变化

-(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,我只是这个开发的新手
猜你喜欢
  • 1970-01-01
  • 2012-05-16
  • 1970-01-01
  • 2017-06-01
  • 2020-08-27
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2013-04-04
相关资源
最近更新 更多