如何从地图视图中拍摄屏幕截图 [英] how to take a screen shot from a mapview
本文介绍了如何从地图视图中拍摄屏幕截图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在我的应用程序中,我使用了mapview.在特定的地方,我可以添加注释.我想拍摄带注解的那个地方的快照.
In my application i have used mapview. On particular place i can put annotation. i want to take the snap shot of that place with annotation in it.
我试图实现这一点.
CGSize size = self.view.bounds.size;
CGRect screensize = CGRectMake(40,40,size.width-240,size.height-400);
UIGraphicsBeginImageContext(screensize.size);
[self.view.layer renderInContext:UIGraphicsGetCurrentContext()];
UIImage *screenshotImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
UIImageWriteToSavedPhotosAlbum(screenshotImage, nil, nil, nil);
UIGraphicsEndImageContext();
此代码获取捕捉,但它从(0,0)坐标获取捕捉.我想从(40,40)坐标中获取快照,图像的大小应为80 * 80.
this code takes the snap but it takes the snap from (0,0) coordinates. i want to take the snap from (40,40) coordinates and the size of the image should be 80*80.
我该怎么做?
推荐答案
我认为您不能直接做到这一点.获得整个图像并裁剪所需的区域.
I don't think you can do it directly. Get the entire image and the crop the desired region.
CGSize size = self.view.bounds.size;
CGRect cropRect = CGRectMake(40, 40, 80, 80);
/* Get the entire on screen map as Image */
UIGraphicsBeginImageContext(size);
[self.view.layer renderInContext:UIGraphicsGetCurrentContext()];
UIImage * mapImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
/* Crop the desired region */
CGImageRef imageRef = CGImageCreateWithImageInRect(mapImage.CGImage, cropRect);
UIImage * cropImage = [UIImage imageWithCGImage:imageRef];
CGImageRelease(imageRef);
/* Save the cropped image */
UIImageWriteToSavedPhotosAlbum(cropImage, nil, nil, nil);
UIGraphicsEndImageContext();
这篇关于如何从地图视图中拍摄屏幕截图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文