SORU
22 AĞUSTOS 2009, CUMARTESİ


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
11 EKİM 2011, Salı


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)

Bunu Paylaş:
  • Google+
  • E-Posta
Etiketler:

YORUMLAR

SPONSOR VİDEO

Rastgele Yazarlar

  • dirkgently1

    dirkgently1

    13 NİSAN 2006
  • footiecyclo

    footiecyclo

    26 EYLÜL 2009
  • Glove and Boots

    Glove and Bo

    1 ŞUBAT 2007