iOS 将两张image合并成一张image
viewController 中有两个imageView,其中一张有倾斜(imageView的transform属性发生改变),将这两张image合成一张,保持相对的位置不变。
效果大致如下图(第二张的位置有问题)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
viewController 中有两个imageView,其中一张有倾斜(imageView的transform属性发生改变),将这两张image合成一张,保持相对的位置不变。
效果大致如下图(第二张的位置有问题)
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
接受
或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
发布评论
评论(4)
设置第二张imageView.layer.zPosition = CGPointMake(.5, 1);
注意frame会改变 自己setFrame一下 这个时候frame的参考点变成下边中间的点了
有些乱但最终还是解决了实际的问题!
- (UIImage *)saveImageWithUIImage:(UIImage *)srcImage{
//要绘制的实际image
UIImage *mergeImage = srcImage;
}
(float)getScaleRateWithImageSize:(CGSize)imageSize imageViewSize:(CGSize)viewSize contentMode:(UIViewContentMode)mode{
if (mode == UIViewContentModeScaleAspectFill) {
return [self getScaleRateWithImageSize:imageSize imageViewSize:viewSize];
}else{
float viewRate = viewSize.width / viewSize.height;
float imageRate = imageSize.width / imageSize.height;
float rate = 1.0f;
/*
* image按竖直方上的比率压缩
/
if (viewRate > imageRate) {
rate = imageSize.height / viewSize.height;
}
/
* image按水平方上的比率压缩
*/
else{
rate = imageSize.width / viewSize.width;
}
return rate;
}
return 1.0;
}
(float)getScaleRateWithImageSize:(CGSize)imageSize imageViewSize:(CGSize)viewSize{
float viewRate = viewSize.width / viewSize.height;
float imageRate = imageSize.width / imageSize.height;
float rate = 1.0f;
/*
/
if (viewRate > imageRate) {
rate = imageSize.width / viewSize.width;
}
/
/
else{
rate = imageSize.height / viewSize.height;
}
return rate;
}
/
*新坐标系下甲片左上角的坐标
*/
float originAngle = [self programWithWidth:layerSize.width height:layerSize.height];
float halfDiagonalLength = [self halfDiagonalLengthWithWidth:layerSize.width height:layerSize.height] * rate;
float x = halfDiagonalLength * cosf(originAngle - angle);
float y = halfDiagonalLength * sinf(originAngle - angle);
return (CGPoint){x, -y};
}
/*
*甲片中心在绘图上下文中的坐标 UIViewContentModeScaleAspectFit / UIViewContentModeScaleAspectFill
*/
(CGPoint)getTranslatePositionWithImageSize:(CGSize)imageSize imageViewSize:(CGSize)viewSize originPosition:(CGPoint)position contentModle:(UIViewContentMode)mode{
if (mode == UIViewContentModeScaleAspectFill) {
return [self getTranslatePositionWithImageSize:imageSize imageViewSize:viewSize originPosition:position];
}else{// --- UIViewContentModeScaleAspectFit ---
float viewRate = viewSize.width / viewSize.height;
float imageRate = imageSize.width / imageSize.height;
}
return CGPointZero;
}
(CGPoint)getTranslatePositionWithImageSize:(CGSize)imageSize imageViewSize:(CGSize)viewSize originPosition:(CGPoint)position{
float viewRate = viewSize.width / viewSize.height;
float imageRate = imageSize.width / imageSize.height;
float position_x = 0.0f;
float position_y = 0.0f;
/*
/
if (viewRate > imageRate) {
float actualViewHeight = imageSize.height * (viewSize.width / imageSize.width);
float deltaHeight = (actualViewHeight - viewSize.height) * 0.5;
position_x = position.x;
position_y = position.y + deltaHeight;
position_x *= imageSize.width / viewSize.width;
position_y *= imageSize.width / viewSize.width;
}
/
*/
else{
float actualViewWidth = imageSize.width * (viewSize.height / imageSize.height);
//此时actualViewWidth 应大于 viewSize.width
float deltaWidth = (actualViewWidth - viewSize.width) * 0.5;
position_x = position.x + deltaWidth;
position_y = position.y;
position_x *= imageSize.height / viewSize.height;
position_y *= imageSize.height / viewSize.height;
}
return (CGPoint){position_x,position_y};
}
(CGSize)getTranslateSizeWithImageSize:(CGSize)imageSize imageViewSize:(CGSize)viewSize originSize:(CGSize)size contentMode:(UIViewContentMode)mode{
if (mode == UIViewContentModeScaleAspectFill) {
return [self getTranslateSizeWithImageSize:imageSize imageViewSize:viewSize originSize:size];
}else{
float viewRate = viewSize.width / viewSize.height;
float imageRate = imageSize.width / imageSize.height;
}
}
/*
*甲片在绘图上下文中的尺寸
*/
- (CGSize)getTranslateSizeWithImageSize:(CGSize)imageSize imageViewSize:(CGSize)viewSize originSize:(CGSize)size{
float viewRate = viewSize.width / viewSize.height;
float imageRate = imageSize.width / imageSize.height;
}
//对角线与x轴的夹角
- (float)programWithWidth:(float)w height:(float)h{
float p = [self halfDiagonalLengthWithWidth:w height:h];
float dis = 0 - w * 0.5;
float dis_p = dis / p;
return acosf(dis_p);
}
//对角线的一半
- (float)halfDiagonalLengthWithWidth:(float)w height:(float)h{
return sqrtf(w * w / 4.0 + h * h / 4.0);
}
楼主你好,我想问一下那个self.baseView是什么类啊(自定义的?),stickerView.endScaleSize,stickerView.endDeltaAngle的属性哪里来的啊,我下载ZDStickerView里面没有啊,谢谢啊!
两张image旋转合成 有demo嘛 大神 发我一份吧 谢谢 啦