Scale image strange problem

Hi
I have loaded an image using MovieClipLoader and am using the following code to scale it to fit a photo frame:
var mcLoader:MovieClipLoader = new MovieClipLoader();
..  add listeners ...
mcLoader.loadClip(filePath, frame.imageHolder);
function loadInitEventHandler(target_mc:MovieClip):Void
var scale:Number = Math.min(frameWidth/target_mc._width * 100, frameHeight/target_mc._height * 100);
target_mc._width = scale;
target_mc._height = scale;
The code works for most of the images except images with resolution 2880 x 2880.  It did not scale properly - part of the image on the right does not show. Please see images below.  The lower image scaled properly, but the upper one did not.
The math seems to be correct and I do not know what the problem is.
Any help is appreciated!
Thanks in advance!

I checked the resolution of the image on the web server.  It is more than 2880 x 2880.  I thought the image resolution was 2880 x 2880 at first because I run a trace and it says 2880 x 2880.  Probably Flash changes the resolution to 2880 x 2880.
Thanks for the help!

Similar Messages

  • Rollover image : strange problem

    Hello,
    I've got a very strange problem :
    I recently bought a new PC (ACER Aspire M5641, with Vista
    32), and installed Adobe Web Standard CS4 (to replace my DW 8 and
    FW 8).
    I make rollover images with FW for years without problem
    (i.e. without having to configure anything on the soft or the OS).
    Since I work with the new setup, each time I test my rollover
    image on Firefox or IE 8, when clicking on the test (not on hover)
    image, I got a "red-then-blue" point appearing on the top left of
    the image.
    Any Idea ?
    Many thanks for your help. I'm stuck.

    Can you post the png file?

  • View –Cover Flow View-Grey scale images

    View –Cover Flow View-Grey scale images
    Hi. No problems when I view my album covers in either [List View] or [Album View]. When I use [Cover Flow View] I get distorted lines, less than even a blurred image, in fact grey scale. Seems strange that iTunes can display in [List View] or [Album View], but not in [Cover Flow View]. Any ideas? Thanks.

    I don't know the answer to this so a couple of suggestions, are you on the latest version of iTunes that is compatible with Windows 2000?
    If not you can download it here:
    http://www.apple.com/support/downloads/itunes732forwindows2000.html
    Are you upto date with your DirectX for Windows 2000? Although looking at the MS website it doesn't look as though there is anything particularly new:
    http://www.microsoft.com/downloads/details.aspx?FamilyID=7c61e5da-8c60-43f6-9549 -65b93cf6f987&DisplayLang=en
    Also check your computer manufacturer's support website to make sure you are upto date with your drivers etc.

  • Strange problem in PS CS4 32-bit only

    I'm having a rather odd problem and haven't been able to find any discussions of something similar. I'm running Windows Vista Ultimate 64 SP1. I have both the 32- and 64-bit versions of PS CS4 installed with the latest updates.
    64-bit PS works like a champ. I love it. Were it not for a variety of plug-ins I use which are not yet 64-bit enabled, I would never use the 32-bit version of PS. However...
    When running 32-bit PS, the program acts as though I have some key or mouse button either pressed or like I'm repeatedly pressing a key. Sort of. It doesn't try to do something on its own - that is, if I open a file and sit here doing nothing, PS won't do anything on its own. I will, though, see the cursor flashing oddly.
    If I attempt to do anything, I end up fighting with the "phantom" keys. Sometimes, I need to press a key several times before it reacts. Often, I'll get warning sounds like you hear when you press a wrong key for a particular state. Certain actions won't hold sufficiently long to let me do something. I just ran into a stubborn problem like this. If I click the crop tool, I cannot type into the width, height, or resolution boxes on the tool bar. I can click there, see a vertical cursor appear for an instant, then it's gone.
    This is driving me nuts. I wish my plug-in vendors would get their acts together and add 64-bit compatibility, but so far only Imaginomic has done so with Noiseware (and I'm grateful to them!).
    Other info: I'm running with a bluetooth mouse and keyboard as well as an Intuous 3 tablet. I have an nVidea GeForce 8600 GT video card. I've tried disabling OpenGL in PS without help. Note again, 64-bit PS works brilliantly with all these. I'm running plug-ins from OnOne (Plugin Suite 4) and Nik (Viveza) as well as Noiseware mentioned above. I tried logging in with my wife's ID to see if any of my settings might be to blame, but it behaves the same with her ID. I'm not sure if this problem showed up with the PS update or if it was there from the start. I'm thinking it did not show this problem when I first upgraded to CS4. I was using CS2 previously, and it's still installed on this computer. It does not exhibit this problem.
    Any ideas or suggestions?
    Tony

    Mylenium - thanks. I also was suspicious of the tablet, but the tablet is not in use when this problem shows up. Nevertheless, I uninstalled the Wacom driver, removed the tablet connection, rebooted, and the problem persists. But, I did get a chance to install a new version of the driver (April 2009).
    Like I said - strange problem. Since it doesn't crash PS, there's not much data. No error message, no stack trace.
    One other tidbit. I still have the crop tool selected. If I load an image and place the cursor over the image window, the cursor changes between the crop cursor and the big white arrow. Back and forth. When it's doing this, if you want to use the selected tool, you have to click right when the tool's cursor is showing, otherwise you get the "bing" noise.

  • Displaying dynamically changing image: a problem with JLabel.

    Hello! I use NetBeans 5.5 and I develop my GUI with Matisse. I'm rather a beginner in developing GUIs with this editor...
    I'd like to display a dynamically changing image. The idea is: GUI shows the image, that is modified as some computations run in a different thread. App will be run on a single machine.
    I'm trying to display the image as a label's icon. The problem is that my app's frame can be resized - and when it is, the label also resizes. When the label is resized, the image should also be resized - the image should always be of the same size as the label. The problem? I noticed, that it works only when I make my app's bigger. When I try to lower its dimensions, the label's dimensions remain the same. Why the label don't make its size smaller?
    My code works as follows: when app's main frame is resize, the panel (the one, that the label is placed in) is also resized. And, since the label is in the panel, it (should) also be resized. So I wrote all the resize-events handlers (therefore I know that the resize event is sent when my app's frame is resized, and when the panel is resized - but the label is resized only when it grows bigger). In this methods I modify the image displayed in the label (I resize the image).
    Or, perhaps, there is some other way to show a (dynamically changing) image with Swing... I chose JLabel, because I didn't want to write my own JComponent. JLabel can display image and that is all I need. The problem is: when the label grows bigger, I create a new, bigger image (icon). Why my label don't get smaller (the resize event isn't even sent)?

    There is no component that dynamically resizes an image. You need to create your own. Something like this:
    JComponent component = new JComponent()
         protected void paintComponent(Graphics g)
              //  Scale image to size of component
              g.drawImage(yourImage, 0, 0, getWidth(), getHeight(), null);
    };

  • Strange problem while login to SCN in Internet explorer

    Dear All,
    I am facing a strange problem, where i am unable to login into SCN through Internet explorer, as when i click logon button a blank screen is coming and the login screen is not opening.Its happening  both in my office and house.
    This question i am posting through google chrome, where i am able to get the below screen.
    The attached image is what i am getting i am talking about
    Is this problem coming for everyone,kindly let me know.As in my office we are using only Internet explorer and i am unable to work on SCN.
    Kindly let me know bout it.Since i am active in this module, i am posting the question here.
    Thanks&Regards
    Darshan Desai

    Hi,
    Please repost at SCN Support to get quick solution.
    IE 9 is best suitable for our forum. IE 11 is not working as required. I am also using Google Chrome at home. But at office i am using  IE9.
    Thanks & Regards,
    Nagarajan

  • Strange problem in applet application

    Hello Everybody,
    I hava an applet whit an image. This image has to changed by color, and text has to be added to the image. The text color is also changable. Here is where it goes wrong.
    When I change the background color of the applet, the transparant image will be colored. This is good.
    At the start text can be added.
    When you change the textcolor, the frame with the JColorChooser will get at the background of the image, like this:
    [http://schaftwagen.ncamade.nl/schaftwagenfout.png|http://schaftwagen.ncamade.nl/schaftwagenfout.png] (image)
    When you change the text with the "opschrift" button (vertical text) the old text stays under the new text.
    When you change the background after this, everything seems to be okay.
    At an other forum I've asked this question, and some of that people didn't had this "problem". I am using Windows 7RC with the newest java version. Tested it on an Windows vista and Windows XP all with the same problem.
    The source is to big for this forum and can be found at [http://www.dreamincode.net/forums/showtopic117029.htm|http://www.dreamincode.net/forums/showtopic117029.htm]. This is the other forum, where I've asked about his issue. (I hope this link isn't against the rules to post this link to the other forum?)
    I hope someone can help me with this problem. The applet can be tested here: [http://schaftwagen.ncamade.nl/colorchooser.asp|http://schaftwagen.ncamade.nl/colorchooser.asp]
    Greats,
    C.H.F.S.
    Edited by: C.H.F.S. on Jul 28, 2009 4:01 AM

    I've just tested it on different boxes, and sometimes it does work indeed, but sometimes other problems come up. On one the background color doesn't change but the text color does it right and changing the text work also correctly in that case.
    Can anyone help me please solving this strange problem?

  • Problem: codebase, jar and image reloading problem please help!

    Hi Java Gurus,
    I have written an applet that extends JApplet for viewing webcam. In order to reduce the download time I put my classes into a doorcam.jar file. The following is my <applet> tag in my html file.
    <applet code="CameraApplet.class"
    archive="doorcam.jar"
         codebase = "webcam/classes"
         width="375" height="475">
    <param name="imagePath" value="http://judge/webcam/images">
    <param name="webCamImage" value="door.jpg">
    <param name="COMPort" value="COM2">
    <param name="frameRate" value="10"> <!-- could not exceed more than 10-->
    <param name="host" value="judge">
    </applet>
    The fist problem is that my class file does not get loaded from the jar file if i provide the "codebase" attribute as above. Instead the browser load every single class file from the webserver. This has some problem too. Coz the browser sometimes just thorough NullPointerException or ClassNotFoundException. After much of debugging I found out that the problem is the IE browser which seldom fails to load classes or image file from the server. If i referesh the browser the applet and all its classes loaded successfully and runs smoothly. This behaviour never occurs when running with "appletviewer".
    I wanted all my classes to be loaded from my jar file. After much of trial and error I found out that if i remove "codebase" attribute the browser loads the classes from my jar file and applet loads very fast. This is where the second problem comes in. The browser does not reload my webcam image file so that the webcam become alive with live images, like before.
    If I run on "appletviewer" everything works fine my web cam is displayed properly. But in IE browser the image does not get reloaded when I refresh my image to give live to my webcam display. The refresh method is given below.
    private void refresh(final URL url) {
    Image webCamImage =getImage(url);
    webCamImage.flush(); // flush out the previous image
    webCamImage = getImage(url); // get a new image
    webCamImageIcon.setImage(webCamImage); webCamImageIcon.paintIcon(webCamLabel, webCamLabel.getGraphics(), 15, 15);
    When I add the "codebase" attribute back, the image gets reloaded for every refresh() and everything works fine. But the classes are also loaded from the server. And occasionally also suffers Class loading and image loading problem. As I presented earlier, when I do refreshing in the browser everything gets loaded and the applet function correctly with web cam displaying very well.
    The problem is so strange that I could not find any way to solve it.
    It would be a great help to me if somebody provide me some work around to the problem.
    I tested on Windows 2000, Windows XP, IE 5.5, IE 6 with J2SDK 1.4.0.
    Thank you all very much in advance.
    best regards,
    Judge

    Thank you so much for the suggestions. I did tried the way u suggested. The problem still the same.
    I think its the problem between IE browser and Java Plug-in.
    I which SUN would find these incompatibilities and solve these problems.
    I even tried using java SDK and plug-in 1.4.1 it even worst. It can't even load an applet. And it does not show any loading messages nor any error messages. It just show a cross sign on the upper left coner.
    I would be so glad, if Sun would try to eliminate the inconsistancies such as caching, loading, initializing etc between browser and its Java plug-In. For example, applets behave well in appletviewer and behave unpredictably in browser environment.
    I have seen so many people in the forums with all sorts of problems because of this.
    Right now I m desperately looking for work around to my problem.
    If somebody would provide me with the solution to my problem it would be a great help to me.
    thank you all so much.
    best regards,
    Judge

  • Images and image field problem

    Hi
    I would like the user to be able to upload an image that will be scaled proportionally to the size of the field pre determined.
    I understand that options of image field: "scale image proportionally" is meant for this exactly.
    For some reason, this works with images but not with image fields.
    please see a printscreen I have made of the problem: same field size and same image uploaded
    thanks

    In Lightroom, there is no specific location where the photos should go. You can put them wherever you want, based upon your storage needs and hard drive setup.
    So, with regards to your specific question, yes you can put the photos in the same folder as where the .lrcat is located, I can't see any harm, but I also don't think you need to do the work to make that happen. You can pretty much leave your photos where they are (which is easier and less time consuming) than moving them to the .lrcat folder, and easier and less time consuming than moving them at all.
    In fact, I strongly suggest you change your thought processes from "Where do I put my photos" to "How can I organize my photos". Now that you are a Lightroom user, you organize your photos from within Lightroom, not by moving them here to there, but by adding keywords and other metadata. Organizing, now that you are LR user, is not folders ... it is metadata. Searching, now that you are a LR user, is not done in your operating system and in folders, it is done in LR by searching for keywords and other metadata.

  • Strange Problem While Recording

    I have a PushBufferStream that I separated in 4, because the first one have 4 videos multiplexed. Then I tried to record one of the new PushBufferStreams by wrapping it in a new DataSource in a new Processor. I created the DataSink and started to record and it worked well. But the video file generated (an .AVI) have a strange problem. It has the duration of the original DataSource, not the duration of the recording time. If I start the original DataSource now and after one minute record the PushBufferStream by 5 seconds, the video file created have 1minute and 5 seconds. In the first image just a static image (the first frame) is shown, and in the lasts 5 seconds the video is shown normaly.
    Does anyone could help me, I don�t know what could I do to solve the problem? Thanks.

    just a thought, check how much memory your app is using, is it storing a minuites worth of video in memory, then when yu record for your five seconds, it's dumpng the whole lot into your avi file.
    maybe empty your buffer before you record.

  • Nokia 3250:A very strange problem...

    hi..i'm facing a very strange problem in my handset 3250.. i've upgraded its os but still there is problem: http://discussions.europe.nokia.com/discussions/bo​ard/message?board.id=smartphones&;message.id=9102#M9102 any idea about such type of problem.....

    MR.,
    what is firmware?? How can i have its latest edition??
    Can you help me because i too have the same problem:
    Problem 1:
    1-I install any software (e.g:snake game) through Application manager (Pc Suit) in memory card.
    2-I launch that software (snake game) just after installation it works properly.
    3-Now i switch-off the hand set and than switch-on it.
    4-I try to launch that software (snake game) again but it doesn't response.
    Problem 2:
    1:There is a image in my Memory card.
    2: I set that image as a wallpaper.
    3-Now i switch-off the hand set and than switch-on it.
    4-Wallpaper reset to default one.
    Problem 3:
    1-I install a theme through Application manager (Pc Suit) in memory card.
    2: I apply that theme in my hand set.
    3-Now i switch-off the hand set and than switch-on it.
    4- Now theme reset to default one.

  • Strange problem with color measure in Mac.

    Hello, I am having a strange problem with color measure in Mac. For example i create a gradient in Photoshop from color 200 200 200 to color 240 240 240. When i measure the color of the gradient with the color measure tool of Photoshop or with the built in OS X color measure tool the measured color is from 200 199 197 to 240 240 238. I have measured the same gradient with Photoshop for PC and the values are OK (the same values that i create).
    I dont know what is the problem, but i belive that the colors that i create would be the same that i measure after creating them, and also the same values between Mac and PC. I will appreciate it a lot any help or information that you could give me that helps me to understand what is happening here.
    Thank you for your time
    Marcelo.

    Yep you got it, proof as monitor basicaly strips out any profiling and just delivers it straight.
    is there any way to make the OS X color measure tool to measure the original color values
    You mean the document colors - No, like I said photoshop is filtering your image through document profile, proof setup and monitor profile. Why do you want to use Digital color meter anyway for this?
    i dont understand what is the point to measure color values that will change every time a calibrate my monitor.
    Because color values are 'bigger' than whats on your monitor. Your monitor (via photoshop) is only doing the best it can to display those values - which can be anything from LAB colors outside the gamut of your monitor - to CMYK colors. Calibrating it is the only way to allow your monitor to do this in any way accurately. (not ever really possible) Monitors have a certain gamut and are only dispays/representations of the REAL colors that a document, with a profile, holds. So there's only one good reason to measure monitor values, and that's to generate a monitor profile.

  • Strange Problem with Mail & Address Book

    Hi,
    I'm having a strange problem with Mail & Address Book.
    When I go to compose a new message from Mail and hit the Address button (to show my email addresses), it won't launch the contacts window!
    I get this log from console;
    2007-10-15 22:55:59.079 Mail[410] * -[NSCFArray objectAtIndex:]: index (0) beyond bounds (0)
    If I try to launch the Address Book from my Applications folder, it won't open, and it gives me this log from console;
    2007-10-15 22:57:57.348 Address Book[417] * -[NSKeyedUnarchiver initForReadingWithData:]: data is NULL
    Oct 15 22:57:57 PB-G4 /Applications/Address Book.app/Contents/MacOS/Address Book: CGImageSourceCreateWithData data parameter is nil\n
    2007-10-15 22:57:57.350 Address Book[417] Don't know about packed image EditLeftCapStd
    2007-10-15 22:57:57.350 Address Book[417] Exception raised during posting of notification. Ignored. exception: * -[NSCFArray addObject:]: attempt to insert nil
    If I quit Address Book, i'll get this from console;
    2007-10-15 22:58:37.892 Address Book[417] -[ABAddressBook setDefaultCountryCode:] called with a unknown country code 'us'
    I tried deleting the preferences, re-installing Address Book, also tried creating a new user, again no luck!
    Can somebody help!!!
    Please?!

    Hi dp13.
    Do you have any Address Book plug-ins or system utilities that could interfere with Address Book? In the Finder, go to each of the following folders (if they exist). What do you see there?
    /Library/Address Book Plug-Ins/
    ~/Library/Address Book Plug-Ins/
    To make accurately reporting this information easier, you may open /Applications/Utilities/Terminal, type the following command (you can just copy it here and paste it in Terminal), and press <Return>. You can then copy the output of that command from Terminal and paste it in your reply to this post:
    ls -1 /Library/Address\ Book\ Plug-Ins ~/Library/Address\ Book\ Plug-Ins
    Note: For those not familiarized with the ~/ notation, it refers to the user’s home folder. You can easily locate any of the folders referred to in this post by copying the folder path here, doing Go > Go to Folder in the Finder, and pasting the folder path there.
    <hr>
    Did you also reinstall the appropriate Combo Update after reinstalling Address Book?
    Quit all the applications and verify/repair the startup disk (not just permissions), as described here:
    The Repair functions of Disk Utility: what's it all about?
    After having fixed all the filesystem issues, if any, reinstall the Combo Update for the type of computer and the version of Mac OS X you’re using, unless this is the version of Mac OS X that came with the computer:
    About the Mac OS X 10.4.10 Combo Update
    Mac OS X 10.4.10 Combo Update for PowerPC
    Mac OS X 10.4.10 Combo Update for Intel
    After installing the Combo Update, the computer may restart twice and the first restart may take several minutes. This is normal.
    Take a look at the following articles for guidelines on how to properly install system updates:
    Troubleshooting installation and software updates
    Installing software updates
    Basically, you should verify/repair the startup disk and back up before installing the update, no applications should be running while installing it, and you may experience unexpected results if you have third-party system software modifications (not normal applications) installed.

  • Strange problem with motherboard H67MA-E45(B3) =( please help

    Hi, I have a strange problem with my motherboard . I have a H67MA-E45 (B3) (MSI-7678) , when i try to update it ( http://www.pcbrain.it/images/stories/msi/H67MA-E45/bios/14.JPG ) , i choose the fourth option "Select one file to update bios" , but the bios did not recognize the update file (E7678IMS.1C0) into the Usb flash drive , but if i choose the second option (select one file to boot) the file is recognized. First I made a backup of the bios, and into the USB flash drive has been created a file called "E7678ICX.162" (my current update). Why the extension is IXC ?!? it should have been IMS ! . I tried changing the file extension "E7678IMS.1C0" (the new update) into "E7678ICX.1C0" and when i select the fourth option , the file is recognized! . Obviously I have not started the update , but if I proceed with the update, changed the name of the extension, is it safe? Or do damage?..please help me  :(
    P.S. Sorry for my bad bad and very poor english , i'm italian =)

    Quote from: HU16E on 28-September-11, 04:38:29
    Manufacturer's Website info;
    "KHX1333C9D3B1K2/4G 4GB 1333MHz
    (2 x 2GB)   CL9-9-9-27 1.5V"
    Still think there is a batch conflict or possibly a bad stick in the new sticks. Might test each new stick individually for a bad one. Again, the other solution for an 8BG kit may be the new Kingston HyperX PnP's. Could you post a screenshot of CPUID's CPU-Z Memory & SPD Tab for one of the new sticks?
    Added: Actually, screenshots of the old sticks Memory & SPD Tab may be of help too. It may be tRAS or tRFC differences between the two kits. Just speculation at this point though.
    All the batchs works perfectly...this is the screen http://imageshack.us/f/163/ramkk.jpg/ ...save and zoom
    EDIT: The old stick are SLOT #1 and SLOT #2 ...the new 3 and 4

  • Image scaling problem

    Hello,
    I have been trying to scale an image to create a thumbnail. The thumbnail image size is around 200*200. The thumbnail is to be rendered on a web browser. My code is:
    public static byte[] getScaledImage(InputStream imageData) throws IOException {
           Image origImg = ImageIO.read(imageData);
           int origImgHeight = origImg.getHeight(null);
           int origImgWidth = origImg.getWidth(null);
           int newImgHeight /*determined by custom logic*/;
           int newImgWidth /*determined by custom logic*/;
          /* code for determining newImgHeight and newImgWidth  keeping the aspect ratio */
           origImg = origImg.getScaledInstance(newImgWidth, newImgHeight,
                                               Image.SCALE_AREA_AVERAGING);
           BufferedImage bimage = null;
           bimage = new BufferedImage(origImg.getWidth(null), origImg.getHeight(null),
                                      BufferedImage.TYPE_INT_RGB);
           Graphics g = bimage.createGraphics();
           g.drawImage(origImg, 0, 0, null);
           g.dispose();
           ByteArrayOutputStream os = new ByteArrayOutputStream(10);
           ImageIO.write(bimage, "jpg", os);
           return os.toByteArray();
    }The calling method is:
    FileCopyUtils.copy(ImageUtils.getScaledImage(lobHandler.getBlobAsBinaryStream(rs, 1)),
                                          imageContent);here imageContent is the http response's outputstream.
    Now the problem is the resulting image displayed on the web page becomes distorted. I first thought that this is due to the thumbnail size. But the scaling done by gimp does not distort the image.
    I have also tried this:
    BufferedImage thumbImage = new BufferedImage(newImgWidth, newImgHeight, BufferedImage.TYPE_INT_RGB);
           Graphics2D graphics2D = thumbImage.createGraphics();
           graphics2D.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BILINEAR);
           graphics2D.drawImage(origImg, 0, 0, newImgWidth, newImgHeight, null);instead of using getScaled instance.
    What could be the problem? This is a problem I need to solve immediately. So I am at a loss. Please help me here.

    Try scaling your source image like this:
    import java.awt.*;
    import java.awt.geom.AffineTransform;
    import java.awt.image.BufferedImage;
    import java.io.*;
    import javax.imageio.ImageIO;
    import javax.swing.*;
    public class ScalingToSize {
        int W = 200;
        int H = 200;
        int SCALE_TO_FIT  = 0;
        int SCALE_TO_FILL = 1;
        private JPanel getContent(BufferedImage image) {
            JPanel panel = new JPanel(new GridBagLayout());
            GridBagConstraints gbc = new GridBagConstraints();
            gbc.insets = new Insets(5,5,5,5);
            gbc.weightx = 1.0;
            panel.add(wrap(image), gbc);
            panel.add(wrap(scale(image, SCALE_TO_FIT)), gbc);
            panel.add(wrap(scale(image, SCALE_TO_FILL)), gbc);
            return panel;
        private BufferedImage scale(BufferedImage src, int style) {
            int type = BufferedImage.TYPE_INT_RGB;
            BufferedImage dest = new BufferedImage(W, H, type);
            Graphics2D g2 = dest.createGraphics();
            if(style == SCALE_TO_FIT) {
                g2.setBackground(UIManager.getColor("Panel.background"));
                g2.clearRect(0,0,W,H);
            double scale = getScale(src, style);
            double x = (W - scale*src.getWidth())/2;
            double y = (H - scale*src.getHeight())/2;
            AffineTransform at = AffineTransform.getTranslateInstance(x, y);
            at.scale(scale, scale);
            g2.drawRenderedImage(src, at);
            g2.dispose();
            return dest;
        private double getScale(BufferedImage image, int style) {
            double xScale = (double)W/image.getWidth();
            double yScale = (double)H/image.getHeight();
            return (style == SCALE_TO_FIT) ? Math.min(xScale, yScale)
                                           : Math.max(xScale, yScale);
        private JLabel wrap(BufferedImage image) {
            ImageIcon icon = new ImageIcon(image);
            return new JLabel(icon, JLabel.CENTER);
        public static void main(String[] args) throws IOException {
            String path = "images/cougar.jpg";
            BufferedImage image = ImageIO.read(new File(path));
            JFrame f = new JFrame();
            f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            f.getContentPane().add(new ScalingToSize().getContent(image));
            f.pack();
            f.setVisible(true);
    }

Maybe you are looking for