我有裁剪的图像&我在ui上显示它。当我向其添加帧时,图像大小会改变。例如,如果图像尺寸是200 * 50&当我将另一个图像作为一个帧添加时,新图像变为相等的高度&帧图像的宽度。我怎样才能得到解决方案?
这是我的代码:
-(void)addFrames:(int)count
{
float scale ;
UIImage *borderImage;
if ([[UIScreen mainScreen] respondsToSelector:@selector(scale)] == YES && [[UIScreen mainScreen] scale] == 2.00)
{
// RETINA DISPLAY
scale = 2.0;
}
else
{
// non - retina display
scale = 1.0;
}
if(count==1)
{
borderImage = [UIImage imageNamed:@""];
}
else if(count==2)
{
borderImage = [UIImage imageNamed:@"borderImage1.png"];
}
else if(count==3)
{
borderImage = [UIImage imageNamed:@"borderImage2.png"];
}
else if(count==4)
{
borderImage =[UIImage imageNamed:@"borderImage3.png"];
}
else if(count==5)
{
borderImage = [UIImage imageNamed:@"borderImage4.png"];
}
UIImage *bottomImage = self.mainImage; //background image
UIImage *image = borderImage; //foreground image
CGSize newSize = CGSizeMake(self.img_background.frame.size.width, self.img_background.frame.size.height);
UIGraphicsBeginImageContext( newSize );
// Use existing opacity as is
[bottomImage drawInRect:CGRectMake(0,0,newSize.width,newSize.height)];
// Apply supplied opacity if applicable
[image drawInRect:CGRectMake(0,0,newSize.width,newSize.height) blendMode:kCGBlendModeNormal alpha:0.8];
UIImage *newImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();//
self.img_background.image=newImage;
framedImage=newImage;
}
我希望新的框架图像与添加框架前的尺寸相同?
答案 0 :(得分:0)
你是那个说:
[bottomImage drawInRect:CGRectMake(0,0,newSize.width,newSize.height)];
拉伸图片以填充此矩形,因此newSize.width
为newSize.height
。如果那不是你想要的,那么就不要这样做。它绘制的地方是你告诉它以你告诉它绘制的尺寸绘制的。