Solved

URGENT:Changing Pixels within an image at run-time

Posted on 2003-12-06
8
199 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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Are you developing a Java application and want to create Excel Spreadsheets? You have come to the right place, this article will describe how you can create Excel Spreadsheets from a Java Application. For the purposes of this article, I will be u…
Introduction Java can be integrated with native programs using an interface called JNI(Java Native Interface). Native programs are programs which can directly run on the processor. JNI is simply a naming and calling convention so that the JVM (Java…
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 how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …

895 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

14 Experts available now in Live!

Get 1:1 Help Now