摘自https://developer.apple.com/library/ios/qa/qa1704/_index.html
Q: How do I take a snapshot of my OpenGL ES view and save the result in a UIImage?
// IMPORTANT: Call this method after you draw and before -presentRenderbuffer:.
- (UIImage*)snapshot:(UIView*)eaglview
{
GLint backingWidth, backingHeight;
// Bind the color renderbuffer used to render the OpenGL ES view
// If your application only creates a single color renderbuffer which is already bound at this point,
// this call is redundant, but it is needed if you're dealing with multiple renderbuffers.
// Note, replace "_colorRenderbuffer" with the actual name of the renderbuffer object defined in your class.
glBindRenderbufferOES(GL_RENDERBUFFER_OES, _colorRenderbuffer);
// Get the size of the backing CAEAGLLayer
glGetRenderbufferParameterivOES(GL_RENDERBUFFER_OES, GL_RENDERBUFFER_WIDTH_OES, &backingWidth);
glGetRenderbufferParameterivOES(GL_RENDERBUFFER_OES, GL_RENDERBUFFER_HEIGHT_OES, &backingHeight);
NSInteger x = 0, y = 0, width = backingWidth, height = backingHeight;
NSInteger dataLength = width * height * 4;
GLubyte *data = (GLubyte*)malloc(dataLength * sizeof(GLubyte));
// Read pixel data from the framebuffer
glPixelStorei(GL_PACK_ALIGNMENT, 4);
glReadPixels(x, y, width, height, GL_RGBA, GL_UNSIGNED_BYTE, data);
// Create a CGImage with the pixel data
// If your OpenGL ES content is opaque, use kCGImageAlphaNoneSkipLast to ignore the alpha channel
// otherwise, use kCGImageAlphaPremultipliedLast
CGDataProviderRef ref = CGDataProviderCreateWithData(NULL, data, dataLength, NULL);
CGColorSpaceRef colorspace = CGColorSpaceCreateDeviceRGB();
CGImageRef iref = CGImageCreate(width, height, 8, 32, width * 4, colorspace, kCGBitmapByteOrder32Big | kCGImageAlphaPremultipliedLast,
ref, NULL, true, kCGRenderingIntentDefault);
// OpenGL ES measures data in PIXELS
// Create a graphics context with the target size measured in POINTS
NSInteger widthInPoints, heightInPoints;
if (NULL != UIGraphicsBeginImageContextWithOptions) {
// On iOS 4 and later, use UIGraphicsBeginImageContextWithOptions to take the scale into consideration
// Set the scale parameter to your OpenGL ES view's contentScaleFactor
// so that you get a high-resolution snapshot when its value is greater than 1.0
CGFloat scale = eaglview.contentScaleFactor;
widthInPoints = width / scale;
heightInPoints = height / scale;
UIGraphicsBeginImageContextWithOptions(CGSizeMake(widthInPoints, heightInPoints), NO, scale);
}
else {
// On iOS prior to 4, fall back to use UIGraphicsBeginImageContext
widthInPoints = width;
heightInPoints = height;
UIGraphicsBeginImageContext(CGSizeMake(widthInPoints, heightInPoints));
}
CGContextRef cgcontext = UIGraphicsGetCurrentContext();
// UIKit coordinate system is upside down to GL/Quartz coordinate system
// Flip the CGImage by rendering it to the flipped bitmap context
// The size of the destination area is measured in POINTS
CGContextSetBlendMode(cgcontext, kCGBlendModeCopy);
CGContextDrawImage(cgcontext, CGRectMake(0.0, 0.0, widthInPoints, heightInPoints), iref);
// Retrieve the UIImage from the current context
UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
// Clean up
free(data);
CFRelease(ref);
CFRelease(colorspace);
CGImageRelease(iref);
return image;
}
2013年9月10日 星期二
2013年9月6日 星期五
在NSDictionary中讀取和寫入CGRect
//讀取
CGRect newFrame = [[change objectForKey:@"new"]CGRectValue];
//寫入
CGRect newFrame = [[change objectForKey:@"new"]CGRectValue];
//寫入
dictionary = [NSDictionary dictionaryWithObjectsAndKeys:
[NSValue valueWithCGRect:CGRectMake(100,100,200,200)],
@"Crocodile",
nil];
2013年9月5日 星期四
objective-C中列舉(enum)的使用
第一種是原始的用法
.h檔
#import <Foundation/Foundation.h>
enum HHSlidaleViewModes{
slideFromLeftToRight = 0,
slideFromRightToLeft,
rightSideFromCenter,
leftSideFromCenter
};
@interface SlidableView : NSObject{
enum HHSlidaleViewModes a;
}
.m檔
#import "SlidableView.h"
@implementation SlidableView
-(void)a{
a = slideFromLeftToRight;
}
@end
第二種是通用的用法
首先,我們要先知道typedef是把型別名稱取一個別名
例如typedef int handsomeInt;
之後就可以宣告整數為 handsomeInt a = 100;
之後,我們就可以把上面的code改為:
.h檔
#import <Foundation/Foundation.h>
typedef enum HHSlidaleViewModes{
slideFromLeftToRight = 0,
slideFromRightToLeft,
rightSideFromCenter,
leftSideFromCenter
} hhSlidableViewModes;
@interface SlidableView : NSObject{
hhSlidaleViewModes a;
}
.m檔
#import "SlidableView.h"
@implementation SlidableView
-(void)a{
a = slideFromLeftToRight;
}
@end
//我自己的用法,利用typedef把後面的enum{running = 0,sleeping,header}改名為StepMode來使用
.h檔
#import <Foundation/Foundation.h>
enum HHSlidaleViewModes{
slideFromLeftToRight = 0,
slideFromRightToLeft,
rightSideFromCenter,
leftSideFromCenter
};
@interface SlidableView : NSObject{
enum HHSlidaleViewModes a;
}
.m檔
#import "SlidableView.h"
@implementation SlidableView
-(void)a{
a = slideFromLeftToRight;
}
@end
第二種是通用的用法
首先,我們要先知道typedef是把型別名稱取一個別名
例如typedef int handsomeInt;
之後就可以宣告整數為 handsomeInt a = 100;
之後,我們就可以把上面的code改為:
.h檔
#import <Foundation/Foundation.h>
typedef enum HHSlidaleViewModes{
slideFromLeftToRight = 0,
slideFromRightToLeft,
rightSideFromCenter,
leftSideFromCenter
} hhSlidableViewModes;
@interface SlidableView : NSObject{
hhSlidaleViewModes a;
}
.m檔
#import "SlidableView.h"
@implementation SlidableView
-(void)a{
a = slideFromLeftToRight;
}
@end
//我自己的用法,利用typedef把後面的enum{running = 0,sleeping,header}改名為StepMode來使用
typedef enum{
running = 0,
sleeping,
header
}StepMode;
2013年9月4日 星期三
@selector傳遞參數
//呼叫不用參數的method
[self performSelector:@selector(fooNoInputs)];
//呼叫一個參數的method
[self performSelector:@selector(fooOneInput:) withObject:@"first"];
//呼叫二個參數的method
[self performSelector:@selector(fooFirstInput:secondInput:) withObject:@"first" withObject:@"second"];
刮刮樂的可刮部份
//
// ScratchableView.h
// CGScratch
//
// Created by Olivier Yiptong on 11-01-11.
// Copyright 2011 __MyCompanyName__. All rights reserved.
//
#import <UIKit/UIKit.h>
@interface ScratchableView : UIView {
float width;
float height;
CGPoint location;
CGPoint previousLocation;
BOOL firstTouch;
CGImageRef scratchable;
CGImageRef scratched;
CGContextRef alphaPixels;
CGDataProviderRef provider;
}
- (void) renderLineFromPoint:(CGPoint)start toPoint:(CGPoint)end;
@end
//
// ScratchableView.m
// CGScratch
//
// Created by Olivier Yiptong on 11-01-11.
// Copyright 2011 __MyCompanyName__. All rights reserved.
//
#import "ScratchableView.h"
@implementation ScratchableView
- (id)initWithFrame:(CGRect)frame {
self = [super initWithFrame:frame];
if (self) {
//self.bounds = CGRectMake(0.0, 0.0, frame.size.width, frame.size.height);
//自行把用來刮的scratch.png放入專案
scratchable = [UIImage imageNamed:@"scratch.png"].CGImage;
//修改成隨bounds大小變化 by Harvey 20130903
// width = CGImageGetWidth(scratchable);
// height = CGImageGetHeight(scratchable);
width = self.bounds.size.width;
height = self.bounds.size.height;
self.opaque = NO;
CGColorSpaceRef colorspace = CGColorSpaceCreateDeviceGray();
CFMutableDataRef pixels = CFDataCreateMutable( NULL , width * height );
alphaPixels = CGBitmapContextCreate( CFDataGetMutableBytePtr( pixels ) , width , height , 8 , width , colorspace , kCGImageAlphaNone );
provider = CGDataProviderCreateWithCFData(pixels);
CGContextSetFillColorWithColor(alphaPixels, [UIColor blackColor].CGColor);
CGContextFillRect(alphaPixels, frame);
CGContextSetStrokeColorWithColor(alphaPixels, [UIColor whiteColor].CGColor);
CGContextSetLineWidth(alphaPixels, 20.0);
CGContextSetLineCap(alphaPixels, kCGLineCapRound);
//CGImageRef mask = CGImageMaskCreate(width, height, 8, 8, width, provider, nil, NO);
CGImageRef mask = CGImageMaskCreate(width, height, 8, 8, width, provider, nil, NO);
scratched = CGImageCreateWithMask(scratchable, mask);
CGImageRelease(mask);
CGColorSpaceRelease(colorspace);
}
return self;
}
- (void)drawRect:(CGRect)rect {
CGContextDrawImage(UIGraphicsGetCurrentContext() , [self bounds] , scratched);
}
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
UITouch *touch = [[event touchesForView:self] anyObject];
firstTouch = YES;
location = [touch locationInView:self];
}
- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event
{
UITouch *touch = [[event touchesForView:self] anyObject];
if (firstTouch) {
firstTouch = NO;
previousLocation = [touch previousLocationInView:self];
} else {
location = [touch locationInView:self];
previousLocation = [touch previousLocationInView:self];
}
// Render the stroke
[self renderLineFromPoint:previousLocation toPoint:location];
}
- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event
{
UITouch *touch = [[event touchesForView:self] anyObject];
if (firstTouch) {
firstTouch = NO;
previousLocation = [touch previousLocationInView:self];
[self renderLineFromPoint:previousLocation toPoint:location];
}
}
- (void)touchesCancelled:(NSSet *)touches withEvent:(UIEvent *)event
{
}
- (void) renderLineFromPoint:(CGPoint)start toPoint:(CGPoint)end {
CGContextMoveToPoint(alphaPixels, start.x , start.y );
CGContextAddLineToPoint(alphaPixels, end.x , end.y );
CGContextStrokePath(alphaPixels);
[self setNeedsDisplay];
}
- (void)dealloc {
CGContextRelease(alphaPixels);
CGImageRelease(scratchable);
CGDataProviderRelease(provider);
[super dealloc];
}
@end
// ScratchableView.h
// CGScratch
//
// Created by Olivier Yiptong on 11-01-11.
// Copyright 2011 __MyCompanyName__. All rights reserved.
//
#import <UIKit/UIKit.h>
@interface ScratchableView : UIView {
float width;
float height;
CGPoint location;
CGPoint previousLocation;
BOOL firstTouch;
CGImageRef scratchable;
CGImageRef scratched;
CGContextRef alphaPixels;
CGDataProviderRef provider;
}
- (void) renderLineFromPoint:(CGPoint)start toPoint:(CGPoint)end;
@end
//
// ScratchableView.m
// CGScratch
//
// Created by Olivier Yiptong on 11-01-11.
// Copyright 2011 __MyCompanyName__. All rights reserved.
//
#import "ScratchableView.h"
@implementation ScratchableView
- (id)initWithFrame:(CGRect)frame {
self = [super initWithFrame:frame];
if (self) {
//self.bounds = CGRectMake(0.0, 0.0, frame.size.width, frame.size.height);
//自行把用來刮的scratch.png放入專案
scratchable = [UIImage imageNamed:@"scratch.png"].CGImage;
//修改成隨bounds大小變化 by Harvey 20130903
// width = CGImageGetWidth(scratchable);
// height = CGImageGetHeight(scratchable);
width = self.bounds.size.width;
height = self.bounds.size.height;
self.opaque = NO;
CGColorSpaceRef colorspace = CGColorSpaceCreateDeviceGray();
CFMutableDataRef pixels = CFDataCreateMutable( NULL , width * height );
alphaPixels = CGBitmapContextCreate( CFDataGetMutableBytePtr( pixels ) , width , height , 8 , width , colorspace , kCGImageAlphaNone );
provider = CGDataProviderCreateWithCFData(pixels);
CGContextSetFillColorWithColor(alphaPixels, [UIColor blackColor].CGColor);
CGContextFillRect(alphaPixels, frame);
CGContextSetStrokeColorWithColor(alphaPixels, [UIColor whiteColor].CGColor);
CGContextSetLineWidth(alphaPixels, 20.0);
CGContextSetLineCap(alphaPixels, kCGLineCapRound);
//CGImageRef mask = CGImageMaskCreate(width, height, 8, 8, width, provider, nil, NO);
CGImageRef mask = CGImageMaskCreate(width, height, 8, 8, width, provider, nil, NO);
scratched = CGImageCreateWithMask(scratchable, mask);
CGImageRelease(mask);
CGColorSpaceRelease(colorspace);
}
return self;
}
- (void)drawRect:(CGRect)rect {
CGContextDrawImage(UIGraphicsGetCurrentContext() , [self bounds] , scratched);
}
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
UITouch *touch = [[event touchesForView:self] anyObject];
firstTouch = YES;
location = [touch locationInView:self];
}
- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event
{
UITouch *touch = [[event touchesForView:self] anyObject];
if (firstTouch) {
firstTouch = NO;
previousLocation = [touch previousLocationInView:self];
} else {
location = [touch locationInView:self];
previousLocation = [touch previousLocationInView:self];
}
// Render the stroke
[self renderLineFromPoint:previousLocation toPoint:location];
}
- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event
{
UITouch *touch = [[event touchesForView:self] anyObject];
if (firstTouch) {
firstTouch = NO;
previousLocation = [touch previousLocationInView:self];
[self renderLineFromPoint:previousLocation toPoint:location];
}
}
- (void)touchesCancelled:(NSSet *)touches withEvent:(UIEvent *)event
{
}
- (void) renderLineFromPoint:(CGPoint)start toPoint:(CGPoint)end {
CGContextMoveToPoint(alphaPixels, start.x , start.y );
CGContextAddLineToPoint(alphaPixels, end.x , end.y );
CGContextStrokePath(alphaPixels);
[self setNeedsDisplay];
}
- (void)dealloc {
CGContextRelease(alphaPixels);
CGImageRelease(scratchable);
CGDataProviderRelease(provider);
[super dealloc];
}
@end
NSZombieEnabled on Xcode 4.0(and up)
NSZombieEnabled只能在develop時使用,千萬別忘了在distrube時移掉,因為NSZombieEnabled不會真正釋放dealloc時的記憶體!
2013年9月2日 星期一
使用drawRect繪圖
引用自http://blog.csdn.net/zhibudefeng/article/details/8463268
- // Only override drawRect: if you perform custom drawing.
- // An empty implementation adversely affects performance during animation.
- - (void)drawRect:(CGRect)rect
- {
- CGContextRef context = UIGraphicsGetCurrentContext();
- /*NO.1画一条线
- CGContextSetRGBStrokeColor(context, 0.5, 0.5, 0.5, 0.5);//线条颜色
- CGContextMoveToPoint(context, 20, 20);
- CGContextAddLineToPoint(context, 200,20);
- CGContextStrokePath(context);
- */
- /*NO.2写文字
- CGContextSetLineWidth(context, 1.0);
- CGContextSetRGBFillColor (context, 0.5, 0.5, 0.5, 0.5);
- UIFont *font = [UIFont boldSystemFontOfSize:18.0];
- [@"公司:北京中软科技股份有限公司\n部门:ERP事业部\n姓名:McLiang" drawInRect:CGRectMake(20, 40, 280, 300) withFont:font];
- */
- /*NO.3画一个正方形图形 没有边框
- CGContextSetRGBFillColor(context, 0, 0.25, 0, 0.5);
- CGContextFillRect(context, CGRectMake(2, 2, 270, 270));
- CGContextStrokePath(context);
- */
- /*NO.4画正方形边框
- CGContextSetRGBStrokeColor(context, 0.5, 0.5, 0.5, 0.5);//线条颜色
- CGContextSetLineWidth(context, 2.0);
- CGContextAddRect(context, CGRectMake(2, 2, 270, 270));
- CGContextStrokePath(context);
- */
- /*NO.5画方形背景颜色
- CGContextTranslateCTM(context, 0.0f, self.bounds.size.height);
- CGContextScaleCTM(context, 1.0f, -1.0f);
- UIGraphicsPushContext(context);
- CGContextSetLineWidth(context,320);
- CGContextSetRGBStrokeColor(context, 250.0/255, 250.0/255, 210.0/255, 1.0);
- CGContextStrokeRect(context, CGRectMake(0, 0, 320, 460));
- UIGraphicsPopContext();
- */
- /*NO.6椭圆
- CGRect aRect= CGRectMake(80, 80, 160, 100);
- CGContextSetRGBStrokeColor(context, 0.6, 0.9, 0, 1.0);
- CGContextSetLineWidth(context, 3.0);
- CGContextAddEllipseInRect(context, aRect); //椭圆
- CGContextDrawPath(context, kCGPathStroke);
- */
- /*NO.7
- CGContextBeginPath(context);
- CGContextSetRGBStrokeColor(context, 0, 0, 1, 1);
- CGContextMoveToPoint(context, 100, 100);
- CGContextAddArcToPoint(context, 50, 100, 50, 150, 50);
- CGContextStrokePath(context);
- */
- /*NO.8渐变
- CGContextClip(context);
- CGColorSpaceRef rgb = CGColorSpaceCreateDeviceRGB();
- CGFloat colors[] =
- {
- 204.0 / 255.0, 224.0 / 255.0, 244.0 / 255.0, 1.00,
- 29.0 / 255.0, 156.0 / 255.0, 215.0 / 255.0, 1.00,
- 0.0 / 255.0, 50.0 / 255.0, 126.0 / 255.0, 1.00,
- };
- CGGradientRef gradient = CGGradientCreateWithColorComponents
- (rgb, colors, NULL, sizeof(colors)/(sizeof(colors[0])*4));
- CGColorSpaceRelease(rgb);
- CGContextDrawLinearGradient(context, gradient,CGPointMake
- (0.0,0.0) ,CGPointMake(0.0,self.frame.size.height),
- kCGGradientDrawsBeforeStartLocation);
- */
- /* NO.9四条线画一个正方形
- //画线
- UIColor *aColor = [UIColor colorWithRed:0 green:1.0 blue:0 alpha:0];
- CGContextSetRGBStrokeColor(context, 1.0, 0, 0, 1.0);
- CGContextSetFillColorWithColor(context, aColor.CGColor);
- CGContextSetLineWidth(context, 4.0);
- CGPoint aPoints[5];
- aPoints[0] =CGPointMake(60, 60);
- aPoints[1] =CGPointMake(260, 60);
- aPoints[2] =CGPointMake(260, 300);
- aPoints[3] =CGPointMake(60, 300);
- aPoints[4] =CGPointMake(60, 60);
- CGContextAddLines(context, aPoints, 5);
- CGContextDrawPath(context, kCGPathStroke); //开始画线
- */
- /* NO.10
- UIColor *aColor = [UIColor colorWithRed:0 green:1.0 blue:0 alpha:0];
- CGContextSetRGBStrokeColor(context, 1.0, 0, 0, 1.0);
- CGContextSetFillColorWithColor(context, aColor.CGColor);
- //椭圆
- CGRect aRect= CGRectMake(80, 80, 160, 100);
- CGContextSetRGBStrokeColor(context, 0.6, 0.9, 0, 1.0);
- CGContextSetLineWidth(context, 3.0);
- CGContextSetFillColorWithColor(context, aColor.CGColor);
- CGContextAddRect(context, rect); //矩形
- CGContextAddEllipseInRect(context, aRect); //椭圆
- CGContextDrawPath(context, kCGPathStroke);
- */
- /* NO.11
- 画一个实心的圆
- CGContextFillEllipseInRect(context, CGRectMake(95, 95, 100.0, 100));
- */
- /*NO.12
- 画一个菱形
- CGContextSetLineWidth(context, 2.0);
- CGContextSetStrokeColorWithColor(context, [UIColor blueColor].CGColor);
- CGContextMoveToPoint(context, 100, 100);
- CGContextAddLineToPoint(context, 150, 150);
- CGContextAddLineToPoint(context, 100, 200);
- CGContextAddLineToPoint(context, 50, 150);
- CGContextAddLineToPoint(context, 100, 100);
- CGContextStrokePath(context);
- */
- /*NO.13 画矩形
- CGContextSetLineWidth(context, 2.0);
- CGContextSetStrokeColorWithColor(context, [UIColor blueColor].CGColor);
- CGRect rectangle = CGRectMake(60,170,200,80);
- CGContextAddRect(context, rectangle);
- CGContextStrokePath(context);
- */
- /*椭圆
- CGContextSetLineWidth(context, 2.0);
- CGContextSetStrokeColorWithColor(context, [UIColor blueColor].CGColor);
- CGRect rectangle = CGRectMake(60,170,200,80);
- CGContextAddEllipseInRect(context, rectangle);
- CGContextStrokePath(context);
- */
- /*用红色填充了一段路径:
- CGContextMoveToPoint(context, 100, 100);
- CGContextAddLineToPoint(context, 150, 150);
- CGContextAddLineToPoint(context, 100, 200);
- CGContextAddLineToPoint(context, 50, 150);
- CGContextAddLineToPoint(context, 100, 100);
- CGContextSetFillColorWithColor(context, [UIColor redColor].CGColor);
- CGContextFillPath(context);
- */
- /*填充一个蓝色边的红色矩形
- CGContextSetLineWidth(context, 2.0);
- CGContextSetStrokeColorWithColor(context, [UIColor blueColor].CGColor);
- CGRect rectangle = CGRectMake(60,170,200,80);
- CGContextAddRect(context, rectangle);
- CGContextStrokePath(context);
- CGContextSetFillColorWithColor(context, [UIColor redColor].CGColor);
- CGContextFillRect(context, rectangle);
- */
- /*画弧
- //弧线的是通过指定两个切点,还有角度,调用CGContextAddArcToPoint()绘制
- CGContextSetLineWidth(context, 2.0);
- CGContextSetStrokeColorWithColor(context, [UIColor blueColor].CGColor);
- CGContextMoveToPoint(context, 100, 100);
- CGContextAddArcToPoint(context, 100,200, 300,200, 100);
- CGContextStrokePath(context);
- */
- /*
- 绘制贝兹曲线
- //贝兹曲线是通过移动一个起始点,然后通过两个控制点,还有一个中止点,调用CGContextAddCurveToPoint() 函数绘制
- CGContextSetLineWidth(context, 2.0);
- CGContextSetStrokeColorWithColor(context, [UIColor blueColor].CGColor);
- CGContextMoveToPoint(context, 10, 10);
- CGContextAddCurveToPoint(context, 0, 50, 300, 250, 300, 400);
- CGContextStrokePath(context);
- */
- /*绘制二次贝兹曲线
- CGContextSetLineWidth(context, 2.0);
- CGContextSetStrokeColorWithColor(context, [UIColor blueColor].CGColor);
- CGContextMoveToPoint(context, 10, 200);
- CGContextAddQuadCurveToPoint(context, 150, 10, 300, 200);
- CGContextStrokePath(context);
- */
- /*绘制虚线
- CGContextSetLineWidth(context, 5.0);
- CGContextSetStrokeColorWithColor(context, [UIColor blueColor].CGColor);
- CGFloat dashArray[] = {2,6,4,2};
- CGContextSetLineDash(context, 3, dashArray, 4);//跳过3个再画虚线,所以刚开始有6-(3-2)=5个虚点
- CGContextMoveToPoint(context, 10, 200);
- CGContextAddQuadCurveToPoint(context, 150, 10, 300, 200);
- CGContextStrokePath(context);
- */
- /*绘制图片
- NSString* imagePath = [[NSBundle mainBundle] pathForResource:@"dog" ofType:@"png"];
- UIImage* myImageObj = [[UIImage alloc] initWithContentsOfFile:imagePath];
- //[myImageObj drawAtPoint:CGPointMake(0, 0)];
- [myImageObj drawInRect:CGRectMake(0, 0, 320, 480)];
- NSString *s = @"我的小狗";
- [s drawAtPoint:CGPointMake(100, 0) withFont:[UIFont systemFontOfSize:34.0]];
- */
- /*
- NSString *path = [[NSBundle mainBundle] pathForResource:@"dog" ofType:@"png"];
- UIImage *img = [UIImage imageWithContentsOfFile:path];
- CGImageRef image = img.CGImage;
- CGContextSaveGState(context);
- CGRect touchRect = CGRectMake(0, 0, img.size.width, img.size.height);
- CGContextDrawImage(context, touchRect, image);
- CGContextRestoreGState(context);
- */
- /*NSString *path = [[NSBundle mainBundle] pathForResource:@"dog" ofType:@"png"];
- UIImage *img = [UIImage imageWithContentsOfFile:path];
- CGImageRef image = img.CGImage;
- CGContextSaveGState(context);
- CGContextRotateCTM(context, M_PI);
- CGContextTranslateCTM(context, -img.size.width, -img.size.height);
- CGRect touchRect = CGRectMake(0, 0, img.size.width, img.size.height);
- CGContextDrawImage(context, touchRect, image);
- CGContextRestoreGState(context);*/
- /*
- NSString *path = [[NSBundle mainBundle] pathForResource:@"dog" ofType:@"png"];
- UIImage *img = [UIImage imageWithContentsOfFile:path];
- CGImageRef image = img.CGImage;
- CGContextSaveGState(context);
- CGAffineTransform myAffine = CGAffineTransformMakeRotation(M_PI);
- myAffine = CGAffineTransformTranslate(myAffine, -img.size.width, -img.size.height);
- CGContextConcatCTM(context, myAffine);
- CGContextRotateCTM(context, M_PI);
- CGContextTranslateCTM(context, -img.size.width, -img.size.height);
- CGRect touchRect = CGRectMake(0, 0, img.size.width, img.size.height);
- CGContextDrawImage(context, touchRect, image);
- CGContextRestoreGState(context);
- */
- }
訂閱:
文章 (Atom)