Solved

java.awt.image and pic morphing

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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
mapShare challenge 13 69
word0 challenge 4 54
mockito example issue 8 38
github account with ecipse 1 20
This was posted to the Netbeans forum a Feb, 2010 and I also sent it to Verisign. Who didn't help much in my struggles to get my application signed. ------------------------- Start The idea here is to target your cell phones with the correct…
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 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…
The viewer will learn how to implement Singleton Design Pattern in Java.

747 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

Need Help in Real-Time?

Connect with top rated Experts

8 Experts available now in Live!

Get 1:1 Help Now