Article View: borland.public.jbuilder.java.api
Article #3123AWT Image to InputStream
From: Mario Prado
Date: Thu, 14 May 1998 00:00
Date: Thu, 14 May 1998 00:00
30 lines
1856 bytes
1856 bytes
Hi
I need to save the contents of one AWT Image in a blob field of one
Dataset, but I'm having problems to convert one AWT Image to a Binary
Stream:
I Try the following code (this was posted in database group):
01- URL theURL = new URL(URLEditField.getText()); // URLEdit
contains the Image URL
02- Image Im1 = getImage(theURL);
03- ByteArrayOutputStream f = new ByteArrayOutputStream();
04- ObjectOutput s = new ObjectOutputStream(f);
05- s.writeObject(Im1); // Generate one exception
06-// s.flush(); // Necessary ?
07- ByteArrayInputStream i = new
ByteArrayInputStream(f.toByteArray());
08- queryDataSet1.editRow();
09- queryDataSet1.setBinaryStream("MAPA", i );
10- queryDataSet1.saveChanges();
But when i run the program one exception is generated in the line 05.
(because I'm mixing apples and oranges on line 05 :) )
So, How can i write one image to s ?
The setBinaryStream (line 09) requires one InputStream to work ...
when i read the image from a file with FileInputStream, the code works
fine ... without need of the ObjectOutputStream ...
Regards and Thanks in advance for any help
Mario Prado - BRAZIL
Federal University of Sao Carlos
Linkway Internet Provider
Technical Details
Message-ID:
<355AE6AB.4E2D81C7@linkway.com.br>Path:
arc1-ca.pugleaf.net!unknown!not-for-mailShow Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 1089d0,9302445ab909d129,start X-Google-Attributes: gid1089d0,public X-Google-Thread: f5619,9302445ab909d129,start X-Google-Attributes: gidf5619,public From: Mario Prado <mario@linkway.com.br> Subject: AWT Image to InputStream Date: 1998/05/14 Message-ID: <355AE6AB.4E2D81C7@linkway.com.br> X-Deja-AN: 353183666 Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset=us-ascii Organization: Linkway ISP Mime-Version: 1.0 Newsgroups: borland.public.jbuilder.java.api,borland.public.jbuilder.jbcl