gpt4 book ai didi

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

转载 作者:可可西里 更新时间:2023-11-01 17:10:55 25 4
gpt4 key购买 nike

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

某行的东西

enter image description here

但你会用手指控制角落

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

最佳答案

按钮 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];



}

关于objective-c - 使用选定区域的矩形框裁剪图像?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8252779/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com