スクリーン バッファからピクセルを読み取ろうとしCGImageRef
ていますCGDisplayCreateImage
。画像の幅は 1366 です。CGImageGetWidth
CGImageGetBytesPerRow
何が起きてる?画像に何らかのパディングがありますか?安全に取得しているデータから、正しい結果を得るにはどうすればよいですか?
編集:これを再現するために必要な最小限のコードは次のとおりです。
#import <Foundation/Foundation.h>
#import <ApplicationServices/ApplicationServices.h>
int main(int argc, const char * argv[])
{
@autoreleasepool {
CGImageRef image = CGDisplayCreateImage(CGMainDisplayID());
size_t width = CGImageGetWidth(image);
size_t bpr = CGImageGetBytesPerRow(image);
size_t bpp = CGImageGetBitsPerPixel(image);
size_t bpc = CGImageGetBitsPerComponent(image);
size_t bytes_per_pixel = bpp / bpc;
NSLog(@"%li %li", bpr/bytes_per_pixel, width);
CGImageRelease(image);
}
return 0;
}