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等编程技术的技巧经验分享),若作品对您有帮助,请关注、分享、点赞、收藏、在看、喜欢,您的支持是我们为您提供帮助的最大动力。

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

相关推荐
2401_8658548813 小时前
iOS应用想要下载到手机上只能苹果签名吗?
后端·ios·iphone
HackerTom1 天前
iOS用rime且导入自制输入方案
ios·iphone·rime
良技漫谈1 天前
Rust移动开发:Rust在iOS端集成使用介绍
后端·程序人生·ios·rust·objective-c·swift
2401_852403551 天前
高效管理iPhone存储:苹果手机怎么删除相似照片
ios·智能手机·iphone
星际码仔2 天前
【动画图解】是怎样的方法,能被称作是 Flutter Widget 系统的核心?
android·flutter·ios
emperinter2 天前
WordCloudStudio:AI生成模版为您的文字云创意赋能 !
图像处理·人工智能·macos·ios·信息可视化·iphone
关键帧Keyframe2 天前
音视频面试题集锦第 8 期
ios·音视频开发·客户端
pb82 天前
引入最新fluwx2.5.4的时候报错
flutter·ios
一名技术极客2 天前
后端开挂:3 行代码写出 8 个接口!
java·api·apijson
Tassel_YUE2 天前
网络自动化03:简单解释send_config_set方法并举例
网络·自动化·cocoa