diff options
author | Fredrik Karlsson <bjorn.fredrik.karlsson@gmail.com> | 2017-10-02 21:40:25 +0200 |
---|---|---|
committer | Fabian Guerra <fabian.guerra@mapbox.com> | 2017-10-02 18:39:30 -0400 |
commit | b767c212c88cefa2917e3bcb48bf466379a521b5 (patch) | |
tree | 05984cfe9eb317799178e50dc4676106f4125edb | |
parent | dff1bc0f517bd27eb421ba8bc82dbd26fae9a37b (diff) | |
download | qtlocation-mapboxgl-b767c212c88cefa2917e3bcb48bf466379a521b5.tar.gz |
[ios] Fix snapshot scale
-rw-r--r-- | platform/darwin/src/MGLMapSnapshotter.mm | 11 | ||||
-rw-r--r-- | platform/ios/src/UIImage+MGLAdditions.h | 2 | ||||
-rw-r--r-- | platform/ios/src/UIImage+MGLAdditions.mm | 4 |
3 files changed, 13 insertions, 4 deletions
diff --git a/platform/darwin/src/MGLMapSnapshotter.mm b/platform/darwin/src/MGLMapSnapshotter.mm index 3dbebf1f08..b4c1704b8d 100644 --- a/platform/darwin/src/MGLMapSnapshotter.mm +++ b/platform/darwin/src/MGLMapSnapshotter.mm @@ -49,6 +49,10 @@ const CGFloat MGLSnapshotterMinimumPixelSize = 64; @end +@interface MGLMapSnapshotter() +@property (nonatomic) MGLMapSnapshotOptions *options; +@end + @implementation MGLMapSnapshotter { std::shared_ptr<mbgl::ThreadPool> _mbglThreadPool; @@ -60,6 +64,7 @@ const CGFloat MGLSnapshotterMinimumPixelSize = 64; { self = [super init]; if (self) { + _options = options; _loading = false; mbgl::DefaultFileSource *mbglFileSource = [MGLOfflineStorage sharedOfflineStorage].mbglFileSource; @@ -130,7 +135,11 @@ const CGFloat MGLSnapshotterMinimumPixelSize = 64; completion(nil, error); }); } else { +#if TARGET_OS_IPHONE + MGLImage *mglImage = [[MGLImage alloc] initWithMGLPremultipliedImage:std::move(image) scale:self.options.scale]; +#else MGLImage *mglImage = [[MGLImage alloc] initWithMGLPremultipliedImage:std::move(image)]; +#endif // Process image watermark in a work queue dispatch_queue_t workQueue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0); @@ -138,7 +147,7 @@ const CGFloat MGLSnapshotterMinimumPixelSize = 64; #if TARGET_OS_IPHONE UIImage *logoImage = [UIImage imageNamed:@"mapbox" inBundle:[NSBundle mgl_frameworkBundle] compatibleWithTraitCollection:nil]; - UIGraphicsBeginImageContext(mglImage.size); + UIGraphicsBeginImageContextWithOptions(mglImage.size, NO, [UIScreen mainScreen].scale); [mglImage drawInRect:CGRectMake(0, 0, mglImage.size.width, mglImage.size.height)]; [logoImage drawInRect:CGRectMake(MGLLogoImagePosition.x, mglImage.size.height - (MGLLogoImagePosition.y + logoImage.size.height), logoImage.size.width,logoImage.size.height)]; diff --git a/platform/ios/src/UIImage+MGLAdditions.h b/platform/ios/src/UIImage+MGLAdditions.h index 3c179d6324..22bb740242 100644 --- a/platform/ios/src/UIImage+MGLAdditions.h +++ b/platform/ios/src/UIImage+MGLAdditions.h @@ -8,7 +8,7 @@ NS_ASSUME_NONNULL_BEGIN - (nullable instancetype)initWithMGLStyleImage:(const mbgl::style::Image *)styleImage; -- (nullable instancetype)initWithMGLPremultipliedImage:(const mbgl::PremultipliedImage&&)mbglImage; +- (nullable instancetype)initWithMGLPremultipliedImage:(const mbgl::PremultipliedImage&&)mbglImage scale:(CGFloat)scale; - (std::unique_ptr<mbgl::style::Image>)mgl_styleImageWithIdentifier:(NSString *)identifier; diff --git a/platform/ios/src/UIImage+MGLAdditions.mm b/platform/ios/src/UIImage+MGLAdditions.mm index 7cf1ed9bcc..8ab1d5c259 100644 --- a/platform/ios/src/UIImage+MGLAdditions.mm +++ b/platform/ios/src/UIImage+MGLAdditions.mm @@ -22,14 +22,14 @@ return self; } -- (nullable instancetype)initWithMGLPremultipliedImage:(const mbgl::PremultipliedImage&&)mbglImage +- (nullable instancetype)initWithMGLPremultipliedImage:(const mbgl::PremultipliedImage&&)mbglImage scale:(CGFloat)scale { CGImageRef image = CGImageFromMGLPremultipliedImage(mbglImage.clone()); if (!image) { return nil; } - self = [self initWithCGImage:image scale:1.0 orientation:UIImageOrientationUp]; + self = [self initWithCGImage:image scale:scale orientation:UIImageOrientationUp]; CGImageRelease(image); return self; |