我正在尝试编写一个小型库,用于捕获屏幕截图并将图像存储在磁盘上。
我已经成功实现了屏幕截图和图像存储在磁盘上的功能。但是,我无法根据指定的高度和宽度调整图像大小。以下是代码片段:
int imageWidth = 200;
int imageHeight = 200;
CFStringRef keys[2];
CFTypeRef values[2];
keys[0] = kCGImagePropertyDPIHeight;
values[0] = CFNumberCreate(NULL, kCFNumberIntType, &imageHeight);
keys[1] = kCGImagePropertyDPIWidth;
values[1] = CFNumberCreate(NULL, kCFNumberIntType, &imageWidth);
CFDictionaryRef options = NULL;
options = CFDictionaryCreate( NULL, (const void **)keys, (const void **)values, 2,
&kCFTypeDictionaryKeyCallBacks, &kCFTypeDictionaryValueCallBacks);
// Set the image in the image destination to be `image' with
// optional properties specified in saved properties dict.
CGImageDestinationAddImage(dest, imageRef, options);
bool success = CGImageDestinationFinalize(dest);
NSAssert( success != 0, @"Image could not be written successfully");
如果我做错了什么,请告诉我。