Note that there are some explanatory texts on larger screens.

plurals
  1. POhow to repeat only part of an image?
    primarykey
    data
    text
    <p>how to repeat only part of an image,</p> <p>there are two images.</p> <p><em>i.stack.imgur.com/KC0Pm.png</em></p> <p>the source pic is something like the above and i want to change it to:</p> <p><em>i.stack.imgur.com/t8CwQ.png</em></p> <p>this means i just want to repeat only part of the image? not stretch the source pic, is it possible to do that? </p> <p>thanks <strong>Update:</strong></p> <p>CODE HERE : <a href="http://www.box.net/shared/cmtz0e48a5urtajxu4yn" rel="nofollow">http://www.box.net/shared/cmtz0e48a5urtajxu4yn</a> still have problem!!</p> <p><strong>Update:</strong> i crop my image file and just repeat the part,but i still have some problem.</p> <pre><code>- (UIImage *)imageWithImage:(NSString *)iconName covertToSize:(CGSize)size { CGRect topLeft,topRight,bottomLeft,bottomRight,top,bottom,left,right; if ([iconName isEqualToString:@"border_baikuang"]) { topLeft = CGRectMake(0, 0, 18, 18); topRight = CGRectMake(108-18, 0, 18, 18); bottomLeft = CGRectMake(0, 104-18, 18, 18); bottomRight = CGRectMake(108-18, 104-18, 18, 18); top = CGRectMake(18, 0, 1, 18); bottom = CGRectMake(18, 104-18, 1, 18); left = CGRectMake(0, 18, 18, 1); right = CGRectMake(108-18, 18, 18, 1); } else if ([iconName isEqualToString:@"border_fuguxiangkuang"]) { topLeft = CGRectMake(0, 0, 28, 28); topRight = CGRectMake(108-28, 0, 28, 28); bottomLeft = CGRectMake(0, 104-28, 28, 28); bottomRight = CGRectMake(108-28, 104-28, 28, 28); top = CGRectMake(28, 0, 28, 24); bottom = CGRectMake(28, 104-28, 28, 24); left = CGRectMake(0, 28, 24, 28); right = CGRectMake(108-24, 28, 24, 28); } float width = size.width; float height = size.height; UIGraphicsBeginImageContext(size); // UIImage *topLeftPattern = [self fetchImgWithSrc:iconName rect:topLeft]; [topLeftPattern drawInRect:CGRectMake(0, 0, topLeftPattern.size.width, topLeftPattern.size.height)]; UIImage *topRightPattern = [self fetchImgWithSrc:iconName rect:topRight]; [topRightPattern drawInRect:CGRectMake(width-topRightPattern.size.width, 0, topRightPattern.size.width, topRightPattern.size.height)]; UIImage *bottomLeftPattern = [self fetchImgWithSrc:iconName rect:bottomLeft]; [bottomLeftPattern drawInRect:CGRectMake(0, height-bottomLeftPattern.size.height, bottomLeftPattern.size.width, bottomLeftPattern.size.height)]; UIImage *bottomRightPattern = [self fetchImgWithSrc:iconName rect:bottomRight]; [bottomRightPattern drawInRect:CGRectMake(width-bottomRightPattern.size.width, height-bottomRightPattern.size.height, bottomRightPattern.size.width, bottomRightPattern.size.height)]; UIImage *topPattern = [self fetchImgWithSrc:iconName rect:top]; [topPattern drawAsPatternInRect:CGRectMake(topLeftPattern.size.width, 0, width-topRightPattern.size.width-topLeftPattern.size.width, topPattern.size.height)]; UIImage *bottomPattern = [self fetchImgWithSrc:iconName rect:bottom]; [bottomPattern drawAsPatternInRect:CGRectMake(bottomLeftPattern.size.width, height-bottomLeftPattern.size.height, width-bottomRightPattern.size.width-bottomLeftPattern.size.width, bottomPattern.size.height)]; UIImage *leftPattern = [self fetchImgWithSrc:iconName rect:left]; [leftPattern drawAsPatternInRect:CGRectMake(0, topLeftPattern.size.height, leftPattern.size.width, height-bottomLeftPattern.size.height-topLeftPattern.size.height)]; UIImage *rightPattern = [self fetchImgWithSrc:iconName rect:right]; [rightPattern drawAsPatternInRect:CGRectMake(width-topRightPattern.size.width, topRightPattern.size.height, rightPattern.size.width, height-bottomRightPattern.size.height - topRightPattern.size.height)]; UIImage *destImage = UIGraphicsGetImageFromCurrentImageContext(); UIGraphicsEndImageContext(); return destImage; </code></pre> <p>}</p> <pre><code>- (UIImage*)fetchImgWithSrc:(NSString *)iconName rect:(CGRect)clipRect { NSString *completeName = [iconName stringByAppendingString:@".png"]; UIImage *src = [UIImage imageFromFileName:completeName]; NSLog(@"src=%@",NSStringFromCGSize(src.size)); UIImage *tmpPattern = [UIImage imageWithCGImage:CGImageCreateWithImageInRect(src.CGImage, clipRect)]; NSLog(@"dest=%@",NSStringFromCGSize(tmpPattern.size)); return tmpPattern; </code></pre> <p>}</p> <p>the result is like this: <a href="http://i.stack.imgur.com/jO0O5.png" rel="nofollow">http://i.stack.imgur.com/jO0O5.png</a></p> <p>is there something wrong?</p> <p>thanks</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload