Bir UIImage bölme işlemini nasıl yarıya indiririm (ortada) böylece iki resim yapar?UIImage ikiye bölünmüş mü?
8
A
cevap
19
,
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);
umut bu size yardımcı olabilir :)
0
Başka bir Stackoverflow sorusundan yanıt. Bu deneyebilirsiniz 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();
5
- (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);
}
+0
Bu, bir sürü bağlamı oluşturmayan tek cevaptır. Kuvars, kırpma işlemini optimize etmede harika bir iş çıkarır (yeni bir bağlam oluşturmak, resim çizmek ve kırpmak yerine görüntünün piksel verilerini hemen alır). Bu görüntüleri birçok küçük parçaya bölersek, potansiyel olarak birçok kat daha hızlıdır! –
0
iOS 11, hızlı 4,0 dürüst olmak düşünmek sürüm https://stackoverflow.com/users/893872/durul-dalkanat Güncellenmiş en iyisi :)
Bu, görüntüyü 4 parçaya böler
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
}
İlgili konular
- 1. UIImage
- 2. Bölünmüş
- 3. Görüntüyü ikiye bölünerek kırpın
- 4. Ondalık dönüştürme ikiye mi?
- 5. Tabloyu ikiye bölme
- 6. UIBezierPath Saydamlık UIImage çevresinde
- 7. Kayan nokta değerlerini ikiye katlama ve bölme
- 8. UIImage imageWithData
- 9. Karşılaştırma UIImage
- 10. Android: 2 göreceli düzen yarım ekranda bölünmüş
- 11. Hassasiyetini kaybetmeden, ikiye katlanabilir mi?
- 12. Düğümlerin bir listesini ikiye bölme
- 13. Bir RelativeLayout öğesinin ikiye bölünmesi
- 14. İki sınırlayıcıyla dize iki sütun halinde bölünmüş
- 15. Bölünmüş tarih aralığı
- 16. Nasıl "bölünmüş" dosyalar
- 17. Bölünmüş dize
- 18. JAVA bölünmüş
- 19. Bölünmüş dize
- 20. Java bölünmüş
- 21. Bölünmüş boşluklar
- 22. bölünmüş dizisi
- 23. Bölünmüş sütun
- 24. Bölünmüş Dize
- 25. bölünmüş metin
- 26. Bölünmüş değerler
- 27. Bölünmüş '/' kadar '['
- 28. SPARQL sorgusu duruma göre bölünmüş
- 29. Twitter bootstrap bölünmüş açılır
- 30. UIImage, UIImage URL'den yüklendiğinde UITableViewCell'de UIImageView Boyutunu Ayarla?
Bu harika çalıştı. Teşekkürler! – Shredder2794