Solved

java.awt.image and pic morphing

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

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
advertisement module in core php 4 162
github account with ecipse 1 47
eclipse shortcuts 9 55
factorial example 4 40
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 …
In this post we will learn how to connect and configure Android Device (Smartphone etc.) with Android Studio. After that we will run a simple Hello World Program.
Viewers will learn about basic arrays, how to declare them, and how to use them. Introduction and definition: Declare an array and cover the syntax of declaring them: Initialize every index in the created array: Example/Features of a basic arr…
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 …

773 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