[comp.sys.next] displaying an image: how?

dcarpent@sjuphil.uucp (D. Carpenter) (06/24/91)

Could some compassionate soul tell me what is lacking in
the code below?  I am trying to write a method that, in
response to a button click, will find a tiff image, create
a window for it, size the window to the size of the image,
and then display it on screen.  Probably fairly simple for
people who, unlike me, know what they are doing. 

I have managed to get the window created, and sized to
the image, but I can't get the image to display.  I haven't
explicitly created a View for the window, so perhaps
there is nothing to composite into?  How would I do this?

Here's what I have so far:

- displayImage:sender
{
  	myImage = [ [NXImage alloc] initFromFile: "/me/anImage.tiff" ];
 	[myImage getSize:&imageSize];

	NXSetRect (&rect, 500.0, 350.0, imageSize.width,
					imageSize.height);
	myWindow = [Window newContent:&rect
				 style:NX_TITLEDSTYLE
				 backing:NX_BUFFERED
				 buttonMask:NX_CLOSEBUTTONMASK
				 defer:YES];
	[[myWindow display] makeKeyAndOrderFront:self];
	
	[myImage composite:NX_COPY toPoint:&(rect.origin)];
	return self;
}

Thanks in advance for any help.

-- 
===============================================================
David Carpenter            dcarpent@sjuphil.UUCP                    
St. Joseph's University    dcarpent@sjuphil.sju.edu
Philadelphia, PA  19131   

wb1j+@andrew.cmu.edu (William M. Bumgarner) (06/25/91)

Excerpts From Captions of netnews.comp.sys.next: 23-Jun-91 displaying an
image: how? D. Carpenter@sjuphil.uuc (1304) 
>- displayImage:sender
>{
>  	myImage = [ [NXImage alloc] initFromFile: "/me/anImage.tiff" ];
> 	[myImage getSize:&imageSize];
> 
>	NXSetRect (&rect, 500.0, 350.0, imageSize.width,
>					imageSize.height);
>	myWindow = [Window newContent:&rect
>				 style:NX_TITLEDSTYLE
>				 backing:NX_BUFFERED
>				 buttonMask:NX_CLOSEBUTTONMASK
>				 defer:YES];
>	[[myWindow display] makeKeyAndOrderFront:self];
>	
>	[myImage composite:NX_COPY toPoint:&(rect.origin)];
>	return self;
>}


You need to lockFocus on a view before compositing the image to the
screen/window/view....

Probably, the easiest way for you to do that would be to do this:

[[myWindow contentView] lockFocus]; // lock focus on the window's content
                                    // view
[myImage composite:NX_COPY toPoint:&(rect.origin)]; // blast the image
[[myWindow contentView] unlockFocus]; // return to last state
[myWindow flushWindow]; // flush the contents to the screen -- this is 
                        // neccessary because you have a NX_BUFFERED window


---

As a side note, to kill the flicker of teh window coming onto the screen
and then the image appearing after that, do this:

change the defer:YES to defer:NO -- this will create the window
immediately instead of waiting until it is moved to the screen. then do:

[myWindow display];
  ... the above compositing code ...
[myWindow makeKeyAndOrderFront:self];

BTW: I'm doing this from memory-- I can't remember if the display
message is actually necessary, but have a feeling it is or else the
contents of the window will come up w/o the widgets being correctly
drawn.

b.bum
OAC -- Objective Arts Consulting <<- might be the name... not sure yet.


b.bumgarner            | Disclaimer:  All opinions expressed are my own.
wb1j+@andrew.cmu.edu   | I officially don't represent anyone unless I
NeXT Campus Consultant | explicity say I am doing so. So there. <Thpppt!>
"I ride tandem with the random/Things don't run the way I planned them.."