मैं यूआईएममेज को विभाजित करने के बारे में कैसे आधा (मध्य में नीचे) तो यह दो छवियों को बना देगा?आधे में विभाजित UIImage?
उत्तर
आप इस कोशिश कर सकते हैं,
UIImage *image = [UIImage imageNamed:@"yourImage.png"];
CGImageRef tmpImgRef = image.CGImage;
CGImageRef topImgRef = CGImageCreateWithImageInRect(tmpImgRef, CGRectMake(0, 0, image.size.width, image.size.height/2.0));
UIImage *topImage = [UIImage imageWithCGImage:topImgRef];
CGImageRelease(topImgRef);
CGImageRef bottomImgRef = CGImageCreateWithImageInRect(tmpImgRef, CGRectMake(0, image.size.height/2.0, image.size.width, image.size.height/2.0));
UIImage *bottomImage = [UIImage imageWithCGImage:bottomImgRef];
CGImageRelease(bottomImgRef);
आशा है कि यह मदद कर सकता है, :)
अन्य स्टैक ओवरफ्लो प्रश्न से उत्तर दें। Source
UIImage *splitMeInTwo = [UIImage imageNamed:@"Star.png"];
UIImageView *original = [[UIImageView alloc] initWithImage:splitMeInTwo];
[self.view addSubview:original];
[original release];
// The size of each part is half the height of the whole image
CGSize size = CGSizeMake([splitMeInTwo size].width, [splitMeInTwo size].height/2);
// Create image-based graphics context for top half
UIGraphicsBeginImageContextWithOptions(size, NO, 0.0);
// Draw into context, bottom half is cropped off
//[image drawAtPoint:CGPointMake(0.0,0.0)];
[splitMeInTwo drawAtPoint:CGPointMake(0.0,0.0) blendMode:kCGBlendModeNormal alpha:1.0];
// Grab the current contents of the context as a UIImage
// and add it to our array
UIImage *top = UIGraphicsGetImageFromCurrentImageContext();
UIImageView *topV = [[UIImageView alloc] initWithImage:top];
CGRect frameTop = topV.frame;
frameTop.origin.x += 360.0f;
topV.frame = frameTop;
[self.view addSubview:topV];
[topV release];
UIGraphicsEndImageContext();
- (void)splitImage:(UIImage *)image
{
CGFloat imgWidth = image.size.width/2;
CGFloat imgheight = image.size.height;
CGRect leftImgFrame = CGRectMake(0, 0, imgWidth, imgheight);
CGRect rightImgFrame = CGRectMake(imgWidth, 0, imgWidth, imgheight);
CGImageRef left = CGImageCreateWithImageInRect(image.CGImage, leftImgFrame);
CGImageRef right = CGImageCreateWithImageInRect(image.CGImage, rightImgFrame);
// These are the images we want!
UIImage *leftImage = [UIImage imageWithCGImage:left];
UIImage *rightImage = [UIImage imageWithCGImage:right];
// Don't forget to free the memory!
CGImageRelease(left);
CGImageRelease(right);
}
यह एकमात्र उत्तर है जो संदर्भों का पूरा समूह नहीं बनाता है। क्वार्ट्ज क्रॉपिंग प्रक्रिया को अनुकूलित करने के लिए एक नया काम करता है (छवि का पिक्सेल डेटा सीधे प्राप्त करने के बजाय, नया संदर्भ बनाने, छवि खींचने, फिर फसल) प्राप्त करने के लिए। जब हम कई छोटे हिस्सों में छवियों को विभाजित कर रहे हैं तो यह संभावित रूप से कई गुना तेजी से होता है! –
आईओएस 11, तेज 4.0 अद्यतन संस्करण https://stackoverflow.com/users/893872/durul-dalkanat जो मैं ईमानदारी से लगता है सबसे अच्छा :)
यह एक छवि को 4 भागों में विभाजित करता है
func splitImage(image2D: UIImage) -> [UIImage] {
let imgWidth = image2D.size.width/2
let imgHeight = image2D.size.height/2
var imgImages:[UIImage] = []
let leftHigh = CGRect(x: 0, y: 0, width: imgWidth, height: imgHeight)
let rightHigh = CGRect(x: imgWidth, y: 0, width: imgHeight, height: imgHeight)
let leftLow = CGRect(x: 0, y: imgHeight, width: imgWidth, height: imgHeight)
let rightLow = CGRect(x: imgWidth, y: imgHeight, width: imgWidth, height: imgHeight)
let leftQH = image2D.cgImage?.cropping(to:leftHigh)
let rightHQ = image2D.cgImage?.cropping(to:rightHigh)
let leftQL = image2D.cgImage?.cropping(to:leftLow)
let rightQL = image2D.cgImage?.cropping(to:rightLow)
imgImages.append(UIImage(cgImage: leftQH!))
imgImages.append(UIImage(cgImage: rightHQ!))
imgImages.append(UIImage(cgImage: leftQL!))
imgImages.append(UIImage(cgImage: rightQL!))
return imgImages
}
- 1. आधे
- 2. UIImage
- 3. UIImage
- 4. UIImage
- 5. UIImage
- 6. UIImage
- 7. UIImage
- 8. UIImage
- 9. UIImage
- 10. आधे स्लाइडिंग व्यूअर एंड्रॉइड
- 11. जावा आधे यूडीपी पैकेट
- 12. केवल आधे रिकॉर्ड्स का चयन करें
- 13. CATransform3D कारणों छवि के आधे
- 14. UIImage घुमाएं?
- 15. UIImage asynchronously
- 16. एक UIImage
- 17. एक UIImage
- 18. UIImage फ्रेम
- 19. एक UIImage
- 20. UIImage की CGImage वापसी शून्य
- 21. [UIImage imageNamed ...] और [UIImage imageWithData ...] के बीच अंतर?
- 22. विभाजित छवि के साथ UISegementedControl अंतरिक्ष
- 23. UIImage मेटा डेटा
- 24. UIImage + RoundedCorner SDWebImage
- 25. AVFoundation कैप्चर UIImage
- 26. फेसबुक आईओएस एसडीके - UIImage
- 27. UIWebview सामग्री को UIImage
- 28. सहेजें UIImage, गलत अभिविन्यास
- 29. UIView को UIImage
- 30. आईफोन UIImage या UIImageView
यह बहुत अच्छा काम करता है। धन्यवाद! – Shredder2794