chore: Initial clean commit

- Removed YuMi/Library/ (138 MB, not tracked)
- Removed YuMi/Resources/ (23 MB, not tracked)
- Removed old version assets (566 files, not tracked)
- Excluded Pods/, xcuserdata/ and other build artifacts
- Clean repository optimized for company server deployment
This commit is contained in:
edwinQQQ
2025-10-09 16:19:14 +08:00
commit a35a711be6
5582 changed files with 408913 additions and 0 deletions

View File

@@ -0,0 +1,65 @@
//
// UIImage+Utils.h
// YYMobileFramework
//
// Created by wuwei on 14/6/20.
// Copyright (c) 2014年 YY Inc. All rights reserved.
//
#import <UIKit/UIKit.h>
typedef NS_ENUM(NSUInteger, GradientType) {
GradientTypeTopToBottom = 0,//从上到小
GradientTypeLeftToRight = 1,//从左到右
GradientTypeUpleftToLowright = 2,//左上到右下
GradientTypeUprightToLowleft = 3,//右上到左下
};
@interface UIImage (Utils)
- (UIImage *)grayscaleImage;
- (UIImage *)imageBlendInGray;
- (UIImage *)imageWithBlendMode:(CGBlendMode)blendMode;
+ (UIImage *)imageWithColor:(UIColor *)color;
+ (UIImage *)imageWithColor:(UIColor *)color size:(CGSize)size;
+ (UIImage *)fixOrientation:(UIImage *)aImage;
- (UIImage *)imageWithColor:(UIColor *)color;
- (UIImage *)setCornerWithRadius:(CGFloat)radius andSize:(CGSize)size;
//异步生成纯色圆角图片
- (void)imageWithSize:(CGSize)size radius:(CGFloat)radius backColor:(UIColor *)backColor completion:(void(^)(UIImage *image))completion;
/**
返回指定大小,颜色,渐变模式的渐变色图片
*/
+ (UIImage *)gradientColorImageFromColors:(NSArray<UIColor *>*)colors gradientType:(GradientType)gradientType imgSize:(CGSize)imgSize;
+ (UIImage *)waterImageWithImage:(UIImage *)image waterImage:(UIImage *)waterImage waterImageRect:(CGRect)rect;
+ (CGSize)sizeWithImageOriginSize:(CGSize)originSize
minSize:(CGSize)imageMinSize
maxSize:(CGSize)imageMaxSize;
///裁剪图片
- (UIImage *)cutImage:(CGSize)newSize;
- (UIImage *)cropRightAndBottomPixels:(NSUInteger)pixels;
-(UIImage *)compressWithMaxLength:(NSUInteger)maxLength;
- (UIImage *)roundedImageWithCornerRadius:(CGFloat)cornerRadius size:(CGSize)size;
+(UIImage *)getImageFromView:(UIView *)view;
+ (NSString *)getImageTypeWithImageData: (NSData *)data;
+(UIImage *)getLanguageImage:(NSString *)image;
+(NSString *)getLanguageText:(NSString *)image;
- (UIImage *)resizeTo:(CGSize)size;
- (UIImage *)imageByApplyingAlpha:(CGFloat)alpha;
@end

View File

@@ -0,0 +1,592 @@
//
// UIImage+Utils.m
// YYMobileFramework
//
// Created by wuwei on 14/6/20.
// Copyright (c) 2014 YY Inc. All rights reserved.
//
#import "UIImage+Utils.h"
#import <ImageIO/ImageIO.h>
@implementation UIImage (Utils)
- (UIImage *)grayscaleImage
{
CGFloat width = self.size.width;
CGFloat height = self.size.height;
CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceGray();
CGContextRef context = CGBitmapContextCreate(nil,
width,
height,
8,
0,
colorSpace,
kCGImageAlphaNone);
// kCGBitmapByteOrder32Little | kCGImageAlphaPremultipliedLast);
if (context == NULL) {
return nil;
}
CGContextDrawImage(context, CGRectMake(0, 0, width, height), self.CGImage);
CGImageRef imageRef = CGBitmapContextCreateImage(context);
UIImage *grayscaleImage = [UIImage imageWithCGImage:imageRef];
CGImageRelease(imageRef);
CGContextRelease(context);
CGColorSpaceRelease(colorSpace);
return grayscaleImage;
}
- (UIImage *)imageBlendInGray {
UIGraphicsBeginImageContext(self.size);
CGRect bounds = CGRectMake(0, 0, self.size.width, self.size.height);
CGContextRef context = UIGraphicsGetCurrentContext();
CGContextFillRect(context, bounds);
[self drawInRect:bounds blendMode:kCGBlendModeLuminosity alpha:1.0f];
[self drawInRect:bounds blendMode:kCGBlendModeDestinationIn alpha:1.0f];
UIImage *newImg = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return newImg;
}
- (UIImage *)imageWithBlendMode:(CGBlendMode)blendMode {
UIGraphicsBeginImageContextWithOptions(self.size, NO, 0.0f);
CGRect bounds = CGRectMake(0, 0, self.size.width, self.size.height);
UIRectFill(bounds);
[self drawInRect:bounds blendMode:blendMode alpha:1.0f];
if (blendMode != kCGBlendModeDestinationIn) {
[self drawInRect:bounds blendMode:kCGBlendModeDestinationIn alpha:1.0f];
}
UIImage *newImg = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return newImg;
}
+ (UIImage *)imageWithColor:(UIColor *)color
{
return [self imageWithColor:color size:CGSizeMake(1, 1)];
}
+ (UIImage *)imageWithColor:(UIColor *)color size:(CGSize)size {
if (!color || size.width <= 0 || size.height <= 0) return nil;
CGRect rect = CGRectMake(0.0f, 0.0f, size.width + 1, size.height);
UIGraphicsBeginImageContextWithOptions(rect.size, NO, 0);
CGContextRef context = UIGraphicsGetCurrentContext();
CGContextSetFillColorWithColor(context, color.CGColor);
CGContextFillRect(context, rect);
UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return image;
}
+ (UIImage *)fixOrientation:(UIImage *)aImage {
// No-op if the orientation is already correct
if (aImage.imageOrientation == UIImageOrientationUp)
return aImage;
// We need to calculate the proper transformation to make the image upright.
// We do it in 2 steps: Rotate if Left/Right/Down, and then flip if Mirrored.
CGAffineTransform transform = CGAffineTransformIdentity;
switch (aImage.imageOrientation) {
case UIImageOrientationDown:
case UIImageOrientationDownMirrored:
transform = CGAffineTransformTranslate(transform, aImage.size.width, aImage.size.height);
transform = CGAffineTransformRotate(transform, M_PI);
break;
case UIImageOrientationLeft:
case UIImageOrientationLeftMirrored:
transform = CGAffineTransformTranslate(transform, aImage.size.width, 0);
transform = CGAffineTransformRotate(transform, M_PI_2);
break;
case UIImageOrientationRight:
case UIImageOrientationRightMirrored:
transform = CGAffineTransformTranslate(transform, 0, aImage.size.height);
transform = CGAffineTransformRotate(transform, -M_PI_2);
break;
default:
break;
}
switch (aImage.imageOrientation) {
case UIImageOrientationUpMirrored:
case UIImageOrientationDownMirrored:
transform = CGAffineTransformTranslate(transform, aImage.size.width, 0);
transform = CGAffineTransformScale(transform, -1, 1);
break;
case UIImageOrientationLeftMirrored:
case UIImageOrientationRightMirrored:
transform = CGAffineTransformTranslate(transform, aImage.size.height, 0);
transform = CGAffineTransformScale(transform, -1, 1);
break;
default:
break;
}
// Now we draw the underlying CGImage into a new context, applying the transform
// calculated above.
CGContextRef ctx = CGBitmapContextCreate(NULL, aImage.size.width, aImage.size.height,
CGImageGetBitsPerComponent(aImage.CGImage), 0,
CGImageGetColorSpace(aImage.CGImage),
CGImageGetBitmapInfo(aImage.CGImage));
CGContextConcatCTM(ctx, transform);
switch (aImage.imageOrientation) {
case UIImageOrientationLeft:
case UIImageOrientationLeftMirrored:
case UIImageOrientationRight:
case UIImageOrientationRightMirrored:
// Grr...
CGContextDrawImage(ctx, CGRectMake(0,0,aImage.size.height,aImage.size.width), aImage.CGImage);
break;
default:
CGContextDrawImage(ctx, CGRectMake(0,0,aImage.size.width,aImage.size.height), aImage.CGImage);
break;
}
// And now we just create a new UIImage from the drawing context
CGImageRef cgimg = CGBitmapContextCreateImage(ctx);
UIImage *img = [UIImage imageWithCGImage:cgimg];
CGContextRelease(ctx);
CGImageRelease(cgimg);
return img;
}
- (UIImage *)imageWithColor:(UIColor *)color {
CGRect rect = CGRectMake(0.0f, 0.0f, 1.0f, 1.0f);
UIGraphicsBeginImageContext(rect.size);
CGContextRef context = UIGraphicsGetCurrentContext();
CGContextSetFillColorWithColor(context, [color CGColor]);
CGContextFillRect(context, rect);
UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return image;
}
//
- (void)imageWithSize:(CGSize)size radius:(CGFloat)radius backColor:(UIColor *)backColor completion:(void(^)(UIImage *image))completion {
//
dispatch_async(dispatch_get_global_queue(0, 0), ^{
//
UIGraphicsBeginImageContextWithOptions(size, true, 0);
CGRect rect = CGRectMake(0, 0, size.width, size.height);
//
[backColor setFill];
UIRectFill(rect);
// //
// UIBezierPath *path = [UIBezierPath bezierPathWithRoundedRect:rect cornerRadius:radius];
// [path addClip];
// [self drawInRect:rect];
//
UIImage *resultImage = [UIGraphicsGetImageFromCurrentImageContext() circularImage];
//
UIGraphicsEndImageContext();
//
dispatch_async(dispatch_get_main_queue(), ^{
completion(resultImage);
});
});
}
- (UIImage *)circularImage {
// 1.
UIGraphicsBeginImageContextWithOptions(self.size, NO, 0);
// 2.
UIBezierPath *path = [UIBezierPath bezierPathWithRoundedRect:CGRectMake(0, 0, self.size.width, self.size.height) byRoundingCorners:UIRectCornerTopLeft|UIRectCornerTopRight | UIRectCornerBottomLeft | UIRectCornerBottomRight cornerRadii:CGSizeMake(self.size.width, self.size.height)];
// UIBezierPath *path = [UIBezierPath bezierPathWithOvalInRect:CGRectMake(0, 0, self.size.width, self.size.height)];
// 3.
[path addClip];
// 4.
[self drawAtPoint:CGPointZero];
// 5.
UIImage * image = UIGraphicsGetImageFromCurrentImageContext();
// 6.
UIGraphicsEndImageContext();
// 7.
return image;
}
+ (UIImage *)gradientColorImageFromColors:(NSArray<UIColor *> *)colors gradientType:(GradientType)gradientType imgSize:(CGSize)imgSize{
NSMutableArray *ar = [NSMutableArray array];
for(UIColor *c in colors) {
[ar addObject:(id)c.CGColor];
}
UIGraphicsBeginImageContextWithOptions(imgSize, YES, 1);
CGContextRef context = UIGraphicsGetCurrentContext();
CGContextSaveGState(context);
CGColorSpaceRef colorSpace = CGColorGetColorSpace([[colors lastObject] CGColor]);
CGGradientRef gradient = CGGradientCreateWithColors(colorSpace, (CFArrayRef)ar, NULL);
CGPoint start;
CGPoint end;
switch (gradientType) {
case GradientTypeTopToBottom:
start = CGPointMake(0.0, 0.0);
end = CGPointMake(0.0, imgSize.height);
break;
case GradientTypeLeftToRight:
start = CGPointMake(0.0, 0.0);
end = CGPointMake(imgSize.width, 0.0);
break;
case GradientTypeUpleftToLowright:
start = CGPointMake(0.0, 0.0);
end = CGPointMake(imgSize.width, imgSize.height);
break;
case GradientTypeUprightToLowleft:
start = CGPointMake(imgSize.width, 0.0);
end = CGPointMake(0.0, imgSize.height);
break;
default:
break;
}
CGContextDrawLinearGradient(context, gradient, start, end, kCGGradientDrawsBeforeStartLocation | kCGGradientDrawsAfterEndLocation);
UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
CGGradientRelease(gradient);
CGContextRestoreGState(context);
CGColorSpaceRelease(colorSpace);
UIGraphicsEndImageContext();
return image;
}
- (UIImage *)setCornerWithRadius:(CGFloat)radius andSize:(CGSize)size {
//
UIGraphicsBeginImageContext(size);
//
CGRect rect = CGRectMake(0, 0, size.width, size.height);
UIBezierPath *path = [UIBezierPath bezierPathWithRoundedRect:rect byRoundingCorners:UIRectCornerAllCorners cornerRadii:CGSizeMake(radius, radius)];
//Path
CGContextAddPath(UIGraphicsGetCurrentContext(), path.CGPath);
//
CGContextClip(UIGraphicsGetCurrentContext());
//
[self drawInRect:rect];
//
CGContextDrawPath(UIGraphicsGetCurrentContext(), kCGPathStroke);
//
UIImage *output = UIGraphicsGetImageFromCurrentImageContext();
//
UIGraphicsEndImageContext();
//
return output;
}
//
+ (UIImage *)waterImageWithImage:(UIImage *)image waterImage:(UIImage *)waterImage waterImageRect:(CGRect)rect
{
//1.
//2.
UIGraphicsBeginImageContextWithOptions(image.size, NO, 0);
//3.
[image drawInRect:CGRectMake(0, 0, image.size.width, image.size.height)];
//
[waterImage drawInRect:rect];
//4.
UIImage * newImage = UIGraphicsGetImageFromCurrentImageContext();
//5.
UIGraphicsEndImageContext();
//
return newImage;
}
+ (CGSize)sizeWithImageOriginSize:(CGSize)originSize
minSize:(CGSize)imageMinSize
maxSize:(CGSize)imageMaxSiz {
CGSize size;
NSInteger imageWidth = originSize.width ,imageHeight = originSize.height;
NSInteger imageMinWidth = imageMinSize.width, imageMinHeight = imageMinSize.height;
NSInteger imageMaxWidth = imageMaxSiz.width, imageMaxHeight = imageMaxSiz.height;
if (imageWidth > imageHeight) //
{
size.height = imageMinHeight; //
size.width = imageWidth * imageMinHeight / imageHeight;
if (size.width > imageMaxWidth)
{
size.width = imageMaxWidth;
}
}
else if(imageWidth < imageHeight)//
{
size.width = imageMinWidth;
size.height = imageHeight *imageMinWidth / imageWidth;
if (size.height > imageMaxHeight){
size.height = imageMaxHeight;
}
}
else//
{
if (imageWidth > imageMaxWidth){
size.width = imageMaxWidth;
size.height = imageMaxHeight;
}else if(imageWidth > imageMinWidth){
size.width = imageWidth;
size.height = imageHeight;
}else{
size.width = imageMinWidth;
size.height = imageMinHeight;
}
}
return size;
}
- (UIImage *)cutImage:(CGSize)newSize{
CGFloat scale = newSize.height / self.size.height;
UIImage *scaleImage = [self originImage:self scaleToSize:CGSizeMake(self.size.width*scale, self.size.height*scale)];
//
return scaleImage;
}
- (UIImage *)resizeTo:(CGSize)size {
UIGraphicsImageRenderer *renderer = [[UIGraphicsImageRenderer alloc] initWithSize:size];
return [renderer imageWithActions:^(UIGraphicsImageRendererContext * _Nonnull context) {
[self drawInRect:CGRectMake(0, 0, size.width, size.height)];
}];
}
- (UIImage *)cropRightAndBottomPixels:(NSUInteger)pixels {
//
CGSize originalSize = self.size;
//
CGSize newSize = CGSizeMake(originalSize.width - pixels, originalSize.height - pixels);
//
UIGraphicsBeginImageContextWithOptions(newSize, NO, self.scale);
//
[self drawAtPoint:CGPointZero];
//
UIImage *croppedImage = UIGraphicsGetImageFromCurrentImageContext();
//
UIGraphicsEndImageContext();
return croppedImage;
}
- (UIImage*) originImage:(UIImage *)image scaleToSize:(CGSize)size {
UIGraphicsBeginImageContextWithOptions(size, NO, [UIScreen mainScreen].scale);
[image drawInRect:CGRectMake(0, 0, size.width, size.height)];
UIImage* scaledImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return scaledImage;
}
-(UIImage *)compressWithMaxLength:(NSUInteger)maxLength{
// Compress by quality
CGFloat compression = 1;
NSData *data = UIImageJPEGRepresentation(self, compression);
if (data.length < maxLength) return self;
CGFloat max = 1;
CGFloat min = 0;
for (int i = 0; i < 6; ++i) {
compression = (max + min) / 2;
data = UIImageJPEGRepresentation(self, compression);
//NSLog(@"Compression = %.1f", compression);
//NSLog(@"In compressing quality loop, image size = %ld KB", data.length / 1024);
if (data.length < maxLength * 0.9) {
min = compression;
} else if (data.length > maxLength) {
max = compression;
} else {
break;
}
}
//NSLog(@"After compressing quality, image size = %ld KB", data.length / 1024);
if (data.length < maxLength) return self;
UIImage *resultImage = [UIImage imageWithData:data];
// Compress by size
NSUInteger lastDataLength = 0;
while (data.length > maxLength && data.length != lastDataLength) {
lastDataLength = data.length;
CGFloat ratio = (CGFloat)maxLength / data.length;
//NSLog(@"Ratio = %.1f", ratio);
CGSize size = CGSizeMake((NSUInteger)(resultImage.size.width * sqrtf(ratio)),
(NSUInteger)(resultImage.size.height * sqrtf(ratio))); // Use NSUInteger to prevent white blank
UIGraphicsBeginImageContext(size);
[resultImage drawInRect:CGRectMake(0, 0, size.width, size.height)];
resultImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
data = UIImageJPEGRepresentation(resultImage, compression);
//NSLog(@"In compressing size loop, image size = %ld KB", data.length / 1024);
}
if (data) {
return [UIImage imageWithData:data];;
} else {
return self;
}
}
- (UIImage *)roundedImageWithCornerRadius:(CGFloat)cornerRadius size:(CGSize)size{
UIGraphicsBeginImageContextWithOptions(size, NO, 1);
UIBezierPath *clippingPath = [UIBezierPath bezierPathWithRoundedRect:CGRectMake(0, 0, size.width, size.height) cornerRadius:cornerRadius];
[clippingPath addClip];
[self drawInRect:CGRectMake(0, 0, size.width, size.height)];
UIImage *roundedImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return roundedImage;
}
+(UIImage *)getImageFromView:(UIView *)view {
// 1. viewbounds
UIGraphicsBeginImageContextWithOptions(view.bounds.size, view.opaque, 0.0);
// 2.
CGContextRef context = UIGraphicsGetCurrentContext();
// 3. view
[view.layer renderInContext:context];
// 4.
UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
// 5.
UIGraphicsEndImageContext();
// 6.
return image;
}
+ (NSString *)getImageTypeWithImageData:(NSData *)data {
uint8_t c;
[data getBytes:&c length:1];
switch (c) {
case 0xFF:
return @"jpeg";
case 0x89:
return @"png";
case 0x47:
return @"gif";
case 0x49:
case 0x4D:
return @"tiff";
case 0x52:
if ([data length] < 12) {
return nil;
}
NSString *testString = [[NSString alloc] initWithData:[data subdataWithRange:NSMakeRange(0, 12)] encoding:NSASCIIStringEncoding];
if ([testString hasPrefix:@"RIFF"] && [testString hasSuffix:@"WEBP"]) {
return @"webp";
}
return nil;
}
return nil;
}
+(UIImage *)getLanguageImage:(NSString *)image{
NSString *curImage = image;
NSString *language = [NSBundle getLanguageText];
if (isMSZH()) {
//
} else if (isMSTR()) {
image = [NSString stringWithFormat:@"%@_tr", image];
} else if (isMSRTL()) {
image = [NSString stringWithFormat:@"%@_ar", image];
} else {
image = [NSString stringWithFormat:@"%@_en", image];
}
//
UIImage *getImage = kImage(image);
// 使
if (getImage == nil) {
NSString *defaultImageName = [NSString stringWithFormat:@"%@_en", curImage];
getImage = kImage(defaultImageName) ?: kImage(curImage);
}
return getImage;
}
+(NSString *)getLanguageText:(NSString *)image{
NSString *curImage = image;
NSString *language = [NSBundle getLanguageText];
if ([language isEqualToString:@"en"]){
image = [NSString stringWithFormat:@"%@_en",image];
} else if ([language isEqualToString:@"ar"]){
image = [NSString stringWithFormat:@"%@_ar",image];
} else if ([language isEqualToString:@"tr"]) { // 使
image = [NSString stringWithFormat:@"%@_en",image];
}
if (kImage(image) == nil){
return curImage;
}
return image;
}
- (UIImage *)imageByApplyingAlpha:(CGFloat)alpha {
UIGraphicsBeginImageContextWithOptions(self.size, NO, 0.0f);
CGContextRef ctx = UIGraphicsGetCurrentContext();
CGRect area = CGRectMake(0, 0, self.size.width, self.size.height);
CGContextScaleCTM(ctx, 1, -1);
CGContextTranslateCTM(ctx, 0, -area.size.height);
CGContextSetBlendMode(ctx, kCGBlendModeMultiply);
CGContextSetAlpha(ctx, alpha);
CGContextDrawImage(ctx, area, self.CGImage);
UIImage *newImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return newImage;
}
@end