창 서버에 연결하면 NSImage
과 NSView
을 사용할 수 있습니다.AppKit 함수를 사용하여 창 서버에 연결할 수 있습니다.
main.m
#include <AppKit/AppKit.h>
int main(int argc, const char **argv) {
if(argc != 3) {
fprintf(stderr, "Usage: %s source_img dest_pdf\n", argv[0]);
exit(1);
}
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
BOOL success;
NSString *imgPath, *pdfPath;
NSImage *myImage;
NSImageView *myView;
NSRect vFrame;
NSData *pdfData;
imgPath = [NSString stringWithUTF8String:argv[1]];
pdfPath = [NSString stringWithUTF8String:argv[2]];
/* Calling NSApplicationLoad will give a Carbon application a connection
to the window server and enable the use of NSImage, NSView, etc. */
success = NSApplicationLoad();
if(!success) {
fprintf(stderr, "Failed to make a connection to the window server\n");
exit(1);
}
/* Create image */
myImage = [[NSImage alloc] initWithContentsOfFile:imgPath];
if(!myImage) {
fprintf(stderr, "Failed to create image from path %s\n", argv[1]);
exit(1);
}
/* Create view with that size */
vFrame = NSZeroRect;
vFrame.size = [myImage size];
myView = [[NSImageView alloc] initWithFrame:vFrame];
[myView setImage:myImage];
[myImage release];
/* Generate data */
pdfData = [myView dataWithPDFInsideRect:vFrame];
[pdfData retain];
[myView release];
/* Write data to file */
success = [pdfData writeToFile:pdfPath options:0 error:NULL];
[pdfData release];
if(!success) {
fprintf(stderr, "Failed to write PDF data to path %s\n", argv[2]);
exit(1);
}
[pool release];
return 0;
}
는 프레임 워크 재단과 AppKit의 연결된 이것을 컴파일
./a.out myImage.png outFile.pdf
: 당신이 그것을 컴파일 할 때
이이처럼 사용할 수 있습니다 당신은 CoreGraphics/Quartz를 사용하여 "그냥"넘어갈 수 있다면 아주 쉽게 할 수 있습니다. 앱 기반. –
당신은 정교 할 수 있습니까? – Anonymous
'NSImage'와 더 중요한 것은'NSImageRep'과 친구들 **이 AppKit.framework에 정의되어 있다는 것을 알고 계십니까? AppKit은 정말 궁금한가요? – NSGod