您的位置:首页 > 移动开发 > IOS开发

iOS 百度地图截屏

2014-04-12 11:30 337 查看
关于百度地图截屏的问题,前几天把自己搞的头大,后来发现,自己太SB了,走了这么长的弯路!原来百度SDK提供的有这么一个方法,就在BMKMapView.h中。截屏方法如下

/**
*获得地图当前可视区域截图
*@return返回view范围内的截取的UIImage
*/
-(UIImage*) takeSnapshot;

为什么不能用常用的方法进行载屏呢?网上给出的答案是这样的 :因为百度地图不是用UIKit实现的,所以得不到截图!

不过通过OpenGL ES View Snapshot,也能截图,但相当繁锁,有兴趣的可以看一下。

苹果文档的内容:http://developer.apple.com/library/ios/#qa/qa1704/_index.html

下面我就把在网上找的常用的关于屏幕截图的一些方法给整理一下,希望能帮到从事这方面开发的瓶友们:

//获得某个范围内的屏幕图像

- (UIImage *)imageFromView: (UIView *) theView atFrame:(CGRect)r

{

UIGraphicsBeginImageContext(theView.frame.size);

CGContextRef context = UIGraphicsGetCurrentContext();

CGContextSaveGState(context);

UIRectClip(r);

[theView.layer renderInContext:context];

UIImage *theImage = UIGraphicsGetImageFromCurrentImageContext();

UIGraphicsEndImageContext();

return theImage;//[self getImageAreaFromImage:theImage atFrame:r];

}

//截取某个View

- (UIImage *)getImageFromView:(UIView *)theView
{
UIGraphicsBeginImageContext(theView.frame.size);
CGContextRef context =UIGraphicsGetCurrentContext();
[theView.layerrenderInContext:context];
UIImage *fectchImage =UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();

return fectchImage;
}
//截取全屏

-(void)fullScreenshots{

UIWindow *screenWindow = [[UIApplication sharedApplication] keyWindow];

UIGraphicsBeginImageContext(screenWindow.frame.size);//全屏截图,包括window

[screenWindow.layer
renderInContext:UIGraphicsGetCurrentContext()];

UIImage
*viewImage = UIGraphicsGetImageFromCurrentImageContext();

UIGraphicsEndImageContext();

UIImageWriteToSavedPhotosAlbum(viewImage,
nil, nil, nil);

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: