首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >将Quartz 2d python演示移植到纯Core Graphics C

将Quartz 2d python演示移植到纯Core Graphics C
EN

Stack Overflow用户
提问于 2010-08-06 09:45:51
回答 1查看 585关注 0票数 1

首先让我注意到,我完全不知道我在用objective-c和mac开发做什么(尽管我用c很好)。我用python的Quartz-2d绑定在leopard上做了一个非常简单的图形工具:

http://developer.apple.com/graphicsimaging/pythonandquartz.html

这基本上输入了一个文本文件并编写了一个很好的png文件(它是一个命令行实用程序)。我非常高兴,直到我把实用程序移到我们的雪豹服务器上,发现雪豹上的CoreGraphics和32位python存在各种各样的问题。其中一些问题是可以解决的,而另一些则不是。因此,我尝试将这个简单的实用程序脚本移植到objective-c (我想是C语言),但遇到了一些问题。有没有人知道有没有一个很好的例子,和python和quartz中给出的几乎完全一样,但都是用原生代码编写的?

我的主要问题是将图形上下文写入文件

代码语言:javascript
复制
myBitmapContext = MyCreateBitmapContext (400, 300);

CGContextSetRGBFillColor (myBitmapContext, 1, 0, 0, 1);
CGContextFillRect (myBitmapContext, CGRectMake (0, 0, 200, 100 ));
CGContextSetRGBFillColor (myBitmapContext, 0, 0, 1, .5);
CGContextFillRect (myBitmapContext, CGRectMake (0, 0, 100, 200 ));
CGImageRef myImage = CGBitmapContextCreateImage (myBitmapContext);// 5

CGContextDrawImage(myBitmapContext, myBoundingBox, myImage);// 6
char *bitmapData = CGBitmapContextGetData(myBitmapContext); // 7

// I'd like to write to a file here!

CGContextRelease (myBitmapContext);// 8
if (bitmapData) free(bitmapData); // 9
CGImageRelease(myImage);

MyCreateBitmapContext是来自apple's guide on quartz 2d的一个简单函数。

有没有人有上面链接中给出的python demo的C移植?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2010-08-06 12:38:07

CGImageRef myImage = CGBitmapContextCreateImage (myBitmapContext);// 5 CGContextDrawImage(myBitmapContext,myBoundingBox,myImage);// 6

什么?为什么要将上下文的内容捕获为图像,然后将该图像重新绘制到您从中获取的上下文中?

//我想在这里写一个文件!

执行步骤5,然后将该图像提供给CGImageDestination

您可能会发现Core Graphics Reference Collection很方便。大多数框架都有类似的文档。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/3420471

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档