Solved

java.awt.image and pic morphing

Posted on 1997-11-18
2
216 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 100 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

Technology Partners: 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!

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…
In this post we will learn how to make Android Gesture Tutorial and give different functionality whenever a user Touch or Scroll android screen.
Viewers will learn about arithmetic and Boolean expressions in Java and the logical operators used to create Boolean expressions. We will cover the symbols used for arithmetic expressions and define each logical operator and how to use them in Boole…
This theoretical tutorial explains exceptions, reasons for exceptions, different categories of exception and exception hierarchy.

697 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