Solved

URGENT:Changing Pixels within an image at run-time

Posted on 2003-12-06
8
198 Views
Last Modified: 2010-03-31
Hi,
In my code, I am using an image of size 200*200. At run-time, I am calculating new values for a pixel, and need to change a few of the pixels. So, on my display, I only want to change the values of the changed pixels instead of drawing the entire image again. How can I do it in Java. What are the data types will i have to use?

This is an extremely urgent question. I need an answer as soon as possible.

Thanks,
0
Comment
Question by:miteshn
  • 4
  • 3
8 Comments
 
LVL 86

Expert Comment

by:CEHJ
ID: 9888548
You can use a PixelGrabber to get the pixels:

http://java.sun.com/j2se/1.4.2/docs/api/java/awt/image/PixelGrabber.html
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 9888553
You can also work with an ImageFilter:

http://javaalmanac.com/egs/java.awt.image/FilterRgb.html
0
 

Author Comment

by:miteshn
ID: 9889986
If I have my Image on a form, how do I reflect the changes on the image? I do not want to redraw the entire form. using Pixel grabber or ImageFilter, I can change the array values, but how do i reflect these changes on screen?

thanks
0
 
LVL 92

Accepted Solution

by:
objects earned 250 total points
ID: 9890180
Use a BufferedImage, it allows you to change individual pixel values.
Then call repaint() on the component displaying the image to show changes on screen.
0
Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

 
LVL 92

Expert Comment

by:objects
ID: 9890488
eg. if the image was painted at the origin of your component and you wanted to change the pixel at 10, 10:

mybufferedimage.setRGB(10, 10, rgb);
repaint(10, 10, 1, 1);

0
 
LVL 86

Assisted Solution

by:CEHJ
CEHJ earned 250 total points
ID: 9891866
If you want to use a BufferedImage, the easiest way to get one is:

BufferedImage image = ImageIO.read(new File("x.jpg"));
   
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 9892090
8-)
0
 
LVL 92

Expert Comment

by:objects
ID: 9892999
0

Featured Post

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
Introduction This article is the second of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers the basic installation and configuration of the test automation tools used by…
Viewers will learn one way to get user input in Java. Introduce the Scanner object: Declare the variable that stores the user input: An example prompting the user for input: Methods you need to invoke in order to properly get  user input:
Viewers will learn about if statements in Java and their use The if statement: The condition required to create an if statement: Variations of if statements: An example using if statements:

757 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now