Advertise Mobile SDKs Books Events Forum News Social Networking Support Us
Follow @iphonedevsdk on Twitter

Interface 2, Advanced iOS
Mockup & Code Gen
($9.99)

Make your own iPhone apps
and run them live!
(free)

Pic Frame Dynamo: Photo Editing
($0.99)

Abiliator
($1.99)

Want your application or service advertised on iPhone Dev SDK?

Go Back   iPhone Dev SDK Forum > Mac OS X Development Forums > Mac OS X Development

Reply
 
LinkBack Thread Tools Display Modes
Old 02-10-2011, 12:31 AM   #1 (permalink)
Registered Member
 
Join Date: Nov 2010
Posts: 5
supersurabbit is on a distinguished road
Default Saving NSView to Bitmap — (ScrollView)

I have an NSView subclass called StretchView. Here's what I want to do: Since the StretchView has scrollbars and is extended via those scrollbars I want to be able to grab the entire StretchView (including the area not visible on screen) and save that to a file.

// StretchView.h
#import <Cocoa/Cocoa.h>
@interface StretchView : NSView {
}
-(IBAction)saveImageButtonPushedid)sender;

@end

// StretchView.m
#import "StretchView.h"
@implementation StretchView

//......

-(IBAction)saveImageButtonPushedid)sender
{
NSLog(@"saveImageButtonPushed");

NSBitmapImageRep *rep;
NSData *data;
NSImage *image;

[self lockFocus];
rep = [[NSBitmapImageRep alloc] initWithFocusedViewRect:[self frame]];
[self unlockFocus];

image = [[[NSImage alloc] initWithSize:[rep size]] autorelease];
[image addRepresentation:rep];

data = [rep representationUsingType: NSPNGFileType properties: nil];
//save as png but failed
[data writeToFile: @"asd.png" atomically: NO];

//save as pdf, succeeded but with flaw
data = [self dataWithPDFInsideRect:[self frame]];
[data writeToFile:@"asd.pdf" atomically:YES];
}
//......
@end


The problem is, the png file that generated is only part of the ScrollView (I tried to change the "initWithFocusedViewRect:[self frame]];" to "initWithFocusedViewRect:[self bounds]];" but in vain).

Then I tried to save the NSView content as pdf file and this time the whole view content was grabbed successfully but the backgound color was gone(I've set the content view's background as red but in the pdf file the background was white).

Can anybody give a hint, thans^_^
supersurabbit is offline   Reply With Quote
Reply

Bookmarks

Tags
nsview

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



» Advertisements
» Online Users: 371
8 members and 363 guests
husthlj, illogical, LegionMD, LunarMoon, mer10, Murphy, padsoftware, stanny
Most users ever online was 1,387, 04-10-2012 at 04:21 AM.
» Stats
Members: 175,677
Threads: 94,127
Posts: 402,916
Top Poster: BrianSlick (7,990)
Welcome to our newest member, husthlj
Powered by vBadvanced CMPS v3.1.0

All times are GMT -5. The time now is 07:12 AM.
Powered by vBulletin® Version 3.8.0
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.3.0