By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
431,883 Members | 1,952 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 431,883 IT Pros & Developers. It's quick & easy.

Image manipulation in applications

P: n/a
Hi.

I'm doing some image manipulation in an applet using the example code on
this page:
http://www.akop.org/art/pixels3.htm

However, I really want an application rather than an applet, I just
can't figure out how to do the image loading and manipulation when it's
not from inside an applet. Any hints on the subject are appreciated.

Thanks in advance,

Rune
--
http://runevision.com
Jul 17 '05 #1
Share this Question
Share on Google+
4 Replies


P: n/a
"Rune Johansen" <rune[insert_current_year_here]@runevision.com> wrote in message news:<eN**********************@news000.worldonline .dk>...
Hi.

I'm doing some image manipulation in an applet using the example code on
this page:
http://www.akop.org/art/pixels3.htm

However, I really want an application rather than an applet, I just
can't figure out how to do the image loading and manipulation when it's
not from inside an applet. Any hints on the subject are appreciated.

Thanks in advance,

Rune

If its java.awt.Component or its descendants, write its paint()
method. Or if it's javax.swing.JComponents, write its paintComponent()
method. These two methods take a Graphics object as their argument,
and the Graphics object can be readily casted into a Graphics2D
object. Those Graphics and Graphics2D objects have various drawing
methods including those that draw existing images on your component.

Examples abound on the net.
Jul 17 '05 #2

P: n/a
"Rune Johansen" <rune[insert_current_year_here]@runevision.com> wrote in message > However, I really want an application rather than an applet, I just
can't figure out how to do the image loading and manipulation when it's
not from inside an applet. Any hints on the subject are appreciated.

Thanks in advance,

Rune


For loading and saving images, you have several options:

Use javax.imageio.ImageIO is the easiest way to load images. It
currently can only handle JPEG, GIF and PNG, but with Java1.5 should
be able to load TIFFs too. ImageIO.read() will read your images and
ImageIO.write() will write them.

The other main way to load images is through the Toolkit.
java.awt.Toolkit.getDefaultToolkit().getImage(file name) will load any
GIF, JPEG or PNG.

If you used the first method to load your image, you'll have a
BufferedImage who's data you can access directly.

If you used the second method, you'll have an ordinary Image. You can
read it's data by creating an array to hold pixel data, then creating
PixelGrabber and calling grabPixels() to get the data. To turn your
data back into an image, you'll need to create a
java.awt.image.MemoryImageSource.

While the first method is much easier to use, the second method is, in
my experience, much faster. The second method is the 'classic' way to
manipulate images.

There is also a way to do all of this with the Java Media Framework,
but I've been unable to figure out how to use it. The docs for it
contain much information, but are nearly impossible to learn from.

Mark McKay
--
http://www.kitfox.com
Jul 17 '05 #3

P: n/a
sorry I put this in the wrong place

I managed to do this with ImageIO, example taken from:

http://www.geocities.com/marcoschmid...creenshot.html

watch out for the javascript errors, but good site with loads of image and
java stuff...

This was the code I used.

// temp output file bit
public void outputFile() throws Exception{
//start of the output stuff

FileOutputStream fo = new FileOutputStream("myImg.jpg");//name of image

BufferedOutputStream bo = new BufferedOutputStream(fo);//set to buffered
stream

//destination here is the name of the raster reference. referencing a
bufferedImage
ImageIO.write(destination, "jpeg", bo);//write the file out using ImageIO
to the HD

bo.close();
//end of the output stuff
}
// EOF temp outupt file bit

hope this helps

cheers
Martin

From: "Murray" <pa***@SPAMoffSPAMMER.optusSP4Mnet.com.au>
Subject: Re: Saving a BufferedImage as a JPEG
Date: 07 May 2004 16:49
"Michael Johnston" <mi****************@saic.com> wrote in message
news:72**************************@posting.google.c om...
I am saving a BufferedImage as a JPEG file under Windows XP.
I am using the JAI JPEGImageEncoder class.
The JPEG is saved as CMYK but I need RGB.
I cannot figure out how to get RGB. Any help?
Where is the BufferedImage coming from? If you're creating the object
yourself, try using INT_RGB imageType instead of the default ARGB.

image = new BufferedImage(x, y, BufferedImage.TYPE_INT_RGB);

It might also be worth trying this:

JPEGImageEncoder encoder = JPEGCodec.createJPEGEncoder(os);
JPEGEncodeParam param = encoder.getDefaultJPEGEncodeParam(image);
encoder.encode(img, param);

--

---------------
http://www.nonstoploop.co.uk/ - dynamic websites
http://www.rossanobacchin.be/ - fine art
http://www.weycameras.co.uk/ - photographic supplies
---------------

"Rune Johansen" <rune[insert_current_year_here]@runevision.com> wrote in
message news:eN**********************@news000.worldonline. dk... Hi.

I'm doing some image manipulation in an applet using the example code on
this page:
http://www.akop.org/art/pixels3.htm

However, I really want an application rather than an applet, I just
can't figure out how to do the image loading and manipulation when it's
not from inside an applet. Any hints on the subject are appreciated.

Thanks in advance,

Rune
--
http://runevision.com

Jul 17 '05 #4

P: n/a
what kind of app are you working on or is this some sort of extended
assignement ?

news.skynet.be wrote:
sorry I put this in the wrong place

I managed to do this with ImageIO, example taken from:

http://www.geocities.com/marcoschmid...creenshot.html

watch out for the javascript errors, but good site with loads of image and
java stuff...

This was the code I used.

// temp output file bit
public void outputFile() throws Exception{
//start of the output stuff

FileOutputStream fo = new FileOutputStream("myImg.jpg");//name of image

BufferedOutputStream bo = new BufferedOutputStream(fo);//set to buffered
stream

//destination here is the name of the raster reference. referencing a
bufferedImage
ImageIO.write(destination, "jpeg", bo);//write the file out using ImageIO
to the HD

bo.close();
//end of the output stuff
}
// EOF temp outupt file bit

hope this helps

cheers
Martin

From: "Murray" <pa***@SPAMoffSPAMMER.optusSP4Mnet.com.au>
Subject: Re: Saving a BufferedImage as a JPEG
Date: 07 May 2004 16:49
"Michael Johnston" <mi****************@saic.com> wrote in message
news:72**************************@posting.google.c om...
I am saving a BufferedImage as a JPEG file under Windows XP.
I am using the JAI JPEGImageEncoder class.
The JPEG is saved as CMYK but I need RGB.
I cannot figure out how to get RGB. Any help?

Where is the BufferedImage coming from? If you're creating the object
yourself, try using INT_RGB imageType instead of the default ARGB.

image = new BufferedImage(x, y, BufferedImage.TYPE_INT_RGB);

It might also be worth trying this:

JPEGImageEncoder encoder = JPEGCodec.createJPEGEncoder(os);
JPEGEncodeParam param = encoder.getDefaultJPEGEncodeParam(image);
encoder.encode(img, param);



Jul 17 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.