Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / April 2007

Tip: Looking for answers? Try searching our database.

BufferedImage Scaling

Thread view: 
artem - 07 Apr 2007 20:53 GMT
Hello all,
i am trying to wright a simple program where i have an image in a
file. I load it in to a BufferedImage and scale it, and then i want to
be able to set the position from the source code.

it works like this. i have 2 BufferedImages i load an image in to them
in the constructor. in the paint method i want to scale img and save
the scaled img to offimg, and the set the position of offimg and draw
it.

here is the source:

BufferedImage img = null; // colored Square
BufferedImage offimg = null; // black Square

    Test1Cont(){
        try {
           img = ImageIO.read(new File("wSquare.bmp"));
           offimg = ImageIO.read(new File("bSquare.bmp"));
        } catch (IOException e) {}
    }

    public void paint(Graphics g) {
       Graphics2D g2d = (Graphics2D) g;
       g2d.fillRect(0, 0, getWidth(), getHeight());
       AffineTransform tx = new AffineTransform();
       tx.scale(5, 5);

       offimg.createGraphics().drawImage(img, tx, null);
       g2d.drawImage(offimg,x,y,null); //set the size with x and y
    }

thanks all
Knute Johnson - 07 Apr 2007 22:19 GMT
> Hello all,
> i am trying to wright a simple program where i have an image in a
[quoted text clipped - 29 lines]
>
> thanks all

Do you want to save the offimg to a file?  Or do you just want to draw
it at some scale?  I suggest you do all of your scaling with the
drawImage() method.

Signature

Knute Johnson
email s/nospam/knute/

artem - 08 Apr 2007 01:48 GMT
On Apr 7, 5:19 pm, Knute Johnson <nos...@rabbitbrush.frazmtn.com>
wrote:
> > Hello all,
> > i am trying to wright a simple program where i have an image in a
[quoted text clipped - 38 lines]
> Knute Johnson
> email s/nospam/knute/

i just want to draw it at a different scale. ok ill try using
drawImage
tnx
artem - 08 Apr 2007 03:17 GMT
> On Apr 7, 5:19 pm, Knute Johnson <nos...@rabbitbrush.frazmtn.com>
> wrote:
[quoted text clipped - 45 lines]
> drawImage
> tnx

ok i got it to works with drawImage. didnt know you could do it with
that. i looked in the tutorial and they where using scaling so i tried
too. lol
Rupert Woodman - 08 Apr 2007 13:35 GMT
When would you use the AffineTransform class?  I see that in this case it
can be done with the Graphics2D.drawImage() method, so why does the
AffineTransform class exist at all?  I'm currently using the AffineTransform
class to rotate an image - is that also the wrong thing to do?

Many thanks
Rgds

Rupert

>> Hello all,
>> i am trying to wright a simple program where i have an image in a
[quoted text clipped - 33 lines]
> at some scale?  I suggest you do all of your scaling with the drawImage()
> method.
Knute Johnson - 08 Apr 2007 17:48 GMT
> When would you use the AffineTransform class?  I see that in this case it
> can be done with the Graphics2D.drawImage() method, so why does the
[quoted text clipped - 5 lines]
>
> Rupert

artem was just drawing an image at some scale.  In your case, rotating,
or if doing some more complicated transform, you need the Graphics2D
method with the AffineTransform argument.  I was just trying to make it
less complicated for artem.

Signature

Knute Johnson
email s/nospam/knute/



Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.