CGContextDrawImage 在传递 UIImage.CGImage 时将图像倒置 [英] CGContextDrawImage draws image upside down when passed UIImage.CGImage

查看:28
本文介绍了CGContextDrawImage 在传递 UIImage.CGImage 时将图像倒置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有谁知道为什么 CGContextDrawImage 会把我的图像倒过来画?我正在从我的应用程序加载图像:

Does anyone know why CGContextDrawImage would be drawing my image upside down? I am loading an image in from my application:

UIImage *image = [UIImage imageNamed:@"testImage.png"];

然后简单地要求核心图形将其绘制到我的上下文中:

And then simply asking core graphics to draw it to my context:

CGContextDrawImage(context, CGRectMake(0, 0, 145, 15), image.CGImage);

它呈现在正确的位置和尺寸,但图像是颠倒的.我一定在这里遗漏了一些非常明显的东西?

It renders in the right place, and dimensions, but the image is upside down. I must be missing something really obvious here?

推荐答案

代替

CGContextDrawImage(context, CGRectMake(0, 0, 145, 15), image.CGImage);

使用

[image drawInRect:CGRectMake(0, 0, 145, 15)];

在开始/结束 CGcontext 方法的中间.

In the middle of your begin/end CGcontext methods.

这会将具有正确方向的图像绘制到您当前的图像上下文中 - 我很确定这与 UIImage 保持方向知识有关,而 CGContextDrawImage 方法在不了解方向的情况下获取底层原始图像数据.

This will draw the image with the correct orientation into your current image context - I'm pretty sure this has something to do with the UIImage holding onto knowledge of the orientation while the CGContextDrawImage method gets the underlying raw image data with no understanding of orientation.

这篇关于CGContextDrawImage 在传递 UIImage.CGImage 时将图像倒置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆