🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: borland.public.jbuilder.java.language
Article #14411

Re: createImage(w,h) is null ?

#14411
From: Paul Furbacher [TeamB]
Date: Mon, 06 Sep 1999 00:00
47 lines
2649 bytes
Dan Woods wrote:

> ...  I have written many applets
> and have no problem with image manipulation by using an offscreen
> image buffer.  I am now writing a JDK1.1.5 application (command line)
> to read in an image and *create* a new image stored to disk.
> 
> My main class extends Panel(), calls another class expecting a
> Component() (ie: 'this' panel) and a source image, and tries to
> create a new image based on the source image.  My lines of code:
> // ------------- 'comp' is the Component() passed in
> /*
>     Image composite = comp.createImage( new MemoryImageSource(
>           imgWidth, imgHeight, new int[imgWidth * imgHeight], 0, imgWidth) );
> */
> /*
>     Image composite = comp.getToolkit().createImage(
>                         new byte[imgWidth * imgHeight]);
> */
>     Image composite = comp.createImage(imgWidth, imgHeight);
>     try { Thread.sleep(1000); } catch (Exception e) {}
> // -------------
> 
> However, none of my attempts work.  In the last case, composite is
> always 'null'.  In the first two, they work except that when I try
>         Graphics offG = composite.getGraphics();
> it complains that getGraphics() only works for an image created
> using "createImage(int width, int height)"
> 
> The last case has always worked in applets, but not for this app.

Are you actually "realizing" your "comp" by adding it to a Frame, 
Window, Applet, and packing/validating the owner?  You would
of course do this in all the applets you've written, but in the
above case, it looks as if you are trying to short-circuit the 
production of the image to a "realized" canvas, and just trying
to shove it out to disk first.  If anything, you have to add your
"comp" to a Frame, pack the Frame, but don't "setVisible()".
Then you can get a valid graphics context, and do your rendering,
etc.

Also, if you "getGraphics()", be sure to "g.dispose()".  We all
know that we're supposed to do it, but someone caught me being
forgetful.  Very leaky, and quite embarrassing.


Paul Furbacher (TeamB)
Technical Details
Message-ID: <37D47155.B62DC257@bilbo.bio.purdue.edu>
Path: arc1-ca.pugleaf.net!unknown!not-for-mail
References: <37CF61B9.DE2B20A9@ucalgary.ca>

Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: f74b3,2ef73006d99f91a3
X-Google-Attributes: gidf74b3,public
From: "Paul Furbacher [TeamB]" <pf@bilbo.bio.purdue.edu>
Subject: Re: createImage(w,h) is null ?
Date: 1999/09/06
Message-ID: <37D47155.B62DC257@bilbo.bio.purdue.edu>
X-Deja-AN: 521918732
Content-Transfer-Encoding: 7bit
References: <37CF61B9.DE2B20A9@ucalgary.ca>
Content-Type: text/plain; charset=us-ascii
Organization: Reverse Alchemy, Inc.
Mime-Version: 1.0
Reply-To: pf@bilbo.bio.purdue.edu
Newsgroups: borland.public.jbuilder.java.language