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

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

相关推荐
恋猫de小郭8 小时前
什么?Flutter 可能会被 SwiftUI/ArkUI 化?全新的 Flutter Roadmap
flutter·ios·swiftui
网安墨雨12 小时前
iOS应用网络安全之HTTPS
web安全·ios·https
福大大架构师每日一题14 小时前
37.1 prometheus管理接口源码讲解
ios·iphone·prometheus
Json_1817901448018 小时前
淘系商品评论json数据示例参考,API接口系列
大数据·json·api
BangRaJun1 天前
LNCollectionView-替换幂率流体
算法·ios·设计
刘小哈哈哈1 天前
iOS 多个输入框弹出键盘处理
macos·ios·cocoa
靴子学长1 天前
iOS + watchOS Tourism App(含源码可简单复现)
mysql·ios·swiftui
北京_宏哥2 天前
python接口自动化(三十五)-封装与调用--流程类接口关联(详解)
前端·python·api
一如初夏丿2 天前
xcode15 报错 does not contain ‘libarclite‘
ios·xcode
杨武博2 天前
ios 混合开发应用白屏问题
ios