• 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
Re: Not even a portion of a window?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Not even a portion of a window?


  • Subject: Re: Not even a portion of a window?
  • From: Lorenzo <email@hidden>
  • Date: Fri, 15 Jul 2005 23:50:31 +0200

Thank you Troy. It is very clear now. And it worked well.
I have been using initWithFocusedViewRect in some other case in the past,
but since [textView drawRec:rect] worked well I made it short and went to
the wrong way. Thank you for your support.


Best Regards
--
Lorenzo
email: email@hidden

> From: Troy Stephens <email@hidden>
> Date: Fri, 15 Jul 2005 11:16:23 -0700
> To: Lorenzo <email@hidden>
> Cc: email@hidden
> Subject: Re: Not even a portion of a window?
>
> On Jul 15, 2005, at 10:20 AM, Lorenzo wrote:
>> H,
>> why can't I get an image of my window?
>> I get an empty image all the time. What did I miss?
>>
>>     NSRect        imageRect = [[aWindow contentView] bounds];
>>     NSSize        imageSize = imageRect.size;
>>     NSData        *imageData = nil;
>>
>>     NSImage *image = [[NSImage alloc] initWithSize:imageSize];
>>     [image lockFocus];
>>         [[aWindow contentView] drawRect:imageRect];
>>         imageData = [image TIFFRepresentation];
>>     [image unlockFocus];
>>
>>     [imageData writeToFile:@"/a_image_%d.tiff" atomically:YES];
>>     [image release];
>>
>> Best Regards
>> --
>> Lorenzo
>> email: email@hidden
>
> -drawRect: relies on some setup that AppKit provides when invoking
> it.  With the exception of sending [super drawRect:aRect] from a
> subclass' implementation of this method, it isn't meant to be invoked
> directly by apps.  Also, it would only result in drawing the
> contentView in this case (which by default is a simple NSView that
> draws nothing); -drawRect: itself does not recurse to draw subviews
> and descendants.
>
> If you want a snapshot of the content portion of your window, the
> recommended technique is to use NSBitmapImageRep's -
> initWithFocusedViewRect: method:
>
>    NSView *contentView = [aWindow contentView];
>    NSRect imageRect = [contentView bounds];
>    [contentView lockFocus];
>    NSBitmapImageRep *bitmapImageRep = [[NSBitmapImageRep alloc]
> initWithFocusedViewRect:imageRect];
>    [conventView unlockFocus];
>
> This will snapshot the window's content area, including the
> background fill.  On Tiger, there is also some new NSView API that
> enables you to render a view subtree to a bitmap (which omits the
> background that would otherwise be provided by the window and any
> ancestor views):
>
> - (void)displayRectIgnoringOpacity:(NSRect)aRect inContext:
> (NSGraphicsContext *)context;
> - (NSBitmapImageRep *)bitmapImageRepForCachingDisplayInRect:(NSRect)
> rect;
> - (void)cacheDisplayInRect:(NSRect)rect toBitmapImageRep:
> (NSBitmapImageRep *)bitmapImageRep;
>
> --
> Troy Stephens
> Cocoa Frameworks
> Apple Computer, Inc.
>
>

 _______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:

This email sent to email@hidden

References: 
 >Re: Not even a portion of a window? (From: Troy Stephens <email@hidden>)

  • Prev by Date: Re: screensaver notifications?
  • Next by Date: Re: [RESOLVED] screensaver notifications?
  • Previous by thread: Re: Not even a portion of a window?
  • Next by thread: Preventing flicker on moving NSView to a different superview
  • Index(es):
    • Date
    • Thread