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 .........

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

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

does this scale also works with black and white images
ie TYPE_BYTE_INDEXED

Scaling the transform does not reduce the size of the Image object itself.

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.

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.

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();
            }
        }

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

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

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.