I have a list of generic bitmaps that are to be transformed to NSImages.  The 
list can be long, I haven limits on it.

Here is the code I use to populate an NSMenu that gets set into an 
NSPopUpButton.

I need to speed this process up ... any suggestions?

    NSMenu *comboMenu = [[[NSMenu alloc] init] autorelease];
   POSITION pos = listOfBBitmaps.GetHeadPosition();
    while ( pos )
    {
        BBitmap *image = &listOfBBitmaps.GetNext ( pos );
        
        CGColorSpaceRef colorSpace;
        colorSpace = CGColorSpaceCreateWithName(kCGColorSpaceGenericRGB);
        CGContextRef    context;
        context = CGBitmapContextCreate (image->m_array, image->m_pixelsx, 
image->m_pixelsy, 8, image->m_pixelsx * 4, colorSpace, 
kCGImageAlphaNoneSkipFirst|kCGBitmapByteOrder32Host);
        
        CGImageRef cgImage = CGBitmapContextCreateImage (context);
        
        CGContextRelease(context);
        CGColorSpaceRelease(colorSpace);
        
        size_t width = CGImageGetWidth( cgImage );
        size_t height = CGImageGetHeight( cgImage );
        NSRect imageRect = NSMakeRect(0, 0, width, height);
        NSImage *nsImage = [[[NSImage alloc] initWithSize:imageRect.size] 
autorelease];
  
        if ( [nsImage respondsToSelector:@selector(lockFocusFlipped:)] )
        {
            [nsImage lockFocusFlipped:YES];
        }
        else
        {
            [nsImage setFlipped:YES];
            [nsImage lockFocus];
        }
            CGContextRef imageContext = (CGContextRef)[[NSGraphicsContext 
currentContext] graphicsPort];
            CGContextDrawImage(imageContext, *(CGRect*)&imageRect, cgImage);
        
        [nsImage unlockFocus];
        
        NSMenuItem *menuItem = [[[NSMenuItem alloc] init] autorelease];
        [menuItem setImage: nsImage];
        
        [menuItem setTitle:[NSString stringWithFormat:@"untitled"]];
        
        [comboMenu addItem:menuItem];
        
        m_imageCount++;
        
    }





-rags



_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Reply via email to