我的笔尖中有两个UIImageviews,其中一个是根据UISlider的值调整大小 代码是: -
-(IBAction)sliderChanged:(UISlider*)slider{
CGFloat scaleFactor=slider.value;
markerImage.transform = CGAffineTransformMakeScale(scaleFactor,scaleFactor);
}
正确调整大小,但是当我通过这些代码将这些图像合并在一起时
UIImage *backImage=backgroundImage.image;
UIImage *markImage=markerImage.image;
UIGraphicsBeginImageContext(backImage.size);
[backImage drawAtPoint:CGPointMake(0,0)];
[markImage drawAtPoint:CGPointMake(0,0)];
UIImage *newImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
我合并了原始大小的图片, 也就是说,标记图像在结果图像中出现在相同的维度中 如何以正确的比例绘制标记图像 谢谢
答案 0 :(得分:1)
而不是drawAtPoint:
,请使用drawInRect:(CGRect)rect
。此外,需要使用滑块值。
假设sliderValue介于0和1之间,
CGRect rect = CGRectMake(0,0, markerImage.size.width*sliderValue, markerImage.size.height*sliderValue);
[markImage drawInRect:rect];
修改强>
CGFloat width = markerImage.size.width*sliderValue;
CGFloat height = markerImage.size.height*sliderValue;
CGRect rect = CGRectMake((markerImage.size.width-width)/2,(markerImage.size.height-height)/2, width, height);
[markImage drawInRect:rect];