ios CCUIImage.m

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

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

相关推荐

最近更新

  1. docker php8.1+nginx base 镜像 dockerfile 配置

    2024-07-23 06:00:04       133 阅读
  2. Could not load dynamic library ‘cudart64_100.dll‘

    2024-07-23 06:00:04       147 阅读
  3. 在Django里面运行非项目文件

    2024-07-23 06:00:04       123 阅读
  4. Python语言-面向对象

    2024-07-23 06:00:04       133 阅读

热门阅读

  1. unity和安卓的so文件联合使用

    2024-07-23 06:00:04       26 阅读
  2. 智能马桶的工作原理

    2024-07-23 06:00:04       30 阅读
  3. gitlab查询分支API显示不全,只有20个问题

    2024-07-23 06:00:04       21 阅读
  4. Linux Vim教程(四):文本编辑与修改技巧

    2024-07-23 06:00:04       26 阅读
  5. Esxi 上的 CentOS 7.6 系统中搭建本地 Yum 源

    2024-07-23 06:00:04       25 阅读
  6. Android 多用户问题

    2024-07-23 06:00:04       30 阅读
  7. QT 4.8版本的Ubuntu2004编译错误的解决方案

    2024-07-23 06:00:04       22 阅读
  8. 算法1--双指针

    2024-07-23 06:00:04       26 阅读
  9. C++实现排序算法

    2024-07-23 06:00:04       26 阅读
  10. 微信小程序面试题汇总

    2024-07-23 06:00:04       24 阅读