473,387 Members | 1,573 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Image manipulation in applications

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
4 5417
"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
"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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: Giggle Girl | last post by:
Overall Background: I am in charge of migrating an already-made Content Mangement System from ASP to PHP. I do not know PHP -- yet! I am trying to foresee potential issues, and here is one. ...
2
by: | last post by:
Hello All, I am writing a web application that reads a bitmap from a file and outputing it to a HTTP response stream to return the image to the requesting client. The image file is a regular...
9
by: Job | last post by:
Hi, I would like to find out what ASP/ASP.net can do with image manipulation. Does ASP have built in functions (eg. after upload to server) to manipulate images, like rotate, scale, crop etc.?...
15
by: David Lozzi | last post by:
Howdy, I have a function that uploads an image and that works great. I love ..Nets built in upload, so much easier than 3rd party uploaders! Now I am making a public function that will take the...
9
by: zacariaz | last post by:
I dont know, and i dont much like javascript, however, i am told that the only way to do want i want to do, is with javascript, so here goes. zoom and cut is the only features i need. 1. the...
10
by: Pulzar | last post by:
Hi there, I want to show a simple image on a web page, and allow the viewer to select and change one of the colours used in the image, and immediately preview the result. I'd like to keep the...
3
by: jon | last post by:
Hello, I've had long standing code that runs in IE, that I'm testing with firefox unsuccessfully now. The problem seems to be that images that I dynamically create don't fire their onload event...
8
by: shotokan99 | last post by:
i have this situation. i have a query string: http://www.myquerystring.com?x=xxxxx what this url does is it will return or start downloading a .png file. what i wanted to do is trap this png...
12
by: laredotornado | last post by:
Hi, I'm using PHP 5. I was wondering given an image, a.jpg, how can I make an image that would look like you slid a white index card (which I have a file, white.jpg with the same dimensions as...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.