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);
}
/**
*获得地图当前可视区域截图
*@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);
}
相关文章推荐
- iOS 百度地图截屏
- iOS 【关于百度地图大头针标记 选中状态/点击状态 的区别及处理办法】
- iOS百度地图简单集成使用
- ios 截屏
- iOS 判断并使用 百度地图 高德地图 自带地图 导航(使用URI,不集成sdk)
- iOS之百度地图获取地理位置名称
- iOS百度地图 Demo
- iOS百度地图——用户当前位置
- iOS截屏功能
- iOS 截屏
- iOS 截屏,view截图的基本方法
- iOS中正确的截屏姿势
- IOS开发—截屏
- iOS 截屏/将图片存储到相册或沙盒目录下
- iOS 百度地图开发集成使用
- 【iOS开发-82】四个案例认识Quartz2D:模拟UIImageView、圆形头像切割、打水印、截屏
- iOS开发-检测用户截屏, 并获取所截图片
- IOS百度地图气泡内容自定义
- iOS 百度地图的模糊搜索地址以及回调的使用
- iOS开发Quzrtz2D:十一:图片截屏以及图片擦除