

延續 Google Maps API 的相關文章,在此假設我們已經成功在畫面上顯示一個 MKMapView,至於要如何取得 MKMapView 中的地圖影像來做更多的應用,可以參考以下程式碼。
由於範例中需動用到 CALayer 類別,所以必須先匯入 QuartzCore Framework,並引用其標頭檔。
接著是取得 MKMapView 中地圖影像的方法,其程式碼如下。
UIGraphicsBeginImageContext(MKMapView.frame.size);
//取得影像
[MKMapView.layer renderInContext:UIGraphicsGetCurrentContext()];
UIImage *captureImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
在上述程式碼中,captureImage 中的影像就是 MKMapView 中的地圖影像,是不是很簡單呢。
沒有留言:
張貼留言