Hi everyone,
I'm trying to draw a PNG file to my iPhone screen and, although I've managed, the results are a little confusing..
Here is some code;
So far, so basic.
The problem I have is that I get "<Error>: CGContextDrawImage: invalid context" whenever I try and call reDraw a second time.
The image is displayed when the app starts, if I call the reDraw function again then I get the error.
My other issue is that the image is flipped and mirrored, but that looks easily fixable compared to the error message.
Any ideas?? Thanks, Kevin
I'm trying to draw a PNG file to my iPhone screen and, although I've managed, the results are a little confusing..
Here is some code;
Code:
- (void)drawRect:(CGRect)rect {
[self reDraw];
}
- (void)reDraw {
CGContextRef cgContext = UIGraphicsGetCurrentContext();
CGImageRef imageRef = [[UIImage imageNamed:[self getImgFilename] ] CGImage];
CGRect frame = [self bounds];
CGContextDrawImage(cgContext, frame, imageRef);
NSLog([self getImgFilename]);
}
- (NSMutableString *)getImgFilename {
NSMutableString *newImage;
if (state=1)
{
newImage = [NSMutableString stringWithString:@"image1.png"];
}
else if (state=2)
{
newImage = [NSMutableString stringWithString:@"image2.png"];
}
return newImage;
}
So far, so basic.
The problem I have is that I get "<Error>: CGContextDrawImage: invalid context" whenever I try and call reDraw a second time.
The image is displayed when the app starts, if I call the reDraw function again then I get the error.
My other issue is that the image is flipped and mirrored, but that looks easily fixable compared to the error message.
Any ideas?? Thanks, Kevin