4

CGContext 描画メソッドの代わりに drawInRect を使用することについて、この Web サイトでいくつかの投稿を読みました。それはまだそれを逆さまに描きますか?drawInRect を使用すると、座標系が左上から始まるように右向きに印刷されると思いましたか?

-(void) drawImage:(UIImage*) image atX:(float) x andY:(float) y withWidth:(float) width andHeight:(float) height onContext:(CGContextRef) context{
UIGraphicsPushContext(context);
[image drawInRect:CGRectMake(x, size.height-y-height, width, height)];
UIGraphicsPopContext();
}

私がやっていることに注意size.height-y-heightしてください。そうしないと、期待した場所に移動しません(drawInRect左上の座標系を使用すると仮定します)。上記のコードでは正しい場所にレンダリングされますが、上下逆になっています。ヘルプ!!!!!!

アップデート

以下の回答のおかげで、これが作業方法です

-(void) drawImage:(UIImage*) image atX:(float) x andY:(float) y withWidth:(float) width andHeight:(float) height onContext:(CGContextRef) context{
UIGraphicsPushContext(context);
CGContextSaveGState(context); 
CGContextTranslateCTM(context, 0, size.height);
CGContextScaleCTM(context, 1.0, -1.0);
[image drawInRect:CGRectMake(x, y, width, height)];
CGContextRestoreGState(context);
UIGraphicsPopContext();
}
4

1 に答える 1

1
    UIGraphicsBeginImageContext(imageViewSize);
CGContextRef imageContext = UIGraphicsGetCurrentContext();

// Draw the image in the upper left corner (0,0) with its actual size
CGContextDrawImage(imageContext, imageViewRect, oldImage.CGImage);

//  As it draws the image from lower right corner, 
//  following code will flip it up side down vertically.


CGContextTranslateCTM(imageContext, 0.0, 0.0);
CGContextScaleCTM(imageContext, 1.0, -1.0);

CGContextDrawImage(imageContext, imageViewRect, oldImage.CGImage);
于 2010-12-21T04:40:12.047 に答える