2013-06-13 20 views
5

Harita üzerinde yerleştirilmek üzere bir yol üstbilgisi var. Rotasyonunu, temel harita görünümü ile tam olarak örtüşecek şekilde ayarlamalıyım. Bunu nasıl başarabilirim? Döndürme açısını buldum. Yer paylaşımlı görünümümü nasıl döndürebilirim? Şimdiye kadar bindirmeyi ekledim, ancak dönüşümleri kullanarak döndüremiyorum. Fark ettiğim, açıyı değiştirdiğimde, resmin dönmediği, bunun yerine x ekseni boyunca (yan yollar) kaydığıdır. İşte MKOverlayView döndürülmesi gereken

Bu ben elle GIMP kullanarak görüntüyü döndürmek ve koyun olduğu bir geçici çözüm var

enter image description here

elde ediyoruz ben

- (void)drawMapRect:(MKMapRect)mapRect zoomScale:(MKZoomScale)zoomScale inContext:(CGContextRef)context 
{ 
    NSString *imagePath = [[NSBundle mainBundle] pathForResource:@"routeImage" ofType:@"png"]; 
    UIImage *image = [[UIImage alloc] initWithContentsOfFile:imagePath]; 

    MKMapRect theMapRect = self.overlay.boundingMapRect; 
    CGRect theRect = [self rectForMapRect:theMapRect]; 

    CGAffineTransform transform = CGAffineTransformMakeRotation((-35.88)/180.0 * M_PI); 
    [self setTransform:transform]; 

    CGContextSaveGState(context); 

    CGContextScaleCTM(context, 1.0, -1.0); 
    CGContextTranslateCTM(context, 0.0, -theRect.size.height); 
    CGContextDrawImage(context, theRect,image.CGImage); 
    CGContextRestoreGState(context); 
} 

çalıştı kodudur. Ama özelleştirilmeye ihtiyacım var.

Bu

GIMP'i kullanılarak dönüştürülmüş image ve bindirme

harita üzerinde yerleştirilir ve [not dönüşümü ile bağlamı döndüğünde bu durum: görüntü döndürülür fakat bakınız tam konumda değildir bağlamı dönerken image. Ayrıca bu ben

 //Hayl-Road-Final.png is the actual image without transformation using GIMP 

     UIImage *image = [[UIImage imageNamed:@"Hayl-Road-Final.png"] retain]; 
     CGImageRef imageReference = image.CGImage; 


     MKMapRect theMapRect = [self.overlay boundingMapRect]; 
     CGRect theRect   = [self rectForMapRect:theMapRect]; 


     // We need to flip and reposition the image here 
     CGContextScaleCTM(ctx, 1.0, -1.0); 
     CGContextTranslateCTM(ctx, 0.0, -theRect.size.height); 

     CGContextRotateCTM(ctx,-35.88); 
     //drawing the image to the context 
     CGContextDrawImage(ctx, theRect, imageReference); 
+0

nasıl başlangıç ​​kodunuz mu yoksa dönüşümü nasıl uygulayacağınız "kendi" görüşünüz nedir? Bağlamı döndürmeyi denediniz mi? – Lukas

+0

@Lukas: Kendiliğinden başvurulan bindirme görünümü. Bağlamı döndürmeyi bile denedim. Olanlar, görüntü kopukluklarını izlerken. Bunu başarmanın başka bir yolu var mı? Yapmanın bir yolu varmış gibi hissediyorum, ama denediğim tüm yollar ya yakınlaştırma ya da tam konumdaki görüntü kırma ile bir dönüş elde edebilirim. İkisi de değil. – Meera

+0

@MeeraJPai, görüntünün döndürülmesini istediğiniz şekilde döndüren bir sürümü sunabilir miydiniz? Anladığım kadarıyla bu tek örnekte istediğin şeyi almak için geçici çözümünüzü kullanman gerekebilir. –

cevap

0

deneyin bu yöntemi ekleme yaptıklarını yakınlaştırma görüntü sonları]

geçerli:

- (UIImage *) rotate: (UIImage *) image angle:(double) 
{ 
    //double angle = 20; 
    CGSize s = {image.size.width, image.size.height}; 
    UIGraphicsBeginImageContext(s); 
    CGContextRef ctx = UIGraphicsGetCurrentContext(); 
    CGContextTranslateCTM(ctx, 0,image.size.height); 
    CGContextScaleCTM(ctx, 1.0, -1.0); 

    CGContextRotateCTM(ctx, 2*M_PI*angle/360); 
    CGContextDrawImage(ctx,CGRectMake(0,0,image.size.width, image.size.height),image.CGImage); 
    UIImage *newImage = UIGraphicsGetImageFromCurrentImageContext(); 
    UIGraphicsEndImageContext(); 
    return newImage; 

} 
0
From your code, you change order of two line. It will be ok: 

CGContextScaleCTM(ctx, 1.0, -1.0); 
CGContextRotateCTM(ctx,-35.88); 
CGContextTranslateCTM(ctx, 0.0, -theRect.size.height); 
CGContextDrawImage(ctx, theRect, imageReference); 

Benimle doğrudur, lütfen deneyin

İlgili konular