• 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
How to show CGImageRef over an overlay nswindow.
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

How to show CGImageRef over an overlay nswindow.


  • Subject: How to show CGImageRef over an overlay nswindow.
  • From: Amit8 J <email@hidden>
  • Date: Thu, 29 Nov 2007 17:59:42 +0530

Hello all,
I am stuck to a problem related to core graphics. Actually i want to
display an image over a overlay nswindow. For creating an cgimageref i
have written the following code:

Code:
CGImageRef  getPNGImage(CFStringRef fileName)
{
  CGDataProviderRef  provider;
  //CFStringRef     fileName  = NULL;
  CGImageRef      image    = NULL;
  CFURLRef       url    = NULL;
  CFBundleRef     appBundle  = CFBundleGetMainBundle();

  if ( appBundle == NULL )  goto Bail;

  //fileName = CFStringCreateWithCString( NULL, "originalColor.png",
kCFStringEncodingASCII );  //  ToolbarPoof.png is in our Resources
directory within the bundle
  if ( fileName == NULL )  goto Bail;

  url = CFBundleCopyResourceURL( appBundle, fileName, NULL, NULL );
  if ( url == NULL ) goto Bail;

  provider  = CGDataProviderCreateWithURL( url );

  image  = CGImageCreateWithPNGDataProvider( provider, NULL, false,
kCGRenderingIntentDefault );

  CGDataProviderRelease( provider );

Bail:
  if ( fileName != NULL )  CFRelease( fileName );
  if ( url != NULL )  CFRelease( url );
  return( image );
}
But i am not able to display the image on the overlay window.first thing
is tht i dont know how to put the image on my window still i tried by
writing following stuff:

Code:
 //getting the current context.
CGContextRef myContext = [[NSGraphicsContext currentContext]
graphicsPort];
//nsstring converted to CFStringRef.
CFStringRef cfFilepath = (CFStringRef)image;
//calling the above method.
CGImageRef image = getPNGImage(cfFilepath);
//drawing the image but where it is displayed i dont know :(.
CGContextDrawImage(myContext,CGRectMake(0,0,CGImageGetWidth( image
),CGImageGetHeight( image )),image);

In my class where i am implementing this i have the following init method:
My main problem is how should i display the image over specified location
ie over the overlay window
or rather how to put the image over the window so tht it is visible.
Code:
// init method for OverlayWindow class
-(id)initWithRect:(NSRect)contentRect Controller:(OverlayController
*)overlayControl
{
        //dockOrientation = @"";

        if(self = [super initWithContentRect:contentRect
styleMask:NSBorderlessWindowMask backing:NSBackingStoreBuffered defer:NO])
        {
                //[self setBackgroundColor: [NSColor clearColor]];
                //[self setAlphaValue:0.00];
                [self setBackgroundColor:[NSColor redColor]];
                [self setAlphaValue:0.5];
                [self setOpaque:NO];
                [self setHasShadow: NO];
                [self setLevel:NSStatusWindowLevel];
                [self makeKeyAndOrderFront:self];
                [self setIgnoresMouseEvents:NO];

                // register for required drag types
                [self registerForDraggedTypes:[NSArray
arrayWithObjects:@"CorePasteboardFlavorType
0x6974756E",@"AlbumListPboardType",@"AlbumDataListPboardType",NSFilenamesPboardType,NSFilesPromisePboardType,
nil]];
                //@"ImageDataListPboardType",
                //[trackingWin registerForDraggedTypes:[NSArray
arrayWithObjects:@"CorePasteboardFlavorType
0x6974756E",@"AlbumListPboardType",@"AlbumDataListPboardType",NSFilenamesPboardType,NSFilesPromisePboardType,
nil]];
                //[self setAcceptsMouseMovedEvents:YES];

                //highlightImage = [NSImage
imageNamed:@"Connect_highlight"];
                isFocused = NO;
                //isDragEntered = NO;
                NSScreen *mainScreen = [NSScreen mainScreen];
                screenRect = [mainScreen frame];
                //[self showWindow:YES];
                overlayController = overlayControl;
                gOverlayWindow = self;

                return self;
        }
        return nil;

}

Regards...
@mit
=====-----=====-----=====
Notice: The information contained in this e-mail
message and/or attachments to it may contain
confidential or privileged information. If you are
not the intended recipient, any dissemination, use,
review, distribution, printing or copying of the
information contained in this e-mail message
and/or attachments to it are strictly prohibited. If
you have received this communication in error,
please notify us by reply e-mail or telephone and
immediately and permanently delete the message
and any attachments. Thank you


_______________________________________________

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: How to show CGImageRef over an overlay nswindow.
      • From: Alastair Houghton <email@hidden>
  • Prev by Date: Re: [OT] Chown returns file lock error
  • Next by Date: NSTableView - Leopard - Tooltips
  • Previous by thread: How to enable/disable the menu items Font > Bold/Italic on Leopard?
  • Next by thread: Re: How to show CGImageRef over an overlay nswindow.
  • Index(es):
    • Date
    • Thread