Article View: borland.public.jbuilder.java.language
Article #16067Re: Create a jpeg
From: lawrence_rodrigues
Date: Fri, 02 Apr 1999 00:00
Date: Fri, 02 Apr 1999 00:00
73 lines
3939 bytes
3939 bytes
In article <7e0784$l4k$1@jaydee.iway.fr>,
"Xav" <xavier@partener.com> wrote:
> Hello,
> We want to create a jpeg image from the result of a combination of 5 jpeg
> image (with pixelgrabber method)
>
> help me thanks
If you are using Java 2D, you can create a JPEG image by using the
com.sun.image.codec.jpeg package. The code below creates a JPEG image and
saves it to a file.
public void save(BufferedImage destImage, String filename) {
try {
ByteArrayOutputStream boutstream = new ByteArrayOutputStream();
JPEGImageEncoder enc = JPEGCodec.createJPEGEncoder(boutstream);
enc.encode(destImage);
FileOutputStream fimage = new FileOutputStream(new File(filename));
boutstream.writeTo(fimage);
fimage.close();
} catch (Exception e) { }
}
The code snippet below shows how to crerate a BufferedImage:
BufferedImage bi = new BufferedImage((int)imWid,
(int)(imHt),
BufferedImage.TYPE_INT_RGB);
Graphics2D g2d = bi.createGraphics();
g2d.drawImage(img, dispTx,this);
img : Your image object.
dispTx: The Affine Transform.
You can use other drawImage()methods for drawing images.
Once the image is drawn, you can save it using the save() method.
I am not sure what you mean by combination of images. If it means creating a
single image from a combination of images layed in a grid ( row X column)
fashion, you can use the following code snippet from my Java Image Browser
(http://www.execpc.com/~larryhr/ib.html). If it is in a single row, modify the
code appropriately.
public void createSingleImage() {
Dimension dim = getCellSize();
int imWid = cols*dim.width;
int imHt = rows*dim.height;
BufferedImage bi = new BufferedImage((int)imWid,
(int)(imHt),
BufferedImage.TYPE_INT_RGB);
Graphics2D g2d = bi.createGraphics();
int x = 0; int y=0;
for(int i=0; i< rows; i++) {
for(int j=0;j<cols; j++) {
if(i*cols+j >= imageset.length) break;
Image img = imageset[i*cols+j];
if(img != null)
g2d.drawImage(img, x+1,y+1, dim.width-2, dim.height-2,this);
x += dim.width;
}
x =0;
y += dim.height;
}
save(bi);//calls save(BufferedImage, filename) after getting the
filename.
}
imageset is an array of preloaded Image objects.
Lawrence Rodrigues (http://www.execpc.com/~larryhr)
Author of "The Awesome Power of Java Beans"
http://www.amazon.com/exec/obidos/ASIN/1884777562/beanman
-----------== Posted via Deja News, The Discussion Network ==----------
http://www.dejanews.com/ Search, Read, Discuss, or Start Your Own
Technical Details
Message-ID:
<7e2ff0$a8t$1@nnrp1.dejanews.com>Path:
arc1-ca.pugleaf.net!unknown!not-for-mailReferences:
<7e0784$l4k$1@jaydee.iway.fr>Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: fcfbb,e244fb77826cd224 X-Google-Attributes: gidfcfbb,public X-Google-Thread: 1057b1,e244fb77826cd224 X-Google-Attributes: gid1057b1,public X-Google-Thread: 113ae9,e244fb77826cd224 X-Google-Attributes: gid113ae9,public X-Google-Thread: f74b3,e244fb77826cd224 X-Google-Attributes: gidf74b3,public From: lawrence_rodrigues@my-dejanews.com Subject: Re: Create a jpeg Date: 1999/04/02 Message-ID: <7e2ff0$a8t$1@nnrp1.dejanews.com> X-Deja-AN: 461925188 References: <7e0784$l4k$1@jaydee.iway.fr> X-Http-Proxy: 1.0 x16.dejanews.com:80 (Squid/1.1.22) for client 192.94.123.19 Organization: Deja News - The Leader in Internet Discussion X-Article-Creation-Date: Fri Apr 02 13:07:48 1999 GMT Newsgroups: borland.public.jbuilder.java.language,comp.lang.java.beans,comp.lang.java.help,triangle.java X-Http-User-Agent: Mozilla/4.07 [en] (Win95; I)