从 Quickdraw 转换为石英 2D

发布于 2024-12-03 11:49:00 字数 373 浏览 2 评论 0原文

我有一个旧代码,

Rect r;    
GetPortBounds(some_bitmap,&r);    
PixMapHandle somehandle = GetGWorldPixMap(some_bitmap);
if(LockPixels(somehandle)){
  TPixel *data = (TPixel *) GetPixBaseAddr(somehandle);  
  long row_bytes = GetPixRowBytes(somehandle);  
  // doing something  
  UnlockPixels(somehandle);  
}  

有人可以帮我用quartz 2d 中的替换代码吗

I have an old code that uses,

Rect r;    
GetPortBounds(some_bitmap,&r);    
PixMapHandle somehandle = GetGWorldPixMap(some_bitmap);
if(LockPixels(somehandle)){
  TPixel *data = (TPixel *) GetPixBaseAddr(somehandle);  
  long row_bytes = GetPixRowBytes(somehandle);  
  // doing something  
  UnlockPixels(somehandle);  
}  

Can anyone help me with the replacement code in quartz 2d

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

在梵高的星空下 2024-12-10 11:49:00

要使用 Quartz 修改位图,您可以使用图像初始化 CGContextRef 并使用 CGContextDraw... 例程绘制到该上下文。
(我为 NSView 子类编写了以下示例代码。效率有点低。如果您使用该代码,请将可以保留在 iVars 中的内容分开。)

- (void)drawRect:(NSRect)dirtyRect
{
    //Load an image ...
    NSImage* image = [[NSImage alloc] initWithContentsOfFile:@"/Library/Desktop Pictures/Grass Blades.jpg"];
    CGImageRef testImage = [[[image representations] objectAtIndex:0] CGImage];
    [image release];
    CGDataProviderRef dataProvider = CGImageGetDataProvider(testImage);
    //... and retrieve its pixel data
    CFDataRef imageData = CGDataProviderCopyData(dataProvider);
    void* pixels = (void*)CFDataGetBytePtr(imageData);
    CGColorSpaceRef colorspace = CGColorSpaceCreateWithName(kCGColorSpaceGenericRGB);
    //Init a quartz context that uses the pixel data memory as buffer
    CGContextRef drawContext = CGBitmapContextCreate(pixels, CGImageGetWidth(testImage), CGImageGetHeight(testImage), CGImageGetBitsPerComponent(testImage), CGImageGetBytesPerRow(testImage), colorspace, CGImageGetBitmapInfo(testImage));
    CGContextSetRGBFillColor(drawContext, 0.8, 0.8, 0.8, 1.0);
    //Do something with the newly created context
    CGContextFillRect(drawContext, CGRectMake(20.0, 20.0, 200.0, 200.0));    
    CGColorSpaceRelease(colorspace);
    CGImageRef finalImage = CGBitmapContextCreateImage(drawContext);
    //Draw the modified image to the screen
    CGContextDrawImage([[NSGraphicsContext currentContext] graphicsPort], dirtyRect, finalImage);
    CFRelease(imageData);
    CGImageRelease(finalImage);
    CGContextRelease(drawContext);
}

To modify a bitmap with Quartz you can initialize a CGContextRef with the image and draw to that context with CGContextDraw... routines.
(I wrote the following sample code for a NSView subclass. It's a bit inefficient. If you use the code, separate the stuff you can keep around in iVars.)

- (void)drawRect:(NSRect)dirtyRect
{
    //Load an image ...
    NSImage* image = [[NSImage alloc] initWithContentsOfFile:@"/Library/Desktop Pictures/Grass Blades.jpg"];
    CGImageRef testImage = [[[image representations] objectAtIndex:0] CGImage];
    [image release];
    CGDataProviderRef dataProvider = CGImageGetDataProvider(testImage);
    //... and retrieve its pixel data
    CFDataRef imageData = CGDataProviderCopyData(dataProvider);
    void* pixels = (void*)CFDataGetBytePtr(imageData);
    CGColorSpaceRef colorspace = CGColorSpaceCreateWithName(kCGColorSpaceGenericRGB);
    //Init a quartz context that uses the pixel data memory as buffer
    CGContextRef drawContext = CGBitmapContextCreate(pixels, CGImageGetWidth(testImage), CGImageGetHeight(testImage), CGImageGetBitsPerComponent(testImage), CGImageGetBytesPerRow(testImage), colorspace, CGImageGetBitmapInfo(testImage));
    CGContextSetRGBFillColor(drawContext, 0.8, 0.8, 0.8, 1.0);
    //Do something with the newly created context
    CGContextFillRect(drawContext, CGRectMake(20.0, 20.0, 200.0, 200.0));    
    CGColorSpaceRelease(colorspace);
    CGImageRef finalImage = CGBitmapContextCreateImage(drawContext);
    //Draw the modified image to the screen
    CGContextDrawImage([[NSGraphicsContext currentContext] graphicsPort], dirtyRect, finalImage);
    CFRelease(imageData);
    CGImageRelease(finalImage);
    CGContextRelease(drawContext);
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文