Resizing image in GUI

Hey everyone,
I want to display an iexternal image (ie an image file image.jpg) in a frame, but when the frame is resized by the user ( it should only be resized in set proprtions) it will rezise the image displayed.
Im new to GUI programming and am not sure how to do this. Can anyone help please ?
Many Thanks,
d-_-b.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       

Without looking at the API, I remember there's something about Image.getScaledInstance(). You need to run that when the frame's size-change listener receives an event.

Similar Messages

  • Which approach to use for resizing image

    There are two ways of resizing images as I know:
    1. image.getScaledInstance(width,height,hint);
    Using hint like Image.SCALE_AREA_AVERAGING gives somehwat satisfactory resizing.
    2. static BufferedImage resize(GraphicsConfiguration gc, BufferedImage source, int w, int h, Object hintValue) {
    BufferedImage result = gc.createCompatibleImage(w, h, source.getTransparency());
    Graphics2D g2 = result.createGraphics();
    g2.setRenderingHint(RenderingHints.KEY_INTERPOLATION, hintValue);
    double sx = (double) w / source.getWidth(), sy = (double) h / source.getHeight();
    g2.drawRenderedImage(source, AffineTransform.getScaleInstance(sx, sy));
    g2.dispose();
    return result;
    where the hint passed is RenderingHints.VALUE_INTERPOLATION_BILINEAR ;
    Now which of the two method method should I use-using image.getScaledInstance() or using AffineTranform ? opr is there any other way which is faster but provides good result?
    i am creating an image editor, so the GUI dialog will have oprtion to choose the algorithm. I want the method which provides better result yet faster.
    Tanveer

    http://forum.java.sun.com/thread.jsp?forum=20&thread=522483

  • Resizing Image objects to keep inline with JFrame width?

    Hi,
    just wondering if you had a GUI with an image in it, how you would code an image object to resize itself to keep its scale relative to the JFrame its in, if that frame was being resized by the GUI user?
    Thanks!

    Previously I'd say just use getScaledInstance() on the image. Then I read this article: [The Perils of Image.getScaledInstance()|http://today.java.net/pub/a/today/2007/04/03/perils-of-image-getscaledinstance.html]

  • Need help on quality of resized image!!

    I am required to resize images to max 1240pixel (longest dimension) as a submission of work, though when work is viewed it will be at 30"x40".  Can not figure out a way to do this where images don't become quite pixelated when viewed at larger size.   Appreciate any suggestions. 

    Is there some software to verify if my graphics card is shotty?
    Techtool Pro has some testing, the AHT tests VRAM, but game benchmarks and stressing will tell you the most.
    Is re-seating the graphics card or memory worth trying?
    Absolutely. Just don't reinstall the graphics card until you clean it thoroughly.
    Cleaning the dust out of my machine?
    YES. A dust filled graphics card heatsink will cause the GPU to cook, and cause problems thet you describe.
    If I need a new graphics card, what are my options? Do I have to purchase it via Apple store? I would like to stick with an Nvidia card so am I stuck buying the same card I currently have or can I upgrade?
    You don't have to buy from Apple, but using with OS X limits your choices to Mac compatible or flashable PC versions.
    There is an awful lot of user input into this topic here:
    http://blog.macsales.com/602-testing-those-new-graphics-cards
    Card reviews can also help:
    http://www.anandtech.com/video/showdoc.aspx?i=3140&p=9
    http://www.tomshardware.com/reviews/radeon-hd-4870,1964.html

  • I need some help resizing my images on PS6. I am using a mac and have been trying to resize with same resolution and constaining proportions but for some reaseon the smaller resized image appears pizelated.

    I need some help resizing my images on PS6. I am using a mac and have been trying to resize with same resolution and constaining proportions but for some reaseon the smaller resized image appears pizelated. Heres an image of before and after. The first image I use is a JPG 72dpi 1500px x1500px and I want to downsize it to 600x600px same res, but it keeps pixelating, this has never happened before. Any suggestions, thoughts?
    thanks!

    I wouldn't say pixelated; more like blurry.
    Like ConnectedCreative said, what steps are you using? Are you using "bicubic sharper" when resizing down?

  • Upload and Resize Image not inserting filename in database

    I have a form that I created using the insert record form wizard. One of the fields is a file field and my form enctype is set to multipart/form-data. I then used the upload and resize image behavior and set the parameters. When testing the form the file uploads to the correct directory but no entry is made into the database for that particular field. The other fields are entered into the database just fine. If it helps, here is the code generated before the  tag:
    <br />
    <br /><?php require_once('../../Connections/test.php'); ?>
    <br /><?php<br />// Load the common classes<br />require_once('../../includes/common/KT_common.php');<br /><br />// Load the tNG classes<br />require_once('../../includes/tng/tNG.inc.php');<br /><br />// Make a transaction dispatcher instance<br />$tNGs = new tNG_dispatcher("../../");<br /><br />// Make unified connection variable<br />$conn_test = new KT_connection($test, $database_test);<br /><br />// Start trigger<br />$formValidation = new tNG_FormValidation();<br />$tNGs->prepareValidation($formValidation);<br />// End trigger<br /><br />//start Trigger_ImageUpload trigger<br />//remove this line if you want to edit the code by hand <br />function Trigger_ImageUpload(&$tNG) {<br />  $uploadObj = new tNG_ImageUpload($tNG);<br />  $uploadObj->setFormFieldName("picture");<br />  $uploadObj->setDbFieldName("picture");<br />  $uploadObj->setFolder("../images/");<br />  $uploadObj->setResize("true", 120, 0);<br />  $uploadObj->setMaxSize(1500);<br />  $uploadObj->setAllowedExtensions("gif, jpg, jpe, jpeg, png, bmp");<br />  $uploadObj->setRename("auto");<br />  return $uploadObj->Execute();<br />}<br />//end Trigger_ImageUpload trigger<br /><br />// Make an insert transaction instance<br />$ins_team = new tNG_insert($conn_test);<br />$tNGs->addTransaction($ins_team);<br />// Register triggers<br />$ins_team->registerTrigger("STARTER", "Trigger_Default_Starter", 1, "POST", "KT_Insert1");<br />$ins_team->registerTrigger("BEFORE", "Trigger_Default_FormValidation", 10, $formValidation);<br />$ins_team->registerTrigger("END", "Trigger_Default_Redirect", 99, "../team.php");<br />$ins_team->registerTrigger("AFTER", "Trigger_ImageUpload", 97);<br />// Add columns<br />$ins_team->setTable("team");<br />$ins_team->addColumn("id", "NUMERIC_TYPE", "POST", "id");<br />$ins_team->addColumn("sort", "NUMERIC_TYPE", "POST", "sort");<br />$ins_team->addColumn("name", "STRING_TYPE", "POST", "name");<br />$ins_team->addColumn("title", "STRING_TYPE", "POST", "title");<br />$ins_team->addColumn("description", "STRING_TYPE", "POST", "description");<br />$ins_team->addColumn("picture", "FILE_TYPE", "FILES", "picture");<br />$ins_team->setPrimaryKey("id", "NUMERIC_TYPE");<br /><br />// Execute all the registered transactions<br />$tNGs->executeTransactions();<br /><br />// Get the transaction recordset<br />$rsteam = $tNGs->getRecordset("team");<br />$row_rsteam = mysql_fetch_assoc($rsteam);<br />$totalRows_rsteam = mysql_num_rows($rsteam);<br />?>

    If the reason is about memory, warning message should be happened when upload the image, because "show thumbnail" means resize at second time, how come you failed to resize the picture that system let it upload succeed at the first time by the same resize process?
    upload procedure
    a.jpg: 2722x1814, 1.2mb
    upload condition: fixed width 330px, 1.5mb
    "upload and resize" a.jpg -> file upload -> "resize engine" -> passed (but not work and no warning message)
    "show thumbnail" a.jpg -> "resize engine" -> failed (not enough memory)
    it doesn't make sense.
    and you miss an important key point, I upload the same picture myself, and resize work, so I said it happened at random, and that's why I am so worried.

  • Resize image in pdf file

    I need to resize image in pdf ,
    I get this [http://www.java2s.com/Tutorial/Java/0419__PDF/Positionandresizeanimage.htm]
    I try to put the code in my servlet
    but I get error on not static method on PdfContentByte cb = writer.getDirectContent(); how to deal this problem
    Thank You

    PdfContentByte cb = writer.getDirectContent();There is no such method in the JDK or the Servlet API.
    Ask whoever provides it.

  • Resizing images published through flickr, but I don't want it to.

    I set up a flickr connection with LR3, very cool. However it resized the image to 1024x768, though I have nothing set under 'resize'. Why is it doing that?  Do I have to set it to resize everything to 9000 pix and not enlarge for it to keep the original size?

    Setting the resolution to 9000 x 9000 wont make any difference. Or at least it did not for me.
    It could be a limitation of Flickr (no Pro account). Perhaps it is different with a Pro account.size file is being uploaded if you dont resize on output but you wont see it if you dont have a Pro account.
    In fact, from the Flickr site: Only smaller (resized) images accessible (though the originals are saved in case you upgrade later)
    This would suggest that your original size file is being uploaded if you dont resize on output but you wont see it if you dont have a Pro account.

  • Problem with getting resized image's bytes

    I've got a problem with getting correct bytes of a newly resized image. The flow is that I retrive an image from the filesystem. Due to the fact that it is large I resize it to a 50x50px thumbnail. I can display this thumbnail in #benchmark1 (see code below). Unfortunately something's wrong with my imageToBytes funtion which returns reasonably small size of image but is totally useless - I can't make an image of it anymore so at #benchmark2 the application either crashes or keeps freezing. I saved this byte array on my disk and tried to preview under Windows how does it look but I got a message "Preview unavailabe". I did some digging in the Internet and I supposed that it's because I don't use any jpg or png encoders to save the file. Actually I think that it's not the case, as the bytes returned from method imageToBytes look weird - I cannot even make a new image of them and display it without any saving in memory.
                                  byte[] bytes = FileHandler.readFile (
                                          FileHandler.PHOTOS_PATH, fileName);
                                  Image img2 = Image.createImage (bytes, 0, bytes.length);
                                  img2 = ImageHandler.getInstance ().resize (img2);
                                                    //#benchmark1
                                  bytes = ImageUtils.imageToBytes (img2);
                                  img2 = Image.createImage (bytes, 0, bytes.length);
                                                    //#benchmark2my imageToBytes function is as follows:
         public static byte[] imageToBytes (Image img)
              int[] imgRgbData = new int[img.getWidth () * img.getHeight ()];
              byte[] imageData = null;
              try
                   img.getRGB (imgRgbData, 0, img.getWidth (), 0, 0, img.getWidth (),
                           img.getHeight ());
              catch (Exception e)
              ByteArrayOutputStream baos = new ByteArrayOutputStream ();
              DataOutputStream dos = new DataOutputStream (baos);
              try
                   for (int i = 0; i < imgRgbData.length; i++)
                        dos.writeInt (imgRgbData);
                   imageData = baos.toByteArray ();
                   baos.close ();
                   dos.close ();
              catch (Exception e)
              return imageData;
    I've run totally out of any idea what's wrong, please help!
    Edited by: crawlie on Jul 17, 2010 6:21 PM                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               

    Hey Crawlie,
    Please note that simply writing int values into ByteArrayOutputStream will not suffice. Please have a look at the following conversion from int pixel value into byte[4]:
    public static final byte[] intToByteArray(int value) {
            return new byte[] {
                    (byte)(value >>> 24),
                    (byte)(value >>> 16),
                    (byte)(value >>> 8),
                    (byte)value
    }Good Luck!
    Daniel

  • Resizing Image and Not Keep Aspect Ratio

    Is there a free program to resize images and not keep the original aspect ratio?
    I need to resize loads of images to 100x100 pixels and have tried Image well and IResize yet they do not seem to have an option to not keep the original aspect ratio.
    Thank you
    20" Intel 2GHz Core Duo imac, 2GB Ram, 250 GB HD    

    Hi, Downsize does not seem all that great according to reviews. Why not see if you can buy PS E' 3 mac -- maybe ebay/amazon (if I remember I only paid about $70 for PS E3) As PS E4 just came out I'm sure someone has PS E3 for sale. You will then have no problems completing your image resizing.
    2 other questions for you..are you using the Mac side of your intel or Windows?
    if your using the Windows side I can let you have PS 6 (PC) ..freegratus.

  • Resizing images

    I am using Photoshop CS (older version).
    I am having a problem with resizing images. Prior to sending this, everything was working okay and now nothing will resize. my file path was file menu > automate > batch > and then I would choose my source and destination for the resized images. In the end, all the newly resized images would stay the same size as before. Can someone please help me with this???

    Neil,
    Have you selected the "resizing" action in the Batch dialog?

  • Cannot resize image

    I opened up PSE 4.0 today and I resized an image and it said that it was resized (6x9 became 5x7, for example), but when I dragged it to my project, it was still the same size (not smaller)! Prior to today, it has always been the size that I wanted it to be. I have not changed anything in PSE so I am wondering if anyone knows how to fix this so I can resize images again.
    Thanks so much!

    Hey Erica,
    You can resize the image using the move tool even after placing it in the project.
    Cheers,
    Chhaya

  • Cannot Resize Images in Elements 8

    Hi,
    I recently had my laptop stolen and I had to reinstall in Elements 8 on my new computer. Since then, I have unable to resize images. I go to Image -> Resize -> Image Size and the pixel dimensions box is grayed out and I am unable to change the pixel dimensions. The document size function works fine and is not grayed out.
    It's very odd and frustrating. Perhaps a simple fix, but I am totally stumped.
    Thank you for any assistance you can give.

    In order to change the pixel dimensions you must first turn on the Resample Image checkbox, since shedding or adding pixels necessarily involves resampling. Try it with that turned on.

  • Iphoto resize images

    I am new to iphoto and need to constantly resize images for internet use. How do I change the resolution or pixels??????? or what ever Mac might call it.
    thank you SO much
    Eleanor

    Personally I have never liked iPhoto for doing anything with an image. GraphicConverter for the Mac is a VERY extensive graphics application that can do about anything you care to do to an image. It is not the same type of program as Photo Shop but you can check it out for a free trial.
    Back to iPhoto, you can go to Share in the menu and email the photo to yourself at one of 3 sizes. This changes the resolution. And yes, Macintosh uses words like pixel and resolution just the same as everyone else.

  • How to resize image with high quality

    I refer lot of examples in image resizing. But quality of resized image not good. pls can give me solution for that with code?

    I refer lot of examples in image resizing.Have you read [_this article_|http://today.java.net/pub/a/today/2007/04/03/perils-of-image-getscaledinstance.html]?
    db

Maybe you are looking for

  • IMac Won't Boot - Grey Loading Bar - Disk Repair Fail

    My 3 month old 27" iMac (late 2013) running Mavericks will not boot up. It was smooth sailing till I'm listening to music and my iMac starts slowing down and freezing. It was so bad I had to hard restart. After I booted up the problem continued. I ra

  • Pl/sql encoding javascript parameter problem

    I am using an html form to get user input via radio buttons via the following segment htp.p('<input type="radio" value="a" onSelect="saySomething('fish')">'); However, when the brackets surrounding (fish) are encountered an error occurs Line No. 41 :

  • Short Dumps in BW Production System

    Hi BW Experts, When iam loading the PCA data (0PCA_C01), i am getting the following Short Dumps in my Systems. DBIF_RSQL_SQL_ERROR RAISE_EXCEPTION TSV_TNEW_PAGE_ALLOC_FAILED TSV_TABH_POOL_NO_ROLL_MEMORY TSV_TNEW_OCCURS_NO_ROLL_MEMORY SYSTEM_NO_ROLL T

  • Invalid Adapter Name

    Hello Experts, I found some posts on this but they did not serve the purpose. We had a newly installed ECC5.0 system with XI, We uploaded JDBC drivers through SDM tool. We are trying for a IDOC2JDBC Scenario and it is the first In the communication c

  • Query in understanding of htf.anchor

    Hi , Can someone help me in understanding the below piece if plsql code which is embedded in htf.anchor. Is the following code will show the output like the one table will be formed with one row where a link will be visible and if we click on that th