Nasıl Uİİmage 90 derece Döndürmek için?
Saat yönünün tersine 90 derece (yatay) döndürmek istiyorum UİİmageOrientationUp (dikey) bir Uİİmage var. Bir CGAffineTransform kullanmak istemiyorum. Bu Uİİmage pikseller aslında pozisyon vardiya istiyorum. Kod bloğu (aşağıda gösterilen) aslında bunu yapmak için bir Uİİmage yeniden boyutlandırma amaçlı kullanıyorum. Bu Uİİmage geçerli boyutu olarak hedef boyutu kurdum ama bir hata alıyorum(Hata): CGBitmapContextCreate: geçersiz veri/satır bayt: en az 8 bit tamsayı için 1708/, 3 bileşen bileşenleri, kCGİmageAlphaPremultipliedLast olmalıdır.(Hedef boyutu BTW olarak ben daha KÜÇÜK bir sağlamak zaman bir hata anlamadım). Herhangi biriniz sadece benim Uİİmage DÖNDÜRMEK için nasıl göster bana 90 derece geçerli boyutunu koruyarak sadece temel grafik fonksiyonlarını kullanarak CCW?
-(UIImage*)reverseImageByScalingToSize:(CGSize)targetSize:(UIImage*)anImage
{
UIImage* sourceImage = anImage;
CGFloat targetWidth = targetSize.height;
CGFloat targetHeight = targetSize.width;
CGImageRef imageRef = [sourceImage CGImage];
CGBitmapInfo bitmapInfo = CGImageGetBitmapInfo(imageRef);
CGColorSpaceRef colorSpaceInfo = CGImageGetColorSpace(imageRef);
if (bitmapInfo == kCGImageAlphaNone) {
bitmapInfo = kCGImageAlphaNoneSkipLast;
}
CGContextRef bitmap;
if (sourceImage.imageOrientation == UIImageOrientationUp || sourceImage.imageOrientation == UIImageOrientationDown) {
bitmap = CGBitmapContextCreate(NULL, targetHeight, targetWidth, CGImageGetBitsPerComponent(imageRef), CGImageGetBytesPerRow(imageRef), colorSpaceInfo, bitmapInfo);
} else {
bitmap = CGBitmapContextCreate(NULL, targetWidth, targetHeight, CGImageGetBitsPerComponent(imageRef), CGImageGetBytesPerRow(imageRef), colorSpaceInfo, bitmapInfo);
}
if (sourceImage.imageOrientation == UIImageOrientationRight) {
CGContextRotateCTM (bitmap, radians(90));
CGContextTranslateCTM (bitmap, 0, -targetHeight);
} else if (sourceImage.imageOrientation == UIImageOrientationLeft) {
CGContextRotateCTM (bitmap, radians(-90));
CGContextTranslateCTM (bitmap, -targetWidth, 0);
} else if (sourceImage.imageOrientation == UIImageOrientationDown) {
// NOTHING
} else if (sourceImage.imageOrientation == UIImageOrientationUp) {
CGContextRotateCTM (bitmap, radians(90));
CGContextTranslateCTM (bitmap, 0, -targetHeight);
}
CGContextDrawImage(bitmap, CGRectMake(0, 0, targetWidth, targetHeight), imageRef);
CGImageRef ref = CGBitmapContextCreateImage(bitmap);
UIImage* newImage = [UIImage imageWithCGImage:ref];
CGContextRelease(bitmap);
CGImageRelease(ref);
return newImage;
}
CEVAP
En kolay yolu (iş parçacığı güvenli) yapmak olduğuna inanıyorum:
//assume that the image is loaded in landscape mode from disk
UIImage * LandscapeImage = [UIImage imageNamed: imgname];
UIImage * PortraitImage = [[UIImage alloc] initWithCGImage: LandscapeImage.CGImage
scale: 1.0
orientation: UIImageOrientationRight];
Not: OlarakBrainwarebu sadece görüntünün yön veri değiştirir dedi - piksel verilerini dokunulmaz. Bazı uygulamalar için bu yeterli olmayabilir.
Ya da swıft:
let PortraitImage : UIImage = UIImage(CGImage: LandscapeImage.CGImage ,
scale: 1.0 ,
orientation: UIImageOrientation.Right)
Nasıl tarih sadece SQL Server datetime...
Nasıl bir bash işlevi, bir dize değeri...
Nasıl Uİİmage (Cocoa Touch) veya CGİma...
Nasıl iPhone dinamik, renkli 1x1 bir U...
Merkezi bir noktada bir bit eşlem dönd...