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?


回答:

Instead of

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

Use

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

In the middle of your begin/end CGcontext methods.

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 UI image holding onto knowledge of the orientation while the CGContextDrawImage method gets the underlying raw image data with no understanding of orientation.

Note that you'll run into this problem in many areas, but one specific example is dealing with address book user images.


  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
CATiledLayer 是一个可以用来加载和显示大尺寸瓦片地图的图层类。瓦片地图是一种将地图分割成许多小块(瓦片)并按需加载显示的技术。 CATiledLayer 在处理瓦片地图时具有很多优势。首先,它可以分割整个地图成许多小瓦片,这样只有在需要显示的时候才加载对应的瓦片,有效地节省了内存空间。其次,CATiledLayer 支持异步地加载瓦片,这意味着在瓦片加载过程中,用户仍然可以滑动和放大缩小地图而不会有明显的卡顿。此外,CATiledLayer 还可以自动处理瓦片的级别细节,即在放大和缩小地图时,会自动加载和卸载相应级别的瓦片,以提供更好的用户体验。 使用 CATiledLayer 加载瓦片地图的过程主要包括以下几个步骤。首先,我们需要将整个地图图片切割成许多小瓦片,并为每个瓦片创建一个对应的 CATiledLayer。然后,我们需要实现一个自定义的 UIView,并将其 layer 类型设置为 CATiledLayer。在自定义的 UIView 中,我们需要实现 drawRect 方法,在该方法中根据当前的可视区域,使用 CGContextDrawImage 方法将需要显示的瓦片绘制到屏幕上。此外,我们还需要实现一个自定义的 UIScrollView,用于处理地图的滑动和缩放,以及对应瓦片的加载和卸载。 总的来说,CATiledLayer 瓦片地图是一种高效加载和显示大尺寸地图的技术,它通过分割地图成小瓦片并按需加载显示,提供了更好的用户体验和内存效率。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值