Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

rand0m3r

macrumors regular
Original poster
Jun 30, 2006
115
1
hi. i've got the following code in my drawRect but nothing is coming out on the screen:

// Drawing the current person's display picture
CGImageRef image = [[appDelegate.people objectAtIndex:appDelegate.currentPersonNum] image2];
CGRect imageRect;
imageRect.origin = CGPointMake(8.0, 8.0);
imageRect.size = CGSizeMake(64.0, 64.0);
CGContextDrawImage(context, imageRect, image);

has anyone had any success with drawing images in your subclassed UIView? cheers.
 

rand0m3r

macrumors regular
Original poster
Jun 30, 2006
115
1
u're right, it was null. i've got it work now, but what the hell it's upside down?!
 

lucasgladding

macrumors 6502
Feb 16, 2007
319
1
Waterloo, Ontario
u're right, it was null. i've got it work now, but what the hell it's upside down?!

Page 38 of the Quartz 2D Programming Guide has one alternative. I'm not sure if isFlipped works when you're working outside the Cocoa drawing methods - you may need to transform the context as mentioned in the guide. If you are new to drawing with Quartz, I would recommend reading the guide before anything else.
 

rand0m3r

macrumors regular
Original poster
Jun 30, 2006
115
1
transforming the context is a bad idea becoz everything else will become upside down and only my image will be the right way around.
 

lucasgladding

macrumors 6502
Feb 16, 2007
319
1
Waterloo, Ontario
transforming the context is a bad idea becoz everything else will become upside down and only my image will be the right way around.

Only if you don't save the graphics state before the transform and restore it afterward.

I haven't done a ton of work with Core Graphics functions, but I have always transformed the matrix before drawing any images. That said, the other drawing has also been done with the transformed matrix. Someone else may chime in with another alternative - I would love to know if there is a better way.
 

firewood

macrumors G3
Jul 29, 2003
8,141
1,384
Silicon Valley
You could pre-flip your png's offline if you don't want to use affine transforms and save/restore CG state. You'd have to measure the performance hit of the latter.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.