Add the test case testSDGraphicsImageRenderer, update the documentation
This commit is contained in:
parent
5cb365ece9
commit
a7682d58b4
|
@ -10,10 +10,11 @@
|
|||
|
||||
/**
|
||||
These following class are provided to use `UIGraphicsImageRenderer` with polyfill, which allows write cross-platform(AppKit/UIKit) code and avoid runtime version check.
|
||||
Compared to `UIGraphicsBeginImageContext`, `UIGraphicsImageRenderer` use dynamic bitmap info from your draw code to generate CGContext, not always use ARGB8888, which is more performant on RAM usage.
|
||||
Compared to `UIGraphicsBeginImageContext`, `UIGraphicsImageRenderer` use dynamic bitmap from your draw code to generate CGContext, not always use ARGB8888, which is more performant on RAM usage.
|
||||
Which means, if you draw CGImage/CIImage which contains grayscale only, the underlaying bitmap context use grayscale, it's managed by system and not a fixed type. (actually, the `kCGContextTypeAutomatic`)
|
||||
For usage, See more in Apple's documentation: https://developer.apple.com/documentation/uikit/uigraphicsimagerenderer
|
||||
For UIKit on iOS/tvOS 10+, these method just use the same `UIGraphicsImageRenderer` API.
|
||||
For others (macOS/watchOS or iOS/tvOS 10-), these method use the `SDImageGraphics.h` to implements the same behavior.
|
||||
For others (macOS/watchOS or iOS/tvOS 10-), these method use the `SDImageGraphics.h` to implements the same behavior (but without dynamic bitmap support)
|
||||
*/
|
||||
|
||||
typedef void (^SDGraphicsImageDrawingActions)(CGContextRef _Nonnull context);
|
||||
|
|
|
@ -12,6 +12,7 @@
|
|||
#import "SDDisplayLink.h"
|
||||
#import "SDInternalMacros.h"
|
||||
#import "SDFileAttributeHelper.h"
|
||||
#import "UIColor+HexString.h"
|
||||
|
||||
@interface SDUtilsTests : SDTestCase
|
||||
|
||||
|
@ -107,6 +108,32 @@
|
|||
expect(hasAttr).beFalsy();
|
||||
}
|
||||
|
||||
- (void)testSDGraphicsImageRenderer {
|
||||
// Main Screen
|
||||
SDGraphicsImageRendererFormat *format = SDGraphicsImageRendererFormat.preferredFormat;
|
||||
#if SD_UIKIT
|
||||
CGFloat screenScale = [UIScreen mainScreen].scale;
|
||||
#elif SD_MAC
|
||||
CGFloat screenScale = [NSScreen mainScreen].backingScaleFactor;
|
||||
#endif
|
||||
expect(format.scale).equal(screenScale);
|
||||
expect(format.opaque).beFalsy();
|
||||
#if SD_UIKIT
|
||||
expect(format.preferredRange).equal(SDGraphicsImageRendererFormatRangeAutomatic);
|
||||
#elif SD_MAC
|
||||
expect(format.preferredRange).equal(SDGraphicsImageRendererFormatRangeStandard);
|
||||
#endif
|
||||
CGSize size = CGSizeMake(100, 100);
|
||||
SDGraphicsImageRenderer *renderer = [[SDGraphicsImageRenderer alloc] initWithSize:size format:format];
|
||||
UIColor *color = UIColor.redColor;
|
||||
UIImage *image = [renderer imageWithActions:^(CGContextRef _Nonnull context) {
|
||||
[color setFill];
|
||||
CGContextFillRect(context, CGRectMake(0, 0, size.width, size.height));
|
||||
}];
|
||||
expect(image.scale).equal(format.scale);
|
||||
expect([[image sd_colorAtPoint:CGPointMake(50, 50)].sd_hexString isEqualToString:color.sd_hexString]).beTruthy();
|
||||
}
|
||||
|
||||
- (void)testSDScaledImageForKey {
|
||||
// Test nil
|
||||
expect(SDScaledImageForKey(nil, nil)).beNil();
|
||||
|
|
Loading…
Reference in New Issue