?
Solved

Changing the color of an image

Posted on 2003-03-03
17
Medium Priority
?
188 Views
Last Modified: 2010-03-31
Is there a way to have an image that is allready created be changed in java by passing in the color?
Say I create a circle that is black. Is ther anyway I can change this allready created image's color?
0
Comment
Question by:nywebsol
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
17 Comments
 
LVL 86

Expert Comment

by:CEHJ
ID: 8059250
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 8059268
0
 

Author Comment

by:nywebsol
ID: 8059280
When i mean created, I mean a created jpg made in like photoshop or something
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 86

Accepted Solution

by:
CEHJ earned 800 total points
ID: 8059309
Well, you'd get it as a BufferedImage and then you can do the above. Here's some code:

import com.sun.image.codec.jpeg.JPEGCodec;
import com.sun.image.codec.jpeg.JPEGImageDecoder;
import java.awt.image.BufferedImage;
import java.io.FileInputStream;
import java.io.IOException;
import javax.swing.*;
import java.awt.*;



public class Jpeg2BufferedImage {
  BufferedImage bufferedImage;
  JPEGImageDecoder decoder;

  public Jpeg2BufferedImage(String fileName){
    try {
      decoder = JPEGCodec.createJPEGDecoder(new FileInputStream(fileName));
      bufferedImage = decoder.decodeAsBufferedImage();
    }
    catch(IOException e){
      System.err.println("Error creating image");
      e.printStackTrace();
    }
  }

  public BufferedImage getBufferedImage(){
    return bufferedImage;
  }
}
0
 

Author Comment

by:nywebsol
ID: 8059314
When i mean created, I mean a created jpg made in like photoshop or something
0
 
LVL 92

Expert Comment

by:objects
ID: 8060841
No need to use JPEGImageDecoder to read a jpeg file.
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 8060872
True! Must have been an involuntary reflex on my part ;-)
0
 
LVL 2

Expert Comment

by:functionpointer
ID: 8062268
The links CEHJ posted show about the only way you can do that to a pre-created image.

Is what you are trying to accomplish along the same lines as your previous posts? I thought you were creating the images yourself???

If this still happens to be the case, you could wrap the image your own class, store the drawing operations you are performing, and just call the same op with a different color. For instance, if you draw a black square, store the op and the rect, poly, line, etc.  If you want to change it to a red square, get the same op/shape and re-perform it with the new color.
0
 

Author Comment

by:nywebsol
ID: 8064565
it is not an image i create. would be a red circle made in something like photoshop.... be able to read it in and change the red to another color is what i want to do.
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 8066132
The examples i posted are fine for this
0
 

Author Comment

by:nywebsol
ID: 8066494
okay, so i get the image as a buffered image with the code below and than i should follow steps on this link?
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 8066613
Yep.
0
 

Expert Comment

by:GnX
ID: 8071076
If you want to do a whole lot of things with images, check this out: http://www.ia.hiof.no/bildeb/imageprocAPI/.
0
 

Expert Comment

by:CleanupPing
ID: 9058953
nywebsol:
This old question needs to be finalized -- accept an answer, split points, or get a refund.  For information on your options, please click here-> http:/help/closing.jsp#1 
EXPERTS:
Post your closing recommendations!  No comment means you don't care.
0
 
LVL 35

Expert Comment

by:TimYates
ID: 9721284
No comment has been added lately, so it's time to clean up this TA.
I will leave a recommendation in the Cleanup topic area that this question is:

Accept CEHJ's comment as answer.

Please leave any comments here within the next seven days.

PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER!

TimYates
EE Cleanup Volunteer
0

Featured Post

New benefit for Premium Members - Upgrade now!

Ready to get started with anonymous questions today? It's easy! Learn more.

Question has a verified solution.

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

Java Flight Recorder and Java Mission Control together create a complete tool chain to continuously collect low level and detailed runtime information enabling after-the-fact incident analysis. Java Flight Recorder is a profiling and event collectio…
Introduction This article is the last of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers our test design approach and then goes through a simple test case example, how …
Viewers will learn about the regular for loop in Java and how to use it. Definition: Break the for loop down into 3 parts: Syntax when using for loops: Example using a for loop:
This theoretical tutorial explains exceptions, reasons for exceptions, different categories of exception and exception hierarchy.
Suggested Courses
Course of the Month9 days, 17 hours left to enroll

762 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