Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6549343
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T12:04:53+00:00 2026-05-25T12:04:53+00:00

Update Nevermind :-) Figured it out using bitmapImageRepForCachingDisplayInRect & cacheDisplayInRect:toBitmapImageRep: . I’ll leave the

  • 0

Update
Nevermind 🙂
Figured it out using bitmapImageRepForCachingDisplayInRect & cacheDisplayInRect:toBitmapImageRep:.
I’ll leave the question here for posterity, though.


I’m working on a little application that, among other things, has an NSView subclass that draws a bunch of bezierPaths. I’d like to be able to save the drawn result as either EPS or PNG.

The view is being drawn in an offscreen window (for scaling reasons), and even though it returns the correct EPS data, I can’t seem to get any useful bitmap data from it.

EPS is no problem (I simply write the NSData from -dataWithEPSInsideRect: to a file), but I can’t seem to get a PNG bitmap.

If I try calling:

[self lockFocus];
NSBitmapImageRep* rep = [[NSBitmapImageRep alloc] initWithFocusedViewRect:self.bounds];
[self unlockFocus];
return rep;

from a category method I’ve added to NSView, I get useless white PNG data out of it when I try representationUsingType:NSPNGFileType properties:[NSDictionary dictionary].

Strangely, if I try calling lockFocus/initBitmapWith../unlockFocus from outside the view (or its category methods), I get an exception saying that the view or one of its ancestors is hidden. And well, yes, it’s offscreen (the offscreen window’s been init’ed with defer:NO, by the way, so it should paint).

So I can either get useless data or I can get an exception. Not awesome.

To add to my confusion: If I make an NSImage containing an EPS representation, and a (useless) white bitmap, where both should be the size of the view’s bounds, the bitmap representation is always 20 pixels/units narrower than the bounds. No idea why! The EPS is the correct size.

Since this may all be related to how the offscreen window’s created, here’s the code for that (from the NSView category)

- (NSWindow*)placeInOffscreenWindow {
NSRect windowBounds = { { -1000.0 , -1000.0 } , self.bounds.size };
NSWindow *hiddenWindow = [[NSWindow alloc] initWithContentRect: windowBounds
                                                         styleMask: NSTitledWindowMask | NSClosableWindowMask
                                                           backing: NSBackingStoreNonretained
                                                             defer: NO];

[[hiddenWindow contentView] addSubview:self];
return hiddenWindow;
}

Any ideas would be appreciated!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T12:04:53+00:00Added an answer on May 25, 2026 at 12:04 pm

    Ended up using bitmapImageRepForCachingDisplayInRect: & cacheDisplayInRect:toBitmapImageRep: instead

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Update: Check out this follow-up question: Gem Update on Windows - is it broken?
-edit- nevermind, i made a mistake in my select statement. Update was working correctly.
UPDATE: Focus your answers on hardware solutions please. What hardware/tools/add-in are you using to
UPDATE - A comprehensive comparison, updated as of February 2015, can be found here:
Update : this is more-or-less a dupe , and it turns out to be
UPDATE : I got my O3D situation straightened out, but I have yet to
Update: As someone pointed out I was missing an s in my Route registration.
Update : Clarified and expanded, since the original question was simplified too far I
Update 3 : Never mind. I kinda got what I was looking for. The
Update: Solved, with code I got it working, see my answer below for the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.