1

目標: オーバーレイ (MKOverlayView) と注釈を含むマップのスクリーンショットを取得します。

私がやった事 :

マップビュー、オーバーレイビュー、および注釈ビューが存在します。これはすべて 1 つのコントローラーによって処理されます。

スクリーンショットを撮るためにAppleが提供するコードを使用しています

// ターゲット サイズでグラフィックス コンテキストを作成します

// On iOS 4 and later, use UIGraphicsBeginImageContextWithOptions to take the scale into consideration

// On iOS prior to 4, fall back to use UIGraphicsBeginImageContext

CGSize imageSize = [[UIScreen mainScreen] bounds].size;

if (NULL != UIGraphicsBeginImageContextWithOptions)
    UIGraphicsBeginImageContextWithOptions(imageSize, NO, 0);
else
    UIGraphicsBeginImageContext(imageSize);

CGContextRef context = UIGraphicsGetCurrentContext();

// Iterate over every window from back to front
for (UIWindow *window in [[UIApplication sharedApplication] windows]) 
{
    if (![window respondsToSelector:@selector(screen)] || [window screen] == [UIScreen mainScreen])
    {
        // -renderInContext: renders in the coordinate space of the layer,
        // so we must first apply the layer's geometry to the graphics context
        CGContextSaveGState(context);
        // Center the context around the window's anchor point
        CGContextTranslateCTM(context, [window center].x, [window center].y);
        // Apply the window's transform about the anchor point
        CGContextConcatCTM(context, [window transform]);
        // Offset by the portion of the bounds left of and above the anchor point
        CGContextTranslateCTM(context,
                              -[window bounds].size.width * [[window layer] anchorPoint].x,
                              -[window bounds].size.height * [[window layer] anchorPoint].y);

        // Render the layer hierarchy to the current context
        [[window layer] renderInContext:context];
        //for(self.mapView.overlayView.layer.)
        //[self.mapView.overlayView.layer renderInContext:context];    
        // Restore the context
        CGContextRestoreGState(context);
    }
}

// Retrieve the screenshot image
UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();

問題は、上記のコード行がマップ ビューと注釈ビューのみのスクリーンショットを取得することです。オーバーレイ ビューは存在しません。

また、オーバーレイ ビュー (MKOverlayView) を明確にするためにイメージです。これはスクリーンショットには表示されません。私は OpenGL を使用していません。デフォルトのピンである注釈ビューを見ることができますが、スクリーンショットはタイルをキャプチャできません。私は長い間それに取り組んできました。どんな助けでも大歓迎です!ありがとう!

これが私のコントローラーの外観です

->> MYコントローラー

  ->> MKMapViewOBject
         ->> MKMapViewOverlayView
         ->> MKMapOverlay
         ->> MKAnnotation
         ->> MKAnnotationView

renderInContext:context に問題がありますか?

詳しくは :

オーバーレイ ビューでタイルを描画するための次のコード

    UIGraphicsPushContext(context);
NSData* data = //get data

if(data)
{
    UIImage* img = [[UIImage alloc] initWithData:data];
    [img drawInRect:drawRect blendMode:kCGBlendModeNormal alpha:0.4 ];
    [img release];

}

UIGraphicsPopContext();
4

1 に答える 1

0

問題は drawMapRect にありました。drawMapRect は、異なるスレッドでマップをオーバーレイするときに MKMapRect の異なる値で呼び出されます。したがって、Apple はコードをスレッド セーフにし、複数の異なる可視 MapRect で実行できるようにしたいと考えています。

指定された MapRect に基づくオーバーレイの作成に取り組んでいます。つまり、その可視部分です。

于 2012-06-29T16:26:08.557 に答える