【问题标题】:make UIImage AspectFit?制作 UIImage AspectFit?
【发布时间】:2019-03-16 13:14:56
【问题描述】:

我正在生成带有图像的 PDF,问题是

 [imageview.image drawInRect:CGRectMake(0, 0, 100, 100)];

在生成的 PDF 中,我的图像被拉伸到了我们在 CGRectMake 中定义的大小,那么我的图像如何设置为 Aspect Fit 而不是 UIImageView?

我的尺寸在 PDF 中固定为 100*100,但图像需要调整纵横比

有什么帮助吗?

【问题讨论】:

  • 您能添加如何将其转换为 PDF 的代码吗?
  • @ankit UIGraphicsBeginPDFPageWithInfo(CGRectMake(0, 0, 612, 880), nil);通过这个

标签: ios objective-c uiimage pdf-generation


【解决方案1】:

您可以尝试设置 imageview 的 contentmode ,其中 view(image) 的内容会在视图绑定更改时更改

例如: imageView.contentMode = UIViewContentModeScaleAspectFit;

参考: 苹果文档中的内容模式

【讨论】:

【解决方案2】:

这是你需要做的。它将保持您要在块中添加的任何内容的纵横比。

计算图像的大小,然后添加到CGRect中。

CGRect AVMakeRectWithAspectRatioInsideRect(CGSize aspectRatio, CGRect boundingRect);

更多信息请查看documentation

【讨论】:

  • 试过了,但是当使用 100*100 的图像进行拉伸时,因为不可能 [imageview drawInRect only [imageview.image drawInRect possible
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2013-03-21
  • 1970-01-01
  • 2012-02-14
  • 2013-01-10
  • 2011-11-15
  • 2011-04-29
相关资源
最近更新 更多