计算旋转后图片大小
方法一:计算图片每个角旋转后坐标,然后计算外围矩形
假设图片位置(x,y,width,height)
则图片四个角坐标分别是
point1 = (x,y);
point2 = (x+width, y);
point3 = (x+width, y+height);
point4 =(x,y+height);
旋转中心点为(centerX,centerY)
旋转变换矩阵为trans(iOS中CGAffineTransform,安卓中的Matrix)
旋转后每个角的坐标分别是
point1 = (CGPointApplyAffineTransform(x-centerX, trans) + centerX,CGPointApplyAffineTransform(y-centerY, trans) + centerY);
point2 = (CGPointApplyAffineTransform(x+width-centerX, trans) + centerX,CGPointApplyAffineTransform(y-centerY, trans) + centerY);
point3 = (CGPointApplyAffineTransform(x+width-centerX, trans) + centerX,CGPointApplyAffineTransform(y+height-centerY, trans) + centerY);
point4 = (CGPointApplyAffineTransform(x-centerX, trans) + centerX,CGPointApplyAffineTransform(y+height-centerY, trans) + centerY);
遍历旋转后的点找出x、y方向的最大、最小值
将这些最大、最小值组合成为新的矩形,这个矩形就是我们要找的旋转后的图片大小
方法二:
UIView * rotatedImageBox = [[UIView alloc]initWithFrame:imageFrame];//imageFrame是旋转前的图片位置
CGFloat rotateAnchorX = (-imageFrame.origin.x + rotateCenter.x)/imageFrame.size.width;
CGFloat rotateAnchorY = (-imageFrame.origin.y + rotateCenter.y)/imageFrame.size.height;
rotatedImageBox.layer.anchorPoint = CGPointMake(rotateAnchorX, rotateAnchorY);
rotatedImageBox.frame = imageFrame;
rotatedImageBox.transform = trans;
CGRect timeFrameInPDF = rotatedImageBox.frame;