• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Generic Bitmap to NSImage
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Generic Bitmap to NSImage


  • Subject: Generic Bitmap to NSImage
  • From: "Raglan T. Tiger" <email@hidden>
  • Date: Thu, 25 Jun 2015 17:10:48 -0600

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 (email@hidden)

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:

This email sent to email@hidden


  • Follow-Ups:
    • Re: Generic Bitmap to NSImage
      • From: Ken Thomases <email@hidden>
    • Re: Generic Bitmap to NSImage
      • From: Graham Cox <email@hidden>
  • Prev by Date: Another AppleScriptObjC Bridge Question
  • Next by Date: Re: Generic Bitmap to NSImage
  • Previous by thread: Another AppleScriptObjC Bridge Question
  • Next by thread: Re: Generic Bitmap to NSImage
  • Index(es):
    • Date
    • Thread