ios CCUIImage.m

objectivec 复制代码
//
//  CCUIImage.h
//  CCFC_IPHONE
//
//


#ifndef CC_UI_IMAGE_H
#define CC_UI_IMAGE_H




#ifdef __OBJC__


#import "CCConfig.h"


#define CREATE_UIIMAGE(imgPath)         [UIImage imageNamed:(imgPath)]
#define CREATE_UIIMAGEVIEW(imgPath)     [[[UIImageView alloc] initWithImage:CREATE_UIIMAGE(imgPath)] autorelease]


#define MACRO_DEFAULT_NAVIGATION_BARBUTTON_ITEM_ICON_WIDTH              20
#define MACRO_DEFAULT_NAVIGATION_BARBUTTON_ITEM_ICON_HEIGHT             20


#if CC_ENABLE_PRIVATE_API && CC_COMPILE_PRIVATE_CLASS
#ifdef  __cplusplus
extern "C" {
#endif
        
 CGImageRef UIGetScreenImage();
        
#ifdef  __cplusplus
}
#endif
#endif


@interface UIImage(cc)


// returns the scaled image
- (UIImage *)scale:(float)scaleSize;


// resize the img to indicated newSize
- (UIImage *)resizeImage:(CGSize)newSize;


// save PNG file to path
- (BOOL)savePNGToPath:(NSString *)fileFullPath;


// save the img to photos album
- (void)saveImgToPhotosAlbum;


// get part of the image
- (UIImage *)getPartOfImage:(CGRect)partRect;


// returns UIImage * from text
+ (UIImage *)imageFromText:(NSString *)text font:(UIFont *)font;




#if CC_ENABLE_PRIVATE_API && CC_COMPILE_PRIVATE_CLASS
+ (UIImage *)getFullScreenImg;
#endif


@end




#endif  // __OBJC__
#endif  // CC_UI_IMAGE_H
cpp 复制代码
//
//  CCUIImage.m
//  CCFC
//
//






@implementation UIImage(cc)


// returns the scaled image
- (UIImage *)scale:(float)scaleSize
{
        
        UIGraphicsBeginImageContext(
                        CGSizeMake(self.size.width * scaleSize, self.size.height * scaleSize));
        [self drawInRect:CGRectMake(0, 0, self.size.width * scaleSize, self.size.height * scaleSize)];
        UIImage *scaledImage = UIGraphicsGetImageFromCurrentImageContext();
        UIGraphicsEndImageContext();
                                                                
        return scaledImage;
}


// resize the img to indicated newSize
- (UIImage *)resizeImage:(CGSize)newSize
{
        UIGraphicsBeginImageContext(CGSizeMake(newSize.width, newSize.height));
        [self drawInRect:CGRectMake(0, 0, newSize.width, newSize.height)];
        UIImage *resizeImage = UIGraphicsGetImageFromCurrentImageContext();
        UIGraphicsEndImageContext();


        return resizeImage;
        
}


// save PNG file to path
- (BOOL)savePNGToPath:(NSString *)fileFullPath
{
        return [UIImagePNGRepresentation(self) writeToFile:fileFullPath atomically:YES];
}


// save the img to photos album
- (void)saveImgToPhotosAlbum
{
        UIImageWriteToSavedPhotosAlbum(self, nil, nil, nil);
}


// get part of the image
- (UIImage *)getPartOfImage:(CGRect)partRect
{
        CGImageRef imageRef = self.CGImage;
        CGImageRef imagePartRef = CGImageCreateWithImageInRect(imageRef, partRect);
        return [UIImage imageWithCGImage:imagePartRef];
}


// returns UIImage * from text
+ (UIImage *)imageFromText:(NSString *)text font:(UIFont *)font
{            
        CGSize size  = [text sizeWithFont:font];     
        UIGraphicsBeginImageContext(size);  
        
        CGContextRef ctx = UIGraphicsGetCurrentContext();       
        [text drawAtPoint:CGPointMake(0, 0) withFont:font];      
        UIImage *image = UIGraphicsGetImageFromCurrentImageContext();          
        UIGraphicsEndImageContext(); 
        CGContextRelease(ctx);
        
        return image;  
} 


#if CC_ENABLE_PRIVATE_API && CC_COMPILE_PRIVATE_CLASS
+ (UIImage *)getFullScreenImg
{
        CGImageRef screenImg = UIGetScreenImage();
        return [UIImage imageWithCGImage:screenImg];
}
#endif


@end

微风不燥,阳光正好,你就像风一样经过这里,愿你停留的片刻温暖舒心。

我是程序员小迷(致力于C、C++、Java、Kotlin、Android、iOS、Shell、JavaScript、TypeScript、Python等编程技术的技巧经验分享),若作品对您有帮助,请关注、分享、点赞、收藏、在看、喜欢,您的支持是我们为您提供帮助的最大动力。

欢迎关注。助您在编程路上越走越好!

相关推荐
Cedric_Anik12 小时前
iOS App的启动与优化
ios
leluckys1 天前
iOS之动态库和静态库的区别
ios
Black_Rock_br1 天前
iPhone 智能进化:Siri 调用 DeepSeek 大模型
ios·语言模型·iphone
猪萌萌1 天前
使用iOS个人声音与SoVITS训练个人AI语音(10分钟快速上手)
人工智能·ios·tts·文字转语音·sovits
二流小码农1 天前
鸿蒙开发:V2版本装饰器@Once
android·ios·harmonyos
bdawn1 天前
深度集成DeepSeek大模型:WebSocket流式聊天实现
python·websocket·openai·api·实时聊天·deepseek大模型·流式输出
Johnny Tong2 天前
iOS 获取设备占用内存
ios·内存·host_vm
木兰不吃草2 天前
如何在 Mac 上下载安装仙剑游戏仙剑世界?可以通过IPA砸壳包安装非常简单
游戏·macos·ios·游戏程序·mac
帅次2 天前
Flutter 异步编程利器:Future 与 Stream 深度解析
android·flutter·ios·小程序·kotlin·webview·android-studio
小鹿撞出了脑震荡2 天前
Effective Objective-C 2.0 读书笔记——大中枢派发
开发语言·ios·objective-c