Solved

java.awt.image and pic morphing

Posted on 1997-11-18
2
214 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
  • 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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

Suggested Solutions

After being asked a question last year, I went into one of my moods where I did some research and code just for the fun and learning of it all.  Subsequently, from this journey, I put together this article on "Range Searching Using Visual Basic.NET …
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…
Viewers learn about the “while” loop and how to utilize it correctly in Java. Additionally, viewers begin exploring how to include conditional statements within a while loop and avoid an endless loop. Define While Loop: Basic Example: Explanatio…
This video teaches viewers about errors in exception handling.

808 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