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

2024-10-03 17:28:59 发布

您现在位置:Python中文网/ 问答频道 /正文

首先让我指出,我完全不知道我在objective-c和mac开发上做了什么(尽管我对c很满意)。我用python的Quartz-2d绑定在leopard上制作了一个非常简单的图形实用程序:

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

它基本上输入一个文本文件并编写一个漂亮的png文件(这是一个命令行实用程序)。当我把这个实用工具移到我们的雪豹服务器上,发现在雪豹上的CoreGraphics和32位python中存在各种各样的问题之前,我非常高兴。这些问题有些是可以解决的,有些则不是。所以,我尝试将这个简单的实用程序脚本移植到objective-c(实际上是c,我想是c)并遇到一些问题。有没有人知道有没有一个很好的例子,几乎和python和quartz中给出的一样,但都是用本机代码编写的?在

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

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演示的C端口?在


Tags: 文件to实用程序图形applemacquartzobjective
1条回答
网友
1楼 · 发布于 2024-10-03 17:28:59
CGImageRef myImage = CGBitmapContextCreateImage (myBitmapContext);// 5

CGContextDrawImage(myBitmapContext, myBoundingBox, myImage);// 6

什么?为什么要将上下文的内容捕获为一个图像,然后将该图像绘制回从中获取的上下文?在

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

执行步骤5,然后将该图像发送给CGImageDestination。在

你可能会发现Core Graphics Reference Collection很方便。大多数框架都有这样的文档。在

相关问题 更多 >