OGeek|极客世界-中国程序员成长平台

标题: ios - 用 float 大小绘制 UIImage [打印本页]

作者: 菜鸟教程小白    时间: 2022-12-11 19:07
标题: ios - 用 float 大小绘制 UIImage

我想为图案背景绘制 UIImage,我需要它是 float 大小。例如: 我需要 7.0699929299999997 的宽度和高度。

enter image description here

我的代码:

UIImage *repeatedImage = [UIImage imageNamed"LayoutRepeatedImage"];
    CGSize destinationSize = CGSizeMake(7.0699929299999997, 7.0699929299999997);
    UIGraphicsBeginImageContext(destinationSize);
    [repeatedImage drawInRect:CGRectMake(0, 0, destinationSize.width, destinationSize.height)];
    UIImage *resizedImage = UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();

但结果是我的图像:

po resizedImage
<UIImage: 0x6000014b21e0> size {8, 8} orientation 0 scale 1.000000

请帮帮我



Best Answer-推荐答案


您可以在图像中绘制小数,但请记住:

  1. 像素是最小单位,图像是由像素组成的,不能有半像素,只有全像素。
  2. 如果您在图像中绘制分数大小,则该分数将导致从最终绘制的颜色中您仅获得基于它覆盖像素的百分比的百分比。因此,对于您的值 7.06999,7 个像素将获得全彩,最后一个像素只有绘制图像中颜色的 6%。最后,它可能看起来很模糊。

关于ios - 用 float 大小绘制 UIImage,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46971862/






欢迎光临 OGeek|极客世界-中国程序员成长平台 (http://ogeek.cn/) Powered by Discuz! X3.4