//
//  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

 

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

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

点赞(0) 打赏

评论列表 共有 0 条评论

暂无评论

微信公众账号

微信扫一扫加关注

发表
评论
返回
顶部