?
Solved

java.awt.image and pic morphing

Posted on 1997-11-18
2
Medium Priority
?
218 Views
Last Modified: 2008-02-26
Can someone suggest how one would go about this: I have a picture at a fine resolution that is of a fiber in a weave as in a schematic. I want to go to finer detail and then blur the image and end up with a finished product as in a woven label.  Any information on how to accomplish this feat? Thanx for your time its appreciated.
Regards,
Gary S. McKenzie
0
Comment
Question by:gene97
[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
  • 2
2 Comments
 
LVL 4

Accepted Solution

by:
rembo earned 200 total points
ID: 1230911

You need two things an image filter to fade your
image.  Image filters work like this:


import java.awt.image.*;

/**
 * A derivation of RGBImageFilter that turns an image
 * into its negative.<p>
 *
 * @version 1.0, January, 1997
 * @author  David Geary
 * @see     RGBImageFilter
 */
public class NegativeFilter extends RGBImageFilter {
    public NegativeFilter() {
        canFilterIndexColorModel = true;
    }
    public int filterRGB(int x, int y, int rgb) {
        DirectColorModel cm =
            (DirectColorModel)ColorModel.getRGBdefault();

        int    alpha = cm.getAlpha(rgb);
        int    red   = cm.getRed  (rgb);                                               int    green = cm.getGreen(rgb);
        int    blue  = cm.getBlue (rgb);

                red   = Math.abs(255 - red);
                green = Math.abs(255 - green);
                blue  = Math.abs(255 - blue );

                alpha = alpha << 24;
        red   = red   << 16;
        green = green << 8;

        return alpha | red | green | blue;
    }
}    

Once you've created the image filter you get the ImageProducer
from the image:

ImageProducer ip = image.getSource();

Then:

FilteredImageSource fis = new FilteredImageSource(ip, filter);

This applies the filter to the image.  

Image newImage = new Image(fis);

So, now you have a new image with the filter you need applied
to it to fade it (you'll have to tweak the filter).

For the magnify portion, you can use the drawImage method
of the Graphics class that allows you to size something.

g.drawImage(-20,-20,img.getWidth(null)*2, image.getHeight(null)*2, this);

This will start the image back in the frame by 20 pixels and
draw it twice as large as normal, this displays a magnified
portion.

Hope that helps,

-Tony


                                                           
0
 
LVL 4

Expert Comment

by:rembo
ID: 1230912

Did you have any luck with this?

0

Featured Post

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

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

An old method to applying the Singleton pattern in your Java code is to check if a static instance, defined in the same class that needs to be instantiated once and only once, is null and then create a new instance; otherwise, the pre-existing insta…
Java had always been an easily readable and understandable language.  Some relatively recent changes in the language seem to be changing this pretty fast, and anyone that had not seen any Java code for the last 5 years will possibly have issues unde…
This tutorial covers a practical example of lazy loading technique and early loading technique in a Singleton Design Pattern.
This tutorial will introduce the viewer to VisualVM for the Java platform application. This video explains an example program and covers the Overview, Monitor, and Heap Dump tabs.
Suggested Courses
Course of the Month10 days, 19 hours left to enroll

770 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