Help please on image resizing

How do you resize images (I can't find anything in the APIs).
At the moment I have an application with an inherited layeredPane and images (from inherited JLabels) drawn on top.
The pane currently has no layout, if I resize the application everything else resizes but the images stay the same.
Would anyone be able to show me what I have to change to enable the images to resize, help would be appreciated.
public class BoardPanel extends JLayeredPane
    public BoardPanel()
    //Overwrite abstract painting method
    public void paintComponent(Graphics g)
        super.paintComponent(g);
        //draw Image at size of panel starting at 0,0
     g.drawImage(backgroundImage,0,0,this.getWidth(), this.getHeight(), null);
    private Image backgroundImage = new ImageIcon("./Images/Board.gif").getImage();
public class PieceIcon extends JLabel
    //Create new image with the piece (symbol) chosen by the player
    public PieceIcon(String symbol,int pNum)
        playerNumber = pNum;
        pieceImage = new ImageIcon("./Images/"+symbol+".jpg").getImage();
        setOpaque(false);
    public void paintComponent(Graphics g)
       super.paintComponent(g);
       g.drawImage(pieceImage,boardPos[0][(MainFrame.getPlayer(playerNumber).getCurrentBoardPos())],
                              boardPos[1][(MainFrame.getPlayer(playerNumber).getCurrentBoardPos())],this);
    private Image pieceImage;
    private int playerNumber;
    private static int[][] boardPos = //load of absolute values, change to proportionate values if images can be resized
public class MainFrame extends JFrame
    /** Creates new form JFrame */
    public MainFrame()
        initGUI();
        pack();
    private void initGUI()
       //create components and add to frame, including:
        JPanel content = new JPanel();
        getContentPane().add(content, java.awt.BorderLayout.CENTER);
        content.add(boardIcon, java.awt.BorderLayout.CENTER);
        //Create the board Pane
           boardIcon.setPreferredSize(new java.awt.Dimension(500,500));
        //start at (x,y) 0,0, with height/width (600,600)
            boardIcon.setBounds(0,0,600,600);  //does this have to be set again if window is resized?
        boardIcon.setLayout(null);      
    public void createPieces()
       //method called in main once player names and details have been enterd
       playerPieces = new PieceIcon[this.getNumPlayers()];
       for(int i=0; i<this.getNumPlayers(); i++)
          //Create new icon with players piece selection and number selection
          playerPieces[i] = new PieceIcon(this.getPlayer(i).getPiece(),i);
         //Add piece at depth of '10' (default layer is 0 so just above other board components)
         boardIcon.add(playerPieces,new Integer(10));
//label size of board, piece drawn at specific point within board
playerPieces[i].setBounds(0,0,boardIcon.getHeight(),boardIcon.getWidth());
private static BoardPanel boardIcon = new BoardPanel();
private PieceIcon[] playerPieces;
Thanks in advance

You need to use g.drawImage(image, dest.x, dest.y, dest.width, dest.height, source.x, source.y, source.width, source.height, null)
It's in the Graphics API. It will scale the image on the fly. The destination coordinates should be the panel you want to paint on.

Similar Messages

  • Coding help please - changing image using links

    Hi there,
    I wonder if anyone could help me? I'm designing a website at
    the moment, but being a traditional print designer, I'm finding it
    quite difficult to get use to the coding at first. What I have is a
    page (which is shown in the link below with what i'm after) with
    six links, some text and a default image which I want the user to
    be able to click on the 'linked text' and change the main image so
    if 1.jpg was the main image, when they click 'cover 2' they get
    2.jpg and so on in the same frame that the main image is kept in.
    I've tried some javascript code I found on another help site
    but it just messes the frames up and only seems to work if the code
    is as one rather than pasted in my pages code?
    Please, please, please can someone help as it's driving me
    mad and the boss is getting closer to the room :-)
    Below is a screenshot of my page and written in red on it is
    the various bits I need to work out with your help.
    [IMG]http://i7.photobucket.com/albums/y254/080780/help.jpg[/IMG]
    http://i7.photobucket.com/albums/y254/080780/help.jpg

    Select a link, and apply a DW Image Swap behavior to swap the
    main image to
    the one desired. Do not use the automatic restore.
    Murray --- ICQ 71997575
    Adobe Community Expert
    (If you *MUST* email me, don't LAUGH when you do so!)
    ==================
    http://www.projectseven.com/go
    - DW FAQs, Tutorials & Resources
    http://www.dwfaq.com - DW FAQs,
    Tutorials & Resources
    ==================
    "Gavin Wood" <[email protected]> wrote in
    message
    news:fhegg8$o4s$[email protected]..
    > Hi there,
    >
    > I wonder if anyone could help me? I'm designing a
    website at the moment,
    > but
    > being a traditional print designer, I'm finding it quite
    difficult to get
    > use
    > to the coding at first. What I have is a page (which is
    shown in the link
    > below
    > with what i'm after) with six links, some text and a
    default image which I
    > want
    > the user to be able to click on the 'linked text' and
    change the main
    > image so
    > if 1.jpg was the main image, when they click 'cover 2'
    they get 2.jpg and
    > so on
    > in the same frame that the main image is kept in.
    >
    > I've tried some javascript code I found on another help
    site but it just
    > messes the frames up and only seems to work if the code
    is as one rather
    > than
    > pasted in my pages code?
    >
    > Please, please, please can someone help as it's driving
    me mad and the
    > boss is
    > getting closer to the room :-)
    >
    > Below is a screenshot of my page and written in red on
    it is the various
    > bits
    > I need to work out with your help.
    >
    >
    [IMG]http://i7.photobucket.com/albums/y254/080780/help.jpg[/IMG]
    > http://i7.photobucket.com/albums/y254/080780/help.jpg
    >
    >
    >

  • Help please - Overlapping Images

    Hi, hope someone can help.
    I'm writing an application that requires a background image with multiple images drawn over the top. These images will be moved as options are selected.
    Can anyone provide an example of how to implement the Overlay layout manager to perform this as I'm having difficulty.
    Thanks in advance.

    Thanks,
    Any idea how to add the background image to the JPanel component.
    I've tried stuff as below but to no success and I'm just really lost and confused with all this.
    public class BoardPanel extends JPanel
    public BoardPanel()
    this.setPreferredSize(new java.awt.Dimension(500,500));
    this.setLayout(new javax.swing.OverlayLayout(this));
    public void paintComponent(Graphics g)
         super.paintComponent(g);
                   g.drawImage(backgroundImage,0,0,getWidth(), getHeight(), null);
    private Image backgroundImage = new ImageIcon("./board.jpg").getImage();
    In main init code:
    BoardPanel boardIcon = new BoardPanel();
    JPanel content = new JPanel();
    getContentPane().add(content, java.awt.BorderLayout.CENTER);
    content.add(boardIcon, java.awt.BorderLayout.CENTER);

  • Help please- Recovering Images

    I have a blackberry Z10, someone in my house deleted all of my pictures and i have no SD card so this is all internal memory. IS there any software that i can have a shot at to help recover this. Note- i have no SD card Thank you

    dfgsdhjkfsd wrote:
    I have a blackberry Z10, someone in my house deleted all of my pictures and i have no SD card so this is all internal memory. IS there any software that i can have a shot at to help recover this. Note- i have no SD card Thank you
    Sorry my friend, but they are lost unless you have a backup using BlackBerry Link
    Using the Playbook and the Z10 and the Z30 and loving them
    Martin

  • PSE newbie frustrated, please help with image resizing

    Hi!
    Tutorials aren't helping me, nor is trial and error. I just want to resize some photos I downloaded to my computer, then upload them to a website to use as my avatar or signature. There are specific pixel dimensions I must adhere to. I want to keep the photo in it's entirety, but when I resize it, it distorts a bit, looks fuzzy...
    I can't figure out what the heck I am doing wrong. Some pictures turn out just fine and others look really bad. I know it can be done because I've seen the same pictures I'm trying to size, being used for the same thing I want to use them for, but theirs are clear, absolutely no distortion whatsoever. The pixel dimensions I have to work with are either 100x100, or 450 pixels wide by 90 pixels high.
    I hope this made sense, I'm not sure how else to word it. Please forgive my ignorance, I've really been trying.
    Thank-you
    B

    For an avatar it’s possibly best to crop to begin with so you get a true square.
    Open the image and select the crop tool and change the aspect ratio to 1 x 1 or 5 x 5 then drag out a square and move the image around inside it or drag the bounding box borders until you have it looking as you want. Then click the green check mark.
    On the top menu click Image > Resize > Image Size and in either the height or width box type 100 px (you only need to type the dimension once the other box will change to 100 automatically. Make sure you have the bottom three boxes checked:
    Scale Styles
    Constrain Proportions
    Resample Image
    With all three checked set the bottom dropdown to Bicubic and then hit OK.
    If you want to apply some sharpening select Enhance on the top menu and choose Unsharp Mask.
    Make sure the Radius is no more than 1.5 and use the amount slider to get the image looking as you want it then save.
      

  • HP Photosmart Premium c309g-m does not have a mirror image print option-help please

    After twice being dropped from HP chat support I have laned in this forum to get some help please.
    I need to be able to print mirror images from my printer and it simply is not a option-it's not a matter of turning on the
    option, it is not there at all.
    Thanks
    Donna

    Check the iron-on packaging for ink specs.   Make sure to use HP iron-on paper.
    Say thanks by clicking "Kudos" "thumbs up" in the post that helped you.
    I am employed by HP

  • I had all photos on a Windows desktop.  Got a mac laptop, installed LR5, and put all images from Windows onto an external hard drive.  When I go to import them into LR on the Mac, they are all locked.  Help, please.  Thanks

    I had all photos on a Windows desktop.  Got a mac laptop, installed LR5, and put all images from Windows onto an external hard drive.  When I go to import them into LR on the mac, they are all locked.  Help, please!

    "I plugged the external into the Mac and moved a folder of images onto the desktop.  It looks like it went from read only to not locked.  Is this possible?"
    Yes, that's exactly what happened. If you buy another drive, you could copy from your existing drive to the new and your files will be read/write. The new drive will have to be formatted as an HFS drive (that's the Mac's format). If you need to format it, you use Disk Utility which is in the Utilities folder on your Mac. Be careful with that -- it wipes out whatever is currently on the drive. Make sure you format the right drive.
    I keep all my images on an external drive, too. In fact, I have two matching drives and sync them so I always have a backup.

  • Please help, my Canon Image Formula P-215 will not work w/ Mavericks

    Please help, my canon image formula p-215 will not work w/ the new mavericks upgrade, is there a work around?

    I ran into the same problem, I posted what worked for me in another topic in this forum:
    https://discussions.apple.com/message/25208435#25208435
    Hope it helps

  • Podcast image not displaying! Help please!

    Hello,
    any help on this would be greatly appreciated as I've been troubleshooting for the past month and can't seem to fix this...
    i recently had my podcast channel approved but the podcast image is still not displaying...
    when I followed the instructions given by Apple on their podcast start up page, I opened iTunes, clicked File, clicked Subscribe to Podcast and entered my RSS feed address.  Everything displayed fine, image was working an everything.
    however, the channel has now been approved and the image is still not showing up in the iTunes store....
    does it usually take a while for images to display?
    my image is 1900x1902 and is 2.5 MB.
    Does it have to be perfectly square in order for it to be displayed? If so, how come it displayed when I entered the feed url after clicking 'Subscribe to Podcast' in the iTunes File menu?
    Is there a size limit? Again, if so, how come it displayed when I entered the feed url after clicking 'Subscribe to Podcast' in the iTunes File menu?
    THank you for your help.
    regards,
    J

    The image filesize is much too large at 2.5MB: it must be less than 500kB and I'm surprised your feed wasn't rejected in the first place because of this. I would recommend reducing the dimensions to 1400 x 1400 to be on the safe size, and reducing the file size to below 500kB is essential (and it must be JPG or PNG).
    When you've changed it, also change the file name, amend the feed and reupload it. It will take quite some days before the image appears in the Store.
    The image appears in My Podcasts view when subscribing but probably the iTunes application - which is completely separate from the Store - isn't so fussy. The Store caches the image so you can see why they would want to limit the filesize, given the many thousands of podcasts in the Store.
    When you have a question please always post the URLs of your Store page and of your feed. I was able to give you an answer this time, but in most cases it's necessary to be able to look at the feed.

  • I am trying to download Firefox 3.6 to use on my Mac OS X version 10.3.9. Three attempts and I continue to get "mounting failed" and "corrupt image". Help please?

    I am trying to download Firefox 3.6 to use on my Mac OS X version 10.3.9. Three attempts and I continue to get "mounting failed" and "corrupt image". Help please?

    Firefox 3.6 requires at least OS X 10.4, the last version of Firefox that worked on OS X 10.3.9 was Firefox 2.0.0.20 which is available from ftp://ftp.mozilla.org/pub/mozilla.org/firefox/releases/2.0.0.20/mac/

  • Have photoshop cs5 installed on desktop..got new Canon rebel T5i camera...cannot open RAW images...updated and installed plug-in...still now working.  Need help, please.

    I have photoshop cs5 installed on desktop...got new Canon rebel T5i camera...cannot open RAW images...updated and installed plug-in...still not working...help please.

    In any event, that camera was first supported by ACR version 7.4 which needs at least CS6 to run.  Naturally, all later versions support it too.
    Your choice is either to upgrade your Photoshop, or to look for, download, install, launch and run the free, stand-alone Adobe DNG Converter 8.6 on each folder containing your raw Canon files to convert them first to raw DNGs that you can open in CS5.
    In no case does an Adobe application belong "on your desktop".  The default install location should always be respected and left alone.

  • LR3-Library-Export-Image Resizing:  Specifying Pixel WxH results in different WxH - tips please?

    This is a multi-dimensional question (he he).  I understand my problem is related to the original/developed WxH ratio.  If the pixel WxH I spec in Export-Image Resizing doesn't match that developed proportion, the results are not what I want.  In other words LR3 keeps the original/developed proportion and not what I want for that export.  Ok, so I just answered my own question - but..... please give me some library or export tips for doing what I want to do.
    What I do:
    1 - I edit my images in RAW and like to keep them in their original proportions from my Canon camera as that is the proportion of HxW i use the most
    2 - Later, if the image is really good (at least I like it), I may export it for different purposes and then may choose or require a different proportion.
    3 - I would really like to not have to re-crop in Develop, then go back and Export, then go back to Develop and change it back to original. 
    Besides being tedious and time consuming, can anyone recommend a better way for me to do these "one off" exports (seems to happen more often lately) without screwing around in Develop and messing up my original work?
    Background:
    One of the reasons I do this is to create wallpapers for computers, for various printing/framing proportions, and then for web site situations.  Windows XP (and I think the others) gets really slow if the program must re-size an image for wallpaper (why? go ask Mr. Gates... better get in line).  So to keep performance high, it is best to create the image in the exact pixel dimensions of the monitor.  This is always some weird number and not like anything else I do this for.  The other reason is for a quick, custom print job for someone who wants an odd matting setup for framing (don't ask).  This results in odd proportions.  Regarding the web.... well smooshing a pic into a column etc. etc...    Now while I am proud of my art and understand LR3 will expect me to re-crop to preserve my artistic brilliance, but really..... I would be happy with a proportional crop from the parallel sides of the offending dimension.
    Also, when I spec a dimension, shouldn't the DPI gray out?  What am not understanding here?
    One last request: please give me tips on solving for world peace... this one really bugs me. 
    Thanx in advance! 

    Bruce,
    As you correctly noticed, the WxH ratio in export represents a canvas, into which the exported image is fit. Here are some illustrations on what the different settings mean:
    For what you are trying to achieve, you have to crop the image to the correct dimensions before doing the export. If I had to do it, I would create virtual copies of the original image as the last step and give each virtual copy its own crop, then export the virtual copies.
    Bruce in Philly wrote:
    Also, when I spec a dimension, shouldn't the DPI gray out?  What am not understanding here?
    The DPI resolution has no meaning for the size of the resulting image if you specify pixels in your export dimensions. But the resolution tag is written into the image, which might affect the way an image is printed, depending on the printing application.
    But if you specify your export dimensions in inches or cm, the resolution together with the dimensions in inch/cm determine the size of the resulting image in pixels. I.e. if you specify 5x7" and 300DPI, your exported images size will be 1500x2100 pixels.
    Beat

  • Can anyone help please with my Time Machine, I have been getting the following message The backup disk image "/Volumes/Mac Backup/Stephen Smith's iMac.sparsebundle" is already in use.

    Can anyone help please with my Time Machine, I have been getting the following message The backup disk image “/Volumes/Mac Backup/Stephen Smith’s iMac.sparsebundle” is already in use.

    See > http://pondini.org/TM/C12.html

  • I have an older Mac desktop, version 10.5.8. I need to reinstall Image Capture. Help, please.

    I have an older Mac desktop, version 10.5.8. I need to reinstall Image Capture. Help, please.

    Do you have the original gray system disks that came with the computer, or a full retail install disk set for 10.5? If so, you can use a utiltiy:
    http://charlessoft.com/pacifist_olderversions.html
    to extract just Image Capture from the disk and install it. Otherwise, you  would have to reinstall the entire OS

  • My MBP didn't recognise my password, started it in safe mode, I can see my files, but I don't know what to do next, as the image of reset password isn't selectable. I just moved from PC. Need help please...

    My MBP didn't recognise my password, started it in safe mode, I can see my files, but I don't know what to do next, as the image of reset password isn't selectable. I just moved from PC. Need help please...

    Safe mode is not what you want in this case. Reboot to recovery mode - hold down cmd-R as the Mac reboots. Go past the language-selection screen, click the Utilities menu, then Terminal. Type:
    resetpassword
    Followed by the return key, and follow the prompts. Reboot normally when done.
    Matt

Maybe you are looking for