简体   繁体   中英

How to move the image on the CGContextRef

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
}

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.

Try this

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM