2
votes

I want to draw UIImage for pattern background and I need need it be float size. For example: I need 7.0699929299999997 width and height.

enter image description here

My code:

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();

But as result my image:

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

Help me out please

1
UIImages resolution is in pixels. You can't have a size that isn't an Integer, even if you provide a CGFloat in the CGSizeMake it'll be converted to an Integer later.TawaNicolas
@TawaNicolas thanks for your reply, it's really bad ;(Artem Z.
Why is it bad? Why would you need to do something like that anyways?TawaNicolas
@TawaNicolas I need a very large background with dots like this. I draw elements above this dots like grid. puu.sh/y8leO/63c688ef47.png And each px is importantArtem Z.
@ArtemZ. Your draw image is create properly like you want but you print "po resizedImage" then you can get size an integer like size {8, 8} because it's not getting floating value. so don't worry about.BuLB JoBs

1 Answers

0
votes

You can draw fractional sizes into image but remember:

  1. pixel is the smallest unit, image is made from pixels, you can not have half pixel, just full pixels.
  2. If you draw fractional size into image, that fraction will cause that from final color drawn you get only percentage based on how much it covers the pixel. So for your value 7.06999, 7 pixels will get full color, last one only 6% of color in the image drawn. In the end it may look blurry on that side.