Files
MapLibreParticleLab/platform/ios/src/UIImage+MGLAdditions.mm
Fabian Guerra Soto f01588cac7 [ios, macos] Improve snap shotter documentation. (#10020)
* [ios, macos] Improve snap shotter documentation.

* [macos] Save snapshots in correct format

* [macos] Renamed snapshot item to Export Image

* [ios, macos] Clarify Snapshotter documentation.

* [ios] Fix snapshot scale

* [macOS] Fix snapshotter 4x scaling.

* [ios] Fix snapshotter final image scale.

* [ios, macos] Update snapshotter size documentation.

* [ios, macos] Throw an exception when the snapshotter has already started.

* [ios, macos] Add snapshotter header example.

* [ios, macos] Use one of the predefined Foundation's exception names.
2017-10-04 10:03:03 -04:00

49 lines
1.5 KiB
Plaintext

#import "UIImage+MGLAdditions.h"
#include <mbgl/util/image+MGLAdditions.hpp>
@implementation UIImage (MGLAdditions)
- (nullable instancetype)initWithMGLStyleImage:(const mbgl::style::Image *)styleImage
{
CGImageRef image = CGImageFromMGLPremultipliedImage(styleImage->getImage().clone());
if (!image) {
return nil;
}
if (self = [self initWithCGImage:image scale:styleImage->getPixelRatio() orientation:UIImageOrientationUp])
{
if (styleImage->isSdf())
{
self = [self imageWithRenderingMode:UIImageRenderingModeAlwaysTemplate];
}
}
CGImageRelease(image);
return self;
}
- (nullable instancetype)initWithMGLPremultipliedImage:(const mbgl::PremultipliedImage&&)mbglImage scale:(CGFloat)scale
{
CGImageRef image = CGImageFromMGLPremultipliedImage(mbglImage.clone());
if (!image) {
return nil;
}
self = [self initWithCGImage:image scale:scale orientation:UIImageOrientationUp];
CGImageRelease(image);
return self;
}
- (std::unique_ptr<mbgl::style::Image>)mgl_styleImageWithIdentifier:(NSString *)identifier {
BOOL isTemplate = self.renderingMode == UIImageRenderingModeAlwaysTemplate;
return std::make_unique<mbgl::style::Image>([identifier UTF8String],
self.mgl_premultipliedImage,
float(self.scale), isTemplate);
}
-(mbgl::PremultipliedImage)mgl_premultipliedImage {
return MGLPremultipliedImageFromCGImage(self.CGImage);
}
@end