Skip to content

Commit 507e2a6

Browse files
committed
Merge commit '0bba3dfd523c2d985f70ca8854de304c202393cc'
2 parents 060105d + 0bba3df commit 507e2a6

4 files changed

Lines changed: 14 additions & 11 deletions

File tree

QMUI/.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
#
33
# gitignore contributors: remember to update Global/Xcode.gitignore, Objective-C.gitignore & Swift.gitignore
44

5+
qmui.xcodeproj/project.xcworkspace/xcuserdata/
6+
57
## Build generated
68
build/
79
DerivedData/

QMUI/QMUIKit/UIKitExtensions/UIImage+QMUI.h

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,9 @@
1212
#define CGContextInspectSize(size) [QMUIHelper inspectContextSize:size]
1313

1414
#ifdef DEBUG
15-
#define CGContextInspectContext(context) [QMUIHelper inspectContextIfInvalidatedInDebugMode:context]
15+
#define CGContextInspectContext(context) [QMUIHelper inspectContextIfInvalidatedInDebugMode:context]
1616
#else
17-
#define CGContextInspectContext(context) if(![QMUIHelper inspectContextIfInvalidatedInReleaseMode:context]){return nil;}
17+
#define CGContextInspectContext(context) if(![QMUIHelper inspectContextIfInvalidatedInReleaseMode:context]){return nil;}
1818
#endif
1919

2020
typedef NS_ENUM(NSInteger, QMUIImageShape) {
@@ -157,7 +157,7 @@ typedef NS_OPTIONS(NSInteger, QMUIImageBorderPosition) {
157157
* 返回一个被mask的图片
158158
*
159159
* @param maskImage mask图片
160-
* @param usingMaskImageMode 是否使用“mask image”的方式
160+
* @param usingMaskImageMode 是否使用“mask image”的方式,若为 YES,则黑色部分显示,白色部分消失,透明部分显示,其他颜色会按照颜色的灰色度对图片做透明处理。若为 NO,则 maskImage 要求必须为灰度颜色空间的图片(黑白图),白色部分显示,黑色部分消失,透明部分消失,其他灰色度对图片做透明处理。
161161
*
162162
* @return 被mask的图片
163163
*/
@@ -248,19 +248,19 @@ typedef NS_OPTIONS(NSInteger, QMUIImageBorderPosition) {
248248

249249
/**
250250
对传进来的 `UIView` 截图,生成一个 `UIImage` 并返回
251-
251+
252252
@param view 要截图的 `UIView`
253-
253+
254254
@return `UIView` 的截图
255255
*/
256256
+ (UIImage *)imageWithView:(UIView *)view;
257257

258258
/**
259259
对传进来的 `UIView` 截图,生成一个 `UIImage` 并返回
260-
260+
261261
@param view 要截图的 `UIView`
262262
@param afterUpdates 是否要在界面更新完成后才截图
263-
263+
264264
@return `UIView` 的截图
265265
*/
266266
+ (UIImage *)imageWithView:(UIView *)view afterScreenUpdates:(BOOL)afterUpdates;

QMUI/QMUIKit/UIKitExtensions/UIImage+QMUI.m

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -55,8 +55,9 @@ - (UIColor *)averageColor {
5555
}
5656

5757
- (UIImage *)grayImage {
58-
int width = self.size.width;
59-
int height = self.size.height;
58+
// CGBitmapContextCreate 是无倍数的,所以要自己换算成1倍
59+
NSInteger width = self.size.width * self.scale;
60+
NSInteger height = self.size.height * self.scale;
6061
CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceGray();
6162
CGContextRef context = CGBitmapContextCreate(nil, width, height, 8, 0, colorSpace, kCGBitmapByteOrderDefault);
6263
CGContextInspectContext(context);
@@ -66,7 +67,7 @@ - (UIImage *)grayImage {
6667
}
6768
CGContextDrawImage(context,CGRectMake(0, 0, width, height), self.CGImage);
6869
CGImageRef imageRef = CGBitmapContextCreateImage(context);
69-
UIImage *grayImage = [UIImage imageWithCGImage:imageRef];
70+
UIImage *grayImage = [UIImage imageWithCGImage:imageRef scale:self.scale orientation:self.imageOrientation];
7071
CGImageRelease(imageRef);
7172
CGContextRelease(context);
7273
return grayImage;
@@ -323,7 +324,7 @@ - (UIImage *)imageWithMaskImage:(UIImage *)maskImage usingMaskImageMode:(BOOL)us
323324
} else {
324325
// 用一个纯CGImage作为mask。这个image必须是单色(例如:黑白色、灰色)、没有alpha通道、不能被其他图片mask。系统的文档:If `mask' is an image, then it must be in a monochrome color space (e.g. DeviceGray, GenericGray, etc...), may not have alpha, and may not itself be masked by an image mask or a masking color.
325326
// 白色部分显示,黑色部分消失,透明部分消失,其他灰色度对图片做透明处理。
326-
mask = maskRef;
327+
mask = maskRef;
327328
}
328329
CGImageRef maskedImage = CGImageCreateWithMask(self.CGImage, mask);
329330
UIImage *returnImage = [UIImage imageWithCGImage:maskedImage scale:self.scale orientation:self.imageOrientation];
Binary file not shown.

0 commit comments

Comments
 (0)