Question

An image has been drawn on the CGContextRef:

CGContextDrawImage(context, CGRectMake(0, 0, width, height), image);

In another function, I want to move the image to the rect like

CGRectMake(100, 100, width, height);

How can I do?

void func(CGContextRef context)//there is just one parameter
{
    //move  the image
}
Was it helpful?

Solution 2

Try this

void func(CGContextRef context, CGFloat x, CGFloat y)
{
    CGContextDrawImage(context, CGRectMake(x,y, width, height), image);
 }

OTHER TIPS

Once you've drawn to the context it can't be undone. You can draw over the previous image, perhaps with a solid color to match the background. I don't know why you would ever want to draw to a context and then move it.

I'm going to assume the first function that draws the image calls the second one that positions it. If that is the case, you can have the second function simply apply a translation transform to the context and then have the first function draw the image after calling the second.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top