如何在缩放图像上变换标签的原点坐标?

时间:2014-12-28 21:06:36

标签: ios objective-c scale transformation

我有一个应用程序可以生成屏幕上显示内容的图像。我在屏幕上有一个标签,原点为:0,148,尺寸为89.5x37.5。屏幕分辨率为375x667,生成的图像为675x1200。从376x667缩放到675x1200时,如何正确确定标签的来源和尺寸?

比例系数为1.8。

origin =(0,148) 维度= 89.5乘37.5

转换起源= ???

转换尺寸= 89.5 * 1.8乘37.5 * 1.8

1 个答案:

答案 0 :(得分:0)

CGFloat scaleFactor = 1.8;
CGRect lblRct = myLabel.frame;
lblRct.origin.x *= scaleFactor; //unnecessary really, as it is 0
lblRct.origin.y *= scaleFactor;
lblRct.size.height *= scaleFactor;
lblRct.size.width *= scaleFactor;

UIFont *font = myLabel.font;
CGFloat ptSz = font.pointSize;
ptSz *= scaleFactor;

UILabel *newLabel = [[UILabel alloc]initWithFrame: lblRct];
newLabel.font = [font fontWithPointSize: ptSz ];
newLabel.text = myLabel.text;


/// render your image into a CGContextRef

[newLabel.layer renderInContext: cxt];