Problem with scaling picture

i got this little programm which opens an image. now, unfortunatelly almost all pictures are to big to fit in a frame. therefore i tryed to scale it. for some reason i get this outofmemoryerror. i have absolutely no clue how i could solve this problem.
my code:
the frame:
public class ImageFrame extends JFrame {
    ImagePanel impanel = new ImagePanel();
    Container c = getContentPane();
    public ImageFrame() {
        super("ImageFrame");
        setSize(500,500);
        setLocation(300,300);
        setDefaultCloseOperation(EXIT_ON_CLOSE);
        c.add(impanel);
        setMenuBar(new MyMenuBar());
        setVisible(true);
    class MyMenuBar extends MenuBar {
        public MyMenuBar() {
            Menu m ;
            MenuItem mi;
            m = new Menu("File");
            mi = new MenuItem("Open");
            mi.addActionListener(new ActionListener(){
                public void actionPerformed(ActionEvent e) {
                    impanel.openImage();
            m.add(mi);
            add(m);
}the panel (with the error):
public class ImagePanel extends JPanel {
    Image image;
    Insets insets;
    String file;
    public void setFile(String file) {
        this.file = file;
    @SuppressWarnings("static-access")
    @Override
    public void paintComponent(Graphics g){
        if (file!=null) {           
            Graphics2D g2d = (Graphics2D) g;
            if (insets == null) {
                insets = getInsets();
            ImageIcon icon = new ImageIcon(file);
            image = icon.getImage();
            Image scale = image.getScaledInstance(400, -1, image.SCALE_SMOOTH);
            //HERE I GOT THE ERROR! WITHOUT THE LINE ABOVE THE PROGRAMM WORKS.
            g2d.drawImage(scale, insets.left, insets.top, this);
        repaint();
    public void openImage() {
        try{
            String Filename = openfile();
            if(Filename!=null) setFile(Filename);
            repaint();
        } catch(Exception ex){}
    String openfile(){
        FileDialog fd=new FileDialog(new Frame(),"File Select");
        fd.show();
        String fullpath=fd.getDirectory()+fd.getFile();
        fd.dispose();
        return fullpath;
}hope someone can help me out here. thanks in advance.

gianni88 wrote:
thanks, i moved the repaint() into the actionPerformed part. is that a better place?
where could i go with the scaling part? what is the reason why i get this error?I claim you can get away with no repaints:
code:
1. Read the image
2. rescale it. Here is a good article: [http://today.java.net/pub/a/today/2007/04/03/perils-of-image-getscaledinstance.html]
3. Set this to be the icon on a JLabel that is already in your GUI:
imageLabel.setIcon(new ImageIcon(rescaledImage));Done!

Similar Messages

  • Hi Guys, I have a problem with Importing Pictures onto my Mac mini with Lion installed by using a Card Reader, What is the problem here so I can get Pictures onto my Computer. ,

    Hi Guys,
    I have a problem with Importing Pictures onto my Mac mini with Lion installed by using a Card Reader,
    What is the problem here so I can get Pictures onto my Computer. ,

    Hi Noob Søren
    There are a few things that are confusing in your question.
    As far as I know, you dont have to install Time Machine on this OS as it is already installed for you. You only need to connect a hard drive to your computer via firewire or usb, click on the Time Machine icon, Open Time Machine Preference in the drop down menu and select a disk: your connected hard drive.
    You can of course reformat this connected device, partition it into a few volumes to organise data if you so wish.
    I find it strange that your mac's hard drive is divided into two volumes... perhaps this was created through bootcamp?
    You can access the configuration of your hd through Applications/Utilities/Disk Utilities.
    Clicking on one of the icons on the right hand panel will bring the details of the contents of your hardDrive and volumes. From there you can decide to erase a partition, reformat etc....
    If your hd contains more than one volume, and one of them is empty, you could decide to remove it. Back up all your important data before doing so.
    Hope this helps
    WN

  • Problem with displaying picture.

    I use PS-CC and LR5.on a HP i7 computer and windows 7.Camera D-800, pictures in raw.
    I usually import pictures in nef  in LR5,. After  some corrections, I export my pictures to DNG format. I sometimes do a little bit of work in camera raw then go into Photoshop.
    My problem: When in photoshop, I get a grainy version of my photo which wasn't the situation in LR5 or Camera raw, Hard to work with. The grains will disappear when I enlarge the picture but then I have to enlarge it so much that I only see or can work with only part of my picture. The problem does not appear in CS6.
    Hope somebody can help me.
    Thanks
    Jacques Legault

    I should clarify this.. When I import photos into LR5, I always use copy as
    DNG. I know that NEF and DNG are the same for photoshop and I always shoot
    in raw.
    One thing I do not know is how to do a screen shot. I will get back tro you
    on that. When I say grain, or noise if you like, I mean that, if i relate
    to films, my picture in LR5  would be at ISO 100 and my screen shot in
    photoshop would look like it was boosted to 1200 or worse.
    See you soon I hope with a screen shot.
    2014-06-14 13:43 GMT-04:00 twenty_one <[email protected]>:
        Problem with displaying picture.  created by twenty_one
    <https://forums.adobe.com/people/twenty_one> in *Photoshop General
    Discussion* - View the full discussion
    <https://forums.adobe.com/message/6458682#6458682>

  • Problems with scaling in illustrator CS3.

    Recently while working on a large file in Illustrator I've had a problem with scaling. Normally I scale with handles, and rarely with the input box. Now I can only scale with the input box. I have gone to preferences but that seems fine, (i think?). Is this a new glitch? Is their a way to solve this problem. Thanks.

    View > Show Bounding Box.
    You probably mistakenly hit the shortcut to turn it off at some point.

  • Problems with simple picture gallery

    I've got a website project where the client wanted a picture
    gallery. I don't really do much with Flash so I went on the web and
    found a tutorial on how to get what I want. Problem is that the
    instructions I followed are fairly old so I couldn't export my
    movie any higher than AS2 and Flash 6 and have it work. That would
    be fine except that I wanted to use a feature that requires Flash 8
    or higher, namely a gradient mask. I was hoping that I could post
    my code and have the board gurus help me out with what i need to do
    to get everything working together.
    First you'll want to create a movie using AS2 and Flash 8 to
    see what I'm trying to accomplish, then export it again with Flash
    6 to see it actually working. You can grab a copy of what I'm
    working with here:
    http://www.technospider.com/~david/rusty.zip
    All help greatly appreciated.
    Thanks,
    David

    based on experience. i didn't check your file.
    you're not likely to get anyone in this forum to check your
    file.
    if there's not code problem, and you can't publish for flash
    8, there will be an error message. if you can publish for flash 8,
    you see no error message but your application fails to work
    correctly, you must have a problem with code.

  • Problems with the pictures in automatic mode

    I bought an xperia Z1 just a few days ago, I just find a problem with the camera flash, when I take a picture in automatic mode. 
    failure is, when a picture is taken in autmomatic mode, the right side of the picture, left with a bright white shadow, wich is ruining the photos.
    I need your help, Its so frustrating, I thought I had made ​​the right decision when I bought this computer, but apparently not
    attached a sample image
    hopefully you can help me
    kind regards

    Probably there was something that reflected your flash.I suggest you disable flash in panoramic night shots.
    All we have to decide is what to do with the time that is given to us - J.R.R. Tolkien

  • Problem with saving picture in Vision Builder

    hello
    I'm using Vision builder and i'm trying to save picture with Image Logging. And i made ftp server that picture could be save. In folder path I write location where I want that picture save. But problem is, that picture does not saves in that location where I want.
    Could anybody help me?
    Please
    Matjaz
    p.s.: I attach a picture that You will see how I made my settings
    Attachments:
    napaka.jpg ‏4307 KB

    rezi wrote:
    why is writen 257 "/" is current directory ??
    It means that root is current directory.
    For setting VBAI as current directory it should be something like
    CWD VBAI
    250 OK. Current directory is /VBAI
    PWD
    257 "/VBAI" is your current directory.
    Try to remove VBAI from Folder path and leave this setting just empty. Then your images should be written into root directory. Also you have selected option "Log images when inspection status FAIL". May be your status PASS? In this case images will be not logged. Try to change this option to "Log Image".

  • Problem with uploading pictures

    i just got my ipod classic 160gigs and i tried to upload pictures with my laptop (hp windows vista), it loads a while but then it suddenly shut off my laptop, i tried it many times but still the same problem...what will i do??im afraid my laptop might destroyed if i continue using this ipod...

    Welcome to Apple Discussions!
    Your laptop just turns off when syncing with your iPod, even when connected to power? Is it possible that there is something wrong with the laptop (maybe power issues when using a USB device). Have you connected any other devices to your computer/has your computer done this in any other situation?
    I hesitate to blame the laptop (and I am no software/hardware expert), but I find it difficult to understand why an iPod or iTunes would cause a laptop to just shut off. I'd think something is wonky with the laptop.
    Does the problem occur when just syncing music/video? Have you tried contacting HP support as well?
    btabz

  • Problems with moving pictures on a layout grid

    Hello,
    currently I am switching from windows golive5 to mac os x golive 9.
    In my "older" version I could move pictures on a layout grid by using the arrow keys (klick on right arrow one time moved the picture one step right...)
    In my new Version this function is just working on pictures without a border.
    If there is a border (HTML border=...) around the picture the picture is scaling bigger an bigger by using any arrow key.
    So my only chance to move these pictures on the grid is by mouse or remove the border, move them by the arrow keys, and recreate the border...
    Even the manual input of the grid position (using Y=50 X=50) by clicking on these arrows or input the numbers directly in the toolbar is scaling the picture.
    Is this a bug? Can I do anything to work like in GoLive 9, just moving every Object by arrow keys?
    Thank you in advance!
    Nic

    Wow, looks like a bug to me! The image enlarges by the combined values of the border whenever it is shifted - with the nudge arrows or not - and that can only be called a bug. I'd just uncheck the border button in the Inspector, move the image and then turn on the border again.
    I can't find the bug report page on Adobe.com for the life of me right now. Does anyone know where it has gone?

  • Problem with making picture invisible

    Hi,
    I prospect forums but I have not found solutions to my problems. I
    want to display different pictures at different times or successively.
    I want to display one picture, wait until the user click onto it
    (I know how do it), then display another picture in the place of the
    first and so blinking (making invisible and inactive) the first.
    Sorry for this simple request. Thanks in advance for your help.

    Hi,
    I send here the program I would like to realize.
    The user must clicks a certain number of times (once or five times) on a red rectangle before two shapes (A and B, once in the left and once in the right) appear and the subject chooses either one. The same thing with another pair of stimuli (C and D) after completion of a number of clicks required on the rectangle. One sequence consists on 2 presentations of the pair AB stimuli with each stimuli once at right and once at left + 2 presentations of CD stimuli with each stimuli once at right and once at left.
    I want to randomize order of events, so I will create (no doing yet) 24 sequences of possible order of events (not only display AB_BA_CD_DC, like the example, here in the block diagram, but too AB_DC_BA_CD, for example). The choice of the sequence is randomized with a random number (multiply by one for the moment in order you see immediately the events when you run the VI).
    I use ring picture to display the stimuli and enumerated constant for the type of stimuli I display. What I would like to do is using only 2 rings indicators, but I have seen when I did that, the program doesn't work. I was "forced" to use one ring each time. It will be more costly for me to write because I must create property node_property visible_false for other ring each time and in this cas I would use 288 rings.
    My question is how can I do for using only 2 rings? And am I forced to use sequence structure?    
    Thanks in advance for your help.
    sequence 1 effort à FR5.zip (849 kb)
    Attachments:
    sequence 1 effort à FR5.zip ‏849 KB

  • Problem with "Save picture as"

    Hi All.
    To explain my problem I have created this application BSP.
    <b>OnInitialization</b>
    navigation->goto_page( 'imagen_error.jpg' ). " This is a MIME object
    When I executed my application I want save the picture. I press the right botton over the picture and I choose "Save picture as". The name of the picture is
    "untitled" and Save as type is ".bmp". I need save it with the original name and type. If I refresh the page I can save it with original name and type.
    Could I refresh the page in my application?
    Could I resolve my problem in another way?
    <b>IMPORTANT: I can't use layout.</b>

    thanks Peter for trying to help
    ok, i've narrowed down the problem, it seems that when i try and save a file onto one partition of one of my ext drives it won't save to my last save dir but if i save to another partition/drive it works ok, also if i rename the 'dodgy' partition it also seems to work ok, so somehow the name of the drive has become corrupted.
    anybody ever heard of this? or how i could fix this as it's a quite annoying because alot of my audio files are referenced on this partition, so itunes or Cubase (audio sequencer) can't find my files now.

  • Problem with downloading pictures from PC-cam350

    I have a PC-Cam 350 that is giving me a problem. I took the camera with me for mothers day and took a bunch of pictures. When I got home I took some more pictures but I hit the button on the back that changes the mode mistakenly. When I plug the camera into the computer and click on the "Digital Camera" section of the PC-Cam center, it downloads all of the pictures up until the ones that I took mistakenly in another mode, and then I get a message that says the CTPCCCam.exe has encountered a problem and needs to close. Is there anyone that knows how I can save the pictures that are in the camera?

    Just had a breakthrough!  I suddenly noticed that there were 4 headings in the Video App, one of which I had never opened before called 'Home Videos'.  I discovered that my own camcorder videos were in it (I guess that that should have been expected.  Duh!) AND films that I had captured and converted to MPeg-4s.   I had expected that these films would have been stored under 'Movies'.  Oh, well, you live and learn!  Hope that that might help anyone else who has been having my problem of missing fims on their iPad.
    Munchkin12

  • Magic Move causing problems with scaled animation

    I have a presentation that uses the Magic Move transition between slides. The Magic Move only effects a solid rectangle at the top of the slide which moves to the bottom of the next slide. The Magic Move transition works great except it causes a rescaling of an object on the slide that has been scaled using the scale animation. There are slides where I animate text to move and scale to a larger percentage.
    The text animation moves and scales perfectly. When the slide is about to preform the Magic Move transition (advancing to the next slide) the object that was scaled by animation scales back to its original size. Then the presentation advanced to the next slide.
    I've reproduced this on two other computers with 'start from scratch' presentations to test. It occurs with any object - text, shape, etc.  Can someone else verify that this is a bug or not?
    OSX 10.9.4
    Keynote 6.2.2 (1878)
    Keynote 6.2 (1861)
    MacPro
    MacBookPro
    Thanks.

    UPDATE.
    Just tested my issue in Keynote version 6.0 and there were no issues. Scaled animated objects and text combined with the Magic Move transition will not result in a the scaled object reverting back to it's original size during the slide transition.
    I still would like verification from another user that you can repeat my problem in version 6.2. Although I'm 80% sure this is a bug I have found, until someone else can confirm my issue i'll hold off on that conclusion.

  • Problems with sending pictures with imessaging

    Today I am having a problem that my imessaging with pictures are not being sent, via Verizon Wireless or when I am on WiFi.  Is there any issues today with imessaging?

    Use the Apple system status page to identify any service outages.
    http://www.apple.com/support/systemstatus/

  • Problems with sending pictures on Iphone 5c

    Im having a large inconvience with my iPhone 5c. Puchased and activated in September, it has served me well up until a week ago. Without altering anything, I have lost the ability to send pictures to other iMessage users. I can receive them perfectly fine but when I send a picture to a iMessage user, it will say "delivered" but the person I sent it to will never get it. My phone works fine with regular texts messages, I can send and receive pictures perfectly fine from a non iPhone user. Is this a common problem? Thanks!

    I am on Tmobile USA fyi.

Maybe you are looking for

  • Wine & Labview Executable​s?

    Is it possible to run LabView executables under wine? Has anyone ever attempted to do this? Thanks for any information. Regards, Ken

  • Erro while running SLDCHECK Tcode

    Hi, We have just installed our SAP XI Server. After configuring the SLD i was trying to check the configuration. While running the tcode "SLDCHECK" it is giving me the following error. Use transaction SLDAPICUST if you wish to maintain the SLD server

  • Problem loading URL from .jar file

    I encounter problems while loading a MsAccess DB contains within a .jar file. This is the following codes I used, try     Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");     java.net.URL url=getClass().getResource("MSAccessDB\\SavingApp DB.mdb");    

  • Can't activate my bb

    hi, i have a new q10, i can't activate it throught 3G or wifi. The error is: Unable to connect to update server (2032). What i can do?

  • Return delivery transportation charges through VT01N

    Dear All, I want to capture return delivery transportation charges through transportation model. Can anyone tell me the process step by step. Thanking you in advance. Sumeet