私はすでに私の側からたくさんの努力をしています。ついに私は助けが必要です。おかげスクロールビュー内のImageViewでズームした画像をクロップする
目標: 1)私は内部scrollViewでズーム画像をトリミング方法ScrollView
2)の内側にImageViewのに合わせてどのように。
私はスクロールビュー内にimageViewを持っています。スクロールビューの境界内に表示されているズーム後にクロップ画像が必要です。私はすでにイメージを切り取ったが、私が望むものと全く同じではなかった。
ここでは、backgroundColor BlackをscrollViewに設定しました。私はそれの中にimageViewを配置すると、それは合いません。
は
とクロップ画像の後
はあるスクロールビュー内のズーム画像がされた後、私のコードはここにある:
- (void)viewDidLoad
{
[super viewDidLoad];
CGRect frame1 = CGRectMake(50,50,200,200);
CGRect frame2 = CGRectMake(50,50,200,200);
imageView1=[[UIImageView alloc]initWithFrame:frame1];
imageView1.image= [UIImage imageNamed:@"back.jpeg"];
imageView1.backgroundColor=[UIColor brownColor];
imageView1.contentMode = UIViewContentModeScaleAspectFit;
scroll=[[UIScrollView alloc]initWithFrame:frame2];
scroll.backgroundColor=[UIColor blackColor];
[scroll addSubview:imageView1];
scroll.delegate=self;
[self.view addSubview:scroll];
[self setContentSizeForScrollView];
self.imageView1.userInteractionEnabled = YES;
}
設定のcrollビューのcontentSize
-(void)setContentSizeForScrollView
{
// scroll.contentSize = CGSizeMake(imageView1.frame.size.width,imageView1.frame.size.height);
scroll.contentSize = CGSizeMake(200, 200);
scroll.minimumZoomScale = .50;
scroll.maximumZoomScale = 1.5;
}
と私の作物のロジックが
-(IBAction)cropButtonClicked
{
//Calculate the required area from the scrollview
CGRect rect = CGRectMake(50, 50, 200,200);
UIImage *image = [self imageByCropping:imageView1.image toRect:rect];
imageView1.image=image;
imageView1.contentMode = UIViewContentModeScaleAspectFit;
}
そして、この方法で作物の画像です:自分の質問の
- (UIImage*)imageByCropping:(UIImage *)myImage toRect:(CGRect)cropToArea{
CGImageRef cropImageRef = CGImageCreateWithImageInRect(myImage.CGImage, cropToArea);
UIImage* cropped = [UIImage imageWithCGImage:cropImageRef];
CGImageRelease(cropImageRef);
return cropped;
}
私はこれを揺さぶっています。上記のコードで見つかった唯一の問題は、「//イメージオフセット座標のクロップフレーム」という見出しの下のコードにあります。私はself.cropview.boundsを使ったのに対し、self.cropview.frameを使っています。 –
クール.....ありがとう。 – Gokul