iPhone Objective-C 图像处理
我正在寻找一种方法,在 Objective-C 中,根据用户的设置方式从几个较小的 PNG 创建一个 PNG。使用现有的 Apple 类是否可以实现这一点,或者我是否需要使用第三方库?如果需要第 3 方代码,有人可以推荐一个好的库吗?越简单越好 - 简单的滤镜(例如使图像变暗/变亮)会很好,但不是必需的。
这里有一些伪代码,可以让您更好地了解我正在寻找的内容:
image = [myImageLibrary imageWithHeight:1024 width:768];
[image addImage:@"background.png" atX:0 andY:0 withRotation:0];
[image addImage:@"image2.png" atX:100 andY:200 withRotation:90];
[image saveAtLocation:@"output.png"];
在output.png中,我们看到image2.png放置在background.png之上并旋转了90
度- 如果这似乎与另一个问题重复,我很抱歉,我只是没有找到适合我想做的事情的答案。
I am looking for a way to, in Objective-C, create a PNG from several smaller PNGs based on how the user sets things up. Is this possible using existing Apple classes, or do I need to use a 3rd party library? If 3rd party code is needed, can anyone recommend a good library? The simpler the better - simple filters (such as darkening/lightening the image) would be nice but not required.
Here is some pseudo-code, to give you a better idea of what I am looking for:
image = [myImageLibrary imageWithHeight:1024 width:768];
[image addImage:@"background.png" atX:0 andY:0 withRotation:0];
[image addImage:@"image2.png" atX:100 andY:200 withRotation:90];
[image saveAtLocation:@"output.png"];
At output.png we see image2.png placed on top of background.png and rotated 90 degrees
P.S. - I am sorry if this seems to be a duplicate of another question, I just have not found an answer that works for what I am trying to do.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您是否阅读过 iOS 绘图和打印指南 和 UIImage 类参考文档?
你所追求的是完全可能的——有了一个构建良好的类,你几乎可以按原样使用伪代码。
作为十个初学者,您可以:
UIGraphicsBeginImageContext
创建您自己的图形上下文。UIGraphicsGetImageFromCurrentImageContext
保存结果图像数据。关于步骤 1 和 3,请参阅 UIKit 函数参考 了解更多信息。此外, UIImage 类 可能对执行转换等有用,作为步骤 2 的一部分。
Have you read the "Creating and Drawing Images" section of the Drawing and Printing Guide for iOS and the UIImage Class Reference docs?
What you're after is perfectly possible - with a well built class you could pretty much use that pseudo code as-is.
As a starter for ten, you could:
UIGraphicsBeginImageContext
.drawAtPoint
: method of the UIImage classUIGraphicsGetImageFromCurrentImageContext
.In terms of steps 1 and 3, see the UIKit Function Reference for more info. Additionally, the
imageWithCGImage:scale:orientation:
method of the UIImage class may prove useful for performing transformations, etc. as a part of step 2.您需要查看 CGContextDrawImage 来使用自定义位图上下文绘制图像,然后使用 UIGraphicsGetImageFromCurrentImageContext() 将其保存。可以通过将 CGAffineTransforms 应用于 CGContext 来完成旋转。
有关核心显卡的更多信息,请参见此处:
http://developer.apple.com/库/mac/#documentation/GraphicsImaging/Conceptual/drawingwithquartz2d/Introduction/Introduction.html
You'll want to look at CGContextDrawImage to draw your images, using a custom bitmap context, and then save it out using UIGraphicsGetImageFromCurrentImageContext(). The rotation can be done by applying CGAffineTransforms to your CGContext.
More information on Core Graphics here:
http://developer.apple.com/library/mac/#documentation/GraphicsImaging/Conceptual/drawingwithquartz2d/Introduction/Introduction.html