使用部分图像文件创建 UIImageView

编程入门 行业动态 更新时间:2024-10-06 16:22:12
本文介绍了使用部分图像文件创建 UIImageView的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我正在继承 UIImageView 以创建基于图块的应用程序.本质上,我将单个图像文件分解为多个片段,然后将这些片段分配给我的图块 (UIImageViews),以便可以独立操作它们.

I'm subclassing UIImageView to create a tile-based application. Essentially, I am taking a single image file and breaking it up into pieces, and then assigning the pieces to my tiles (UIImageViews), so that they can be manipulated independently.

抓取图像的一部分并使用它来绘制 UIImageView 的最佳方法是什么?我考虑过覆盖 drawRect 并使用 CGAffineTransform,但似乎应该有更简单的方法来做到这一点,也许通过指定 CGRect到传递给 UIImageView 的 UIImage,但我没有看到用于此的 API.

What's the best way to grab a portion of an image and use that to draw a UIImageView? I thought about overriding drawRect and using CGAffineTransform, but it seems like there ought to be a simpler way to do this, perhaps by specifying a CGRect to the UIImage that is passed to the UIImageView, but I don't see an API for this.

推荐答案

开始吧:

UIImage* img = [UIImage imageNamed:@"myImage.jpg"]; CGRect imgFrame = CGRectMake(x, y, tileWidth, tileHeight); CGImageRef imageRef = CGImageCreateWithImageInRect([img CGImage], imgFrame); UIImage* subImage = [UIImage imageWithCGImage: imageRef]; CGImageRelease(imageRef);

更多推荐

使用部分图像文件创建 UIImageView

本文发布于:2023-10-10 18:13:26,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1479354.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:图像文件   UIImageView

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!