0

hi
i want to know that what does the scale() method of AffineTransform do
i mean when we reduce the size of a image does this transform reduces the number of pixels or something else .........

3
Contributors
10
Replies
11
Views
9 Years
Discussion Span
Last Post by gauravmishra
0

Yes if you do down scale, function will reduce number of pixels and work out colour for each remaining pixel. Where if you scale up (enlarge) it will just spread the colour difference from pixel one to pixel two on the extra pixel received from enlragment

0

but when i tried to downscale an image and when i use .getHeight() and getWidth() on the modified image
it shows the older values.
that is i uses 800x800 image
and scale(0.5,0.5);
but still
height=800
width=800

0

this is wat i want to do
i have arbitrary sized small images of characters say of size 20x13 or 17x9 i want to convert these images to 10x10 how can i do this.

0

i am dealing with black and white images and when i tried scale them what i got was small 10x10 boxes filled with black colour.

0

i used the following code

public void actionPerformed(ActionEvent e)
        {
            int i,j,k,w,h;
            double w_scale=1.0,h_scale=1.0;
            drawimage=2;

byte[] comp = {0 , -1};
        IndexColorModel cm = new IndexColorModel(2,2,comp,comp,comp);
BufferedImage temp1=new BufferedImage(15,15,BufferedImage.TYPE_BYTE_INDEXED,cm);
            for(k=0;k<characters.size();k++)
            {
                BufferedImage temp=(BufferedImage)characters.get(k); //characters is ArrayList
                w=temp.getWidth();
                h=temp.getHeight();
                if(w>=15 && h>=15)
                {
                    w_scale=15/w;
                    h_scale=15/h;
                }
                else if(w<15 && h>=15)
                {
                    w_scale=1.0;
                    h_scale=15/h;
                }
                else if(w<15 && h<15)
                {
                    h_scale=15/h;
                    w_scale=1.0;
                }
                else if(w>=15 && h<15)
                {
                    w_scale=15/w;
                    h_scale=15/h;
                }
                AffineTransform t=new AffineTransform();

                t=AffineTransform.getScaleInstance(w_scale,h_scale);
                Graphics2D g=temp1.createGraphics();
                g.drawImage(temp,t,null);

                g.dispose();


                small_list.add(temp1);
                repaint();
            }
        }

Edited by Dani: Formatting fixed

0

Did it work or you having some problems with it?

PS: When posting code please use tags. In advanced options press hash sign "#" and that will automaticaly insert these tags for you. Just simple place your code between them

0

when i used above code and tried to print the modified images wat i get is black boxes.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.