Image.getScaledInstance doesn't scale

Hi All!
I've got a problem with image scaling of JPG file. In the constructor body of my class that inherites from JPanal I wrote following code:
Image image,image1;
image = (new ImageIcon(this.getClass().getResource("/Pics/about.jpg"))).getImage();
Thread.sleep(2000);
image1 = image.getScaledInstance(this.getWidth(), this.getHeight(), Image.SCALE_DEFAULT);Everything is OK with 'image' loading, but getScaledInstance doesn't scale loaded image.
In debuger I observe image1.getwidth()/getHeight() = -1...
What's wrong?

You can try one of these:
public PieceIcon(String symbol,int pNum)    { 
      playerNumber = pNum;
      pieceImage = new ImageIcon("./Images/"+symbol+".jpg").getImage().getScaledInstance(10,10,Image.SCALE_DEFAULT);
        //Image doesn't appear dispite being smaller than original image, appears if scaledInstance part removed
       setOpaque(false);    }
       validate();// try it with just one or the other or both
       repaint();

Similar Messages

  • Image.getScaledInstance() does not always work under Windows Vista

    Hi:
    I've run into some intermittent image scaling problems under Windows Vista (minus Aero effects) that I never experienced with the same program, same image(s), running same Java version under XP. The images I'm using are all JPEGs, and the problem appears to affect approx 1 out of 3 grayscale images (no color ones so far) w/o respect to size (ie: small ones can be problems while larger ones will work). Java -version shows 1.6.0_02-b06. I was wondering if anyone else out there has seen this, or can point out what I may be doing wrong. Sample code to duplicate follows.
    Tx,
    Jallewel
    // ===================================================================
    // Image Scaling Problem, Description & Demo Program (minus the image):
    //   Environment:  SDK/JRE: Java 1.6.0_02-b06, running under
    //        Windows Vista Home Premium (32-Bit) on Dell Inspiron w/3GB RAM
    //   ************* Symptoms ******************
    //   Problem occurs when invoking image.getScaledInstance().
    //   Problem shows up under Windows Vista, configured w/Windows Classic look
    //       & feel - that is, with Aero effects turned OFF.
    //   Problem does NOT show up under Windows XP on Dell Dimension 4500.
    //   Test across computers used same SDK/JRE, Java program, and Image.
    //   Problem ONLY appears in grayscale JPEG images, and only 1 out of 3 of those.
    //   (I can provide a problem image)
    // Results Compiling & Running This Program:
    //   C:\Users\~\VistaProblem>javac VistaProblem.java
    //   C:\Users\~\VistaProblem>java VistaProblem
    //      Uncaught error fetching image:
    //      java.lang.ClassCastException: [I cannot be cast to [B
    //        at java.awt.image.ColorModel.getAlpha(Unknown Source)
    //        at java.awt.image.ColorModel.getRGB(Unknown Source)
    //        at sun.awt.image.ImageRepresentation.convertToRGB(Unknown Source)
    //        at sun.awt.image.ImageRepresentation.setPixels(Unknown Source)
    //        at java.awt.image.AreaAveragingScaleFilter.accumPixels(Unknown Source)
    //        at java.awt.image.AreaAveragingScaleFilter.setPixels(Unknown Source)
    //        at sun.awt.image.ImageDecoder.setPixels(Unknown Source)
    //        at sun.awt.image.JPEGImageDecoder.sendPixels(Unknown Source)
    //        at sun.awt.image.JPEGImageDecoder.readImage(Native Method)
    //        at sun.awt.image.JPEGImageDecoder.produceImage(Unknown Source)
    //        at sun.awt.image.InputStreamImageSource.doFetch(Unknown Source)
    //        at sun.awt.image.ImageFetcher.fetchloop(Unknown Source)
    //        at sun.awt.image.ImageFetcher.run(Unknown Source)
    import java.*;
    import java.awt.*;
    import java.io.*;
    import javax.imageio.*;
    // class VistaProblem
    public class VistaProblem extends Frame {
       private static ScrollPane sp = new ScrollPane(ScrollPane.SCROLLBARS_AS_NEEDED);
       public static ImageComponent ic;
       // Constructor
       public VistaProblem() {
          super("VistaProblem");
          add(sp, BorderLayout.CENTER);
          this.setSize(700, 520);
          setVisible(true);
         String fPathName = "./ProblemImage.jpg";
          ic = new ImageComponent(getToolkit().getImage(fPathName));
          sp.add(ic);
          sp.validate();
          ic.Scale(220, 200);
       // class ImageComponent
       class ImageComponent extends Component {
          private Image image;
          // Constructor
          ImageComponent(Image img) {
             this.image = img;
          // paint
          public void paint(Graphics g) {
             g.setColor(getBackground());
             g.drawImage(image, 10, 10, this);
             g.dispose();
          // Scale
          public void Scale (int width, int height) {
             // ***** PROBLEM LINE HERE; COMMENT OUT AND PROGRAM WORKS *****
             this.image = this.image.getScaledInstance(width, height, Image.SCALE_SMOOTH);
             repaint();
       // Main Entry Point
       public static void main(String args[]) {
          Frame f = new VistaProblem();
    } // end VistaProblem

    That does indeed appear to be a bug. I looks like it's having problems with the alpha value in the color model, so a possible workaround would be to change the color model the image uses before scaling. This may entail creating a new BufferedImage and drawing the old image into it.

  • Module that doesn't scale 100% to its container

    Hi,
    I have a module that doesn't scale 100% to its container
    <?xml version="1.0" encoding="utf-8"?>
    <mx:Module xmlns:mx="http://www.adobe.com/2006/mxml" layout="vertical"
        percentWidth="100" percentHeight="100" verticalGap="0"
        >
        <mx:creationComplete>
            <![CDATA[
            vo = VO.getInstance();
            ]]>
        </mx:creationComplete>
        <mx:Script>
    You see anything wrong?

    I set up the panel like this      
    privileges= new SuperPanel();
            privileges.x=0;
            privileges.y=0;
            privileges.width=725;
            privileges.height=500;
            privileges.verticalScrollPolicy='off';
            privileges.allowDrag=true;
            privileges.allowResize=true;
            privileges.allowClose=true;
            privileges.allowMaximize=true;
            privileges.allowMinimize=true;
            privileges.allowMaximize=true;
            privileges.addEventListener(CloseEvent.CLOSE,privilegesClose)
            privileges.layout='vertical';
            privileges.title="Assign privileges";
            privileges.addChild(privilegesML);
    then I load the module
              privilegesML.url = 'modules/Privileges.swf';
    The module looks a bit like this
    <?xml version="1.0" encoding="utf-8"?>
    <mx:Module xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" paddingBottom="0" paddingLeft="0" paddingRight="0" paddingTop="0"
        width="100%" height="100%" verticalGap="0"
        >
        <mx:creationComplete>
            <![CDATA[
            vo = VO.getInstance();
            ]]>
        </mx:creationComplete>
        <mx:HBox width="100%">
            <mx:Button label="Save changes to server" click="deals.dataProvider=tradesResult">
                <mx:icon>@Embed(source='../../images/32px-Crystal_Clear_app_kwrite.png')</mx:icon>
            </mx:Button>
            <mx:Button label="Refresh list" icon="@Embed(source='../../images/cog.png')" click="myService.getUsers();"/>
        </mx:HBox>
        <mx:AdvancedDataGrid id="deals" displayItemsExpanded="false" dataProvider="{vo.usersResult}" width="100%" height="100%" sortExpertMode="true" variableRowHeight="true" headerStyleName="smallHeader" editable="false" fontWeight="normal">
            <mx:columns>
                <mx:AdvancedDataGridColumn dataField="name" headerText="User name" width="120" textAlign="center" editable="false"/>
                <mx:AdvancedDataGridColumn headerText="Add trade" width="70" editorDataField="addTradeView" rendererIsEditor="true" backgroundColor="0xddf5ff">
                    <mx:itemRenderer>
                        <mx:Component>
                                <mx:CheckBox >
        <mx:Script>
                                    <![CDATA[
                                        override public function set data(value:Object):void
                                            super.data=value;
                                            if(value != null){
                                            this.selected=this.data.addTradeView;
                                    ]]>
                                </mx:Script>
                                    <mx:change>
                                        <![CDATA[
                                        this.data.isModifiedClientSide = 1;
                                        this.data.addTradeView = this.selected; //used to check through data and update server
                                        ]]>
                                    </mx:change>
                                </mx:CheckBox>
                        </mx:Component>
                    </mx:itemRenderer>
                </mx:AdvancedDataGridColumn>
            </mx:columns>
        </mx:AdvancedDataGrid>
    </mx:Module>

  • Scaling sprite for printing doesn't scale content

    Need help with this one!
    I have a Flash docutment that is 950 x 650. I want to add a
    "print" button that will automatically scale it to fit uncropped on
    an 8.5" x 11" page (Landscape).
    Problem is, although the sprite DOES scale to fit the page,
    the content doesn't scale but rather just ends up being cropped.
    It's like my sprite is a window looking through to my image. I
    change the size of the window but the image behind it remains the
    same size.
    Here's the code:
    Thanks!
    Phalconheart

    I have found that I needed to add each sprite and textfield
    individually. I actually just created new instances of each element
    to add to my page sprite. ie.
    if stage has a square object and a circle objects:
    var square:Square = new Square();
    square.scaleX = .8;
    square.scaleY = .8;
    var circle:Circle = new Circle();
    circle.scaleX = .8;
    circle.scaleY = .8;
    printSprite.addChild(square);
    printSprite.addChild(circle);
    .... yada yada
    myPrintJob.addPage(printSprite, etc etc

  • Mail App Stationary Doesn't Scale / Resize on Mobile devices

    Testing the Mail Stationary, for which I was very excited about, and found that it doesn't scale on mobile devices or even my desktop Mail app. Sent from Mail app on desktop and tried viewing on iPhone, iPad, and my desktop... all 3 devices required horizontal scrolling to view the entire message... while other email marketing messsages scaled just fine.
    UPDATE: Found that in some cases it will scale if I open another message first and then switch back, at least on the iPhone and iPAd in landscape orientation.
    What's up with Apple, or possibly me, that their own stationary doesn't scale on their own devices??  I haven't even tested on Outlook because I can only imagine the results (wouldn't it be ironic if it worked there??)
    Experiences?
    Do the thrid party templates, Jumsoft or Equinox, work any better?

    having exactly the same problems and made exactly the same experiences..
    maybe one more: i checked Outlook - bouth for Mac and Windows. Outlook doesn't like attached images, they are visible in HTML but also attached like real attachments. put them on an webserver and add complete URL and your stationery will look fine.. in Outlook

  • 2014 Mac mini doesn't scale the entire HP Envy 32 monitor screen

    I recently purchased a HP Envy 32 monitor for use with my 2014 Mac mini with the Iris display. I get 2560x1440 resolution at 60 Hz on both the DP (1.2) as well as the HDMI ports (using the auto-detected HP Envy 32 color profile) but the display doesn't scale the entire screen of the monitor. Is anyone else using this configuration successfully? If so, what have you done to make full use of the 32" monitor real-estate? I simply cannot find any options in Display preferences (Yosemite) to change underscan options or for that matter within the monitor itself. Is there a particular display profile or driver I can use to fix this issue?

    I'm using a 4K compatible DP cable connected to the Thunderbolt port and getting to the max resolution of the monitor. So I don't think the issue lies there. I was able to use SwitchResX trial mode to discover an underscan option that allowed me to scale to the entire monitor screen. Assuming SwitchResX is manipulating core OSX functions, I'd assume there is some display related configuration within OSX that I should be able to tweak in order to scale the monitor screen natively in OSX without requiring any 3rd party software. Any thoughts for how to go about tweaking the display natively?
    Thanks

  • Illustrator Image Trace doesn't work with large images

    Illustrator's Image Trace doesn't seem to work at all with large images.  The attached image shows the following:
    A) The original raster cropped tightly.
    B) Converting the raster with default "Black and White Logo" settings.  Results in 242 paths and 4792 anchors.
    C) Adding a massive amount of white space and then converting the raster with default "Black and White Logo" settings.  Results in 407 paths and 1620 anchors.
    For whatever reason Illustrator can't seem to handle large images.  This test shows it's not an issue with the image being too complex since all I've done is add white space and the file was saved without compression so there should be no noise.
    This type of glitch started with CS6 with the new Image Trace tool.  Is there a fix for this?  Maybe setting Image Trace into legacy mode?

    Moving to Illustrator forum.

  • Image Capture doesn't recognize iPhone and Camera anymore

    Image Capture doesn't recognize my iPhone or my Fujifilm camera. I am pretty sure this happened after updating to Safari 4.0.2 and having to restart which I did today. Yesterday I was able to to browse through my devices.

    I'm adding that iTunes has no problem reading the iPhone.

  • Desktop content viewer still doesn't scale 2048 folios?

    or does it?
    if I'm creating a 2048x1536 folio in inDesign and preview it on the desktop the viewer doesn't scale to fit so i can only see half the page
    anyone know a way around this, other than to create a 1024 doc?
    - Tim

    Our v20 release will include the ability to zoom the desktop viewer smaller so you can preview folios for the new iPad.
    Neil

  • Image Capture doesn't recognize my Built-in iSight Camera

    I'm trying to use Image Capture but when I open the application is shows the following message:
    "No scanner or camera connected".
    It's supposed the camera is connected because I'm also using Skype video call (not at the same time I'm trying to use Image Capture) and there's no problem with it.
    Image Capture was working perfectly couple months ago, now it isn't.
    Does somebody know what the problem might be?
    Thanks for your comments and opinions.
    Sebastian.

    image capture doesn't use the isight, it's for other digital cameras & scanners. use the screen capture ability. hold, command shift, press 4 & tap spacebar to see a camera icon. click on an open / active window when it's lighted in blue, click the mouse. saves the pic as a png on your desktop.

  • Image Capture doesn't recognize my Canon device camera (it has before). I made a copy of the Image Capture app by mistake.  What do I do?

    My Macbook doesn't have iPhoto installed. ??  I don't know why, because it used to be installed.
    I have been able to download photos from my camera using Image Capture, but now Image Capture doesn't show my camera in the Devices window.  It did yesterday.
    Ideally, I would like to install iPhoto again, but how do I do it without having to purchase the app again?
    This might also be relevant:
    I wanted to add an Image Capture icon to my dock, but I inadvertently made a copy of the app (called Image Capture copy).  When I tried to erase the copy, I couldn't.  Image Capture copy is in my Trash and the Image Capture app is in my Applications folder.  I tried opening the app from both the Trash version and the app version, but it doesn't help.
    Please help!
    Sue

    Use the disks that came with your Mac to do a custom install of the software you need, i.e. iPhoto.  The disk should look like #4 in this screenshot:

  • Image lightbox doesn't work in Firefox 4.0.

    Hello,
    When viewing 'Larger images' on a website, the lightbox that usually highlights the image, giving it a blacked out background doesn't work any more.
    The image simply doesn't appear, although the lightbox does?
    Anyone else experiencing this? Is there a setting of some sort that I have to enable or an Add On that will solve this?
    Thanks.

    There isn't one yet.

  • Placing images at an exact scale in Indesign CS5?

    Hi all,
    I'm hoping someone can clue me in here... I've just updated from Indesign CS3 to CS5. I was hoping in the upgrade Indesign would give you an option for placing images in picture frames at an exact scale (like you can in Quark), for instance if you place an empty picture box on the master pages and enter 55% scale you would drop in images on each page of the layout at 55% scale.
    In Indesign CS3 the closest I could get to that was to place an "FPO" image in the picture boxes on the master pages at 55% scale, then when I'd replace each FPO on the layout pages with my images they would drop in at 55% scale. It worked pretty well.
    With CS5 I'm finding that when I replace an FPO image it will still drop in at the same scale the FPO is at, but ONLY if you load and place one image at a time... if you load, say, twenty images and drop them into the layout replacing the FPO images, they come out as prorortionally fitted to the picture frame... NOT as 55%.
    this is a real issue for me as I routinely work on layouts where I need to place 400 and up images at an exact scale...
    Anyone know a work around here, or any tips?
    Thanks in advance.

    As far as I know, you can't set scaling for a empty frame. You can use a placholder image and scale that, and if you turn off relink preserves dimensions relinking to a new image would preserve the scaling, but only if you do it one at a time through the links panel. Using the Place command and replacing theimages will not preserve the scaling, so through the interface there isn't much help.
    On the other hand, I think this could be scripted. If you need all the images to be the same scale it should just be a matter of looping through the document images and setting the scale. If none of the scripters are taking notice here, ask over in the scriping forum.

  • Printing a JComponent, but it doesn't scale to fit the papers size

    Hello all,
    I derived a class "GraphPanel" from "JPanel" and did some simple graphics in the paint()-Method.
    The paint-Method uses the getSize().width and height-properties so that the lines and images it draws always scale to the components size. This works fine.
    The class GraphPanel also implements the Printable-Interface and I implemented the print-Method as follows:
        public int print(Graphics g, PageFormat pf, int page) throws PrinterException {
            if (page > 0) {
                return NO_SUCH_PAGE;
            Graphics2D g2d = (Graphics2D)g;
            g2d.translate(pf.getImageableX(), pf.getImageableY());
            AffineTransform at = new AffineTransform(pf.getMatrix());
            g2d.transform(at);
            this.print(g);
            return PAGE_EXISTS;      
        } // printI wanted the JPanel to be print out: scaled over all the papers' size (no matters if this means shrinking or blowing up the drawings).
    The result wasn't what I expected: the size of the printing depends on the size of the JPanel at the screen :-(
    Please can anybody give me a hint for doing this scaling?
    Thanks a lot,
    Thorsten

    What if you add this line
    g2d.scale( pf.getImageableWidth()/getWidth() , pf.getImageableHeight()/getHeight() );just before you print
    this.print(g);

  • Iphoto & Image Capture doesn't see Iphone, Itunes Does?

    Iphoto & Image Capture doesn't see Iphone, Itunes Does.
    I am able to do everything as normal in itunes but cannot import photos using Image Capture(my prefered way to get my images) as it does not see my devise. Same for iphoto it doesn't see my iphone, please help.
    Thank you

    paulcb wrote:
    It's generally recommended not to use a USB hub with the iPhone. I've used one with no problems but many have reported solving sync problems just by eliminating the hub and plugging directly into a USB2.0 port.
    I'm sure.
    The trouble is that there are too many bits of hardware that are recommended not to use a hub with. I have a PhoneValet (which won't work at all with a hub) and a set of first generation Harman-Kardon speakers (ditto). Then I need a USB port to plug the hub itself into, and that's my three USB ports used up.
    Martin

Maybe you are looking for

  • How to import a message class in a fm

    Hello! I' m programminn a FM. I need to use a message class that i have created. How i can import it? I have to return a strcuct which i have to copy my message class. My code:           DETAIL_RETURN-ID =           DETAIL_RETURN-NUMBER =           D

  • PST is not an Outlook data file error coming while opening the Outlook

    Hi, Suddenly my outlook is showing the .pst file is not an Outlook data file error while starting. No big changes was made to the system to cause this. I had upgraded the IE version to 9 the same day. Done lots of trouble shooting but still not able

  • HOW TO find the cost center.

    Hello, Please let me know the Ttransaction Code how to find for a particular division wat cost center has been assigned. For example: how to find for BMHS divison wat cost center has been assigned.Please let me know the steps. Regards AM.

  • Install Java Add-in for ABAP BW 3.5

    I have a System on which we have 3 SAP Instances 2 Instances of SAP R/3 4.6D 1 instance of SAP BW 3.5 I want to add a New Java Instance for BW and it is giving error during the installtion that Collation needs to be CP850_BIN2 I will appreciate if an

  • Where to find the user manual for Camileo X-SPORTS

    Hello! Unfortunately can't find in Toshibas's download sections *user manual* for action camera *Camileo X-Sport*. Need more info about some operations and technical things, to decide about purchasing. Any ideas, where can I find this extended manual