Scaling up and down BufferedImages by percent?

Hi, I have a BufferedImage and I would like to know the exact syntax to scale up and down an image by percentage. Basically I want to scale the BufferedImage by a specific percentage like scale down to 50% or scale up to 150%. Anyone know any methods to do so? If I can use a specific library then which library can I use and how to use it(clear syntax like: profileImage.scale(50);)
I read an image using the following:
BufferedImage profileImage = ImageIO.read (new File ("Image.bmp"));And I would appreciate if the libraries imported are posted too. Thanks
Edited by: Taufiq on Feb 26, 2008 2:54 PM

Demo:
import java.awt.*;
import java.awt.geom.*;
import java.awt.image.*;
import java.io.*;
import java.net.*;
import javax.imageio.*;
import javax.swing.*;
public class ImageResizingExample {
    public static void main(String[] args) throws IOException {
        URL url = new URL("http://blogs.sun.com/jag/resource/JagHeadshot-small.jpg");
        BufferedImage image = ImageIO.read(url);
        if (image == null) throw new NullPointerException();
        Image smaller = scaledInstance(image, 0.5);
        BufferedImage blurry = rescaled(image, AffineTransformOp.TYPE_NEAREST_NEIGHBOR, 1.5);
        BufferedImage better = rescaled(image, AffineTransformOp.TYPE_BICUBIC, 1.5);
        display(image, smaller, blurry, better);
    static Image scaledInstance(BufferedImage im, double factor) {
        int w = (int) (im.getWidth() * factor);
        int h = (int) (im.getHeight() * factor);
        return im.getScaledInstance(w, h, Image.SCALE_AREA_AVERAGING);
    static BufferedImage rescaled(BufferedImage im, int hint, double factor) {
        AffineTransform xform =  AffineTransform.getScaleInstance(factor, factor);
        return new AffineTransformOp(xform, hint).filter(im, null);
    static void display(final Image... images) {
        EventQueue.invokeLater(new Runnable(){
            public void run() {
                JPanel cp = new JPanel(new GridLayout(0,2, 5, 5));
                for(Image image : images) {
                    cp.add(new JLabel(new ImageIcon(image)));
                JFrame f = new JFrame("ImageResizingExample");
                f.setContentPane(cp);
                f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
                f.pack();
                f.setLocationRelativeTo(null);
                f.setVisible(true);
}

Similar Messages

  • Video scale up and down suggestions

    Please help me form some basic coding plan for scaling up and down the video at run time when I
    open a digital scrap book.
    The idea is very simple.. I have a Digital Interactive scrap book which will flip to the page which has the event housed on that page and will show a Thumbnail of the event. In the meantime the Loader will keep loading the movie file and show a progress bar. Once when the loader is done with, I want the Video to scale up to the size of the Stage and then play the video and once the file has reached the end it should scale down the video and go back to the Index page-the home page whioch started this..
    Please help me sir, as I am not good with action script but wit your guidance I will make all efforts.
    Thanks

    You can just tween the width and height of FLVPlayback to the stage width and height and move the position to (0, 0).

  • My 3g is getting shut down on 40 percent and not turning on until plunged in

    my 3g is getting shut down on 40 percent and not turning on until plunged in

    Hi S,
    Did they have you try an SMC Reset: http://support.apple.com/kb/HT3964?

  • Make object fit browser window when scaling it up and down?

    I want to add a flip book on my page. But i want it to scale up and down, so it will fit both a 13" screen as well as a 27" screen. Is this even possible?

    Hi,
    Please take a look at this for a similar discussion : https://forums.adobe.com/message/6264647#6264647
    Regards,
    Aish

  • s:BitmapImage get image scaled size and position after it loaded and scaled

    I am try to know the dimensions of the uploaded image into <s:BitmapImage without success.
    The data coming back to me are isthe real image size and not size after it was scaled to fit the component size.
    I can see that the image scaled down and fit to the maxWidth, but I can't get the actual/real scaled width from the BitmapIMage properties.
    I tried:
    <s:BitmapImage id="mainBitMap"  ready="mainBitMap_readyHandler(event)" complete="bitmapimage1_completeHandler(event)" source="{data.Thumbnail.URL}" maxHeight="250" maxWidth="250" scaleMode="letterbox"/>
      protected function bitmapimage1_completeHandler(event:Event):void{ 
    trace("----------------------Start-----------------------"); 
    trace("mainBitMap.bitmapData.width" + mainBitMap.bitmapData.width); 
    trace("mainBitMap.width" + mainBitMap.width); 
    trace("mainBitMap.measuredWidth" + mainBitMap.measuredWidth); 
    trace("mainBitMap.displayObject.width" + mainBitMap.displayObject.width); 
    trace("mainBitMap.explicitWidth.width" + mainBitMap.explicitWidth); 
    trace("mainBitMap.preliminaryWidth" + mainBitMap.preliminaryWidth); 
    trace("mainBitMap.sourceWidth" + mainBitMap.sourceWidth); 
    trace("-----------------------End------------------------");
    Result:
    ----------------------Start-----------------------
    mainBitMap.bitmapData.width=435
    mainBitMap.width=0
    mainBitMap.measuredWidth=0
    mainBitMap.displayObject.width=0
    mainBitMap.explicitWidth.width=NaN
    mainBitMap.preliminaryWidth=NaN
    mainBitMap.displayObject.preliminaryWidth=435
    -----------------------End------------------------
    Thanks,
    Nimrod.

    Hi,
    I tried the ready event, But I still receive the same results.
    I expect to get the new scaled width And height according to the maxHeight and MaxWidth.
    I see that the image scaled to fi it But I can't recive the new size of it.
    Thanks,
    Nimrod

  • IPhone 6 plus battery shuts down at 3 percent

    I have a problem my 2 week iPhone 6 plus shuts down at 3 percent but when I connect the lighting cable it reboots immediately and shuts down again it takes 2 automatic boot up before it stays on, I do never had this type of problem it is weird because it shuts down automatically like if the batter is drain at 3 percent when I connect the lighting cable it boots up and shuts down automatically and then boots up again and then it stays on but showing at a starting point at 3 percent I do not know why this happens... Also my battery drains very quick it takes only 1 day when I have to recharge the phone, this never happen before it took me up to 2 days to drain completely the battery now it takes only one day of normal use...

    I am in the same situation you are.  I called the fraud dept, was on hold for over an hour, confirmed everything and was told I would get the phones on the 19th.  The interesting thing is that my son got text messages on his phone to call the fraud dept even though my phone is the main number.
    Customer service tells me something different every time I call to make sure I have an order.

  • I downloaded Maverick and now I can't open pages from the Dock.  The Pages icon just jumps up and down abut doesn't open.  However, I can one pages by clicking on the App. I have an iMac with iWork 08.

    Since upgrading to Maverick from Mountain Lion I am unable to open Pages from the Dock.  When I click on the pages icon in the dock the icon just keeps bouncing up and down.  However, I can open pages by clicking on the icon in the Apps folder.  No problems prior to upgrading to Maverick.

    Quit Pages. Drag its icon out of the Dock. Create a new one by dragging the application into the Dock. Test.

  • At times when dragging the vertical scroll bar my computer screen oscillates up and down for some time before going blank or not responding to any clicks requiring a forced system restart. What is wrong?

    Hi,
    Suddenly while working with Firefox if I happen to drag the vertical scroll bar, a very abnormal behavior occurs. My screen dances up and down for a short time before either going black or getting restored but with no clicks working. The only way to resume is to force a restart of the system.
    Any help would be deeply appreciated.
    Thanks and Regards
    Deepak

    That didn't work. On trying to install a new driver I got the error the graphics driver could not find compatible graphics hardware. Is there anything else that can be done to at least prevent the hanging of the computer even if it means less features from Firefox being available?

  • Touchpad no longer scrolls up and down on Satellite A

    So my HD crashed and i have to completely install Windows and all the Toshiba stuff with it a new.
    All is well - except for one thing, my touchpad no longer scrolls up and down using the side of it in IE or Chrome, but it still works in SeaMonkey.
    My Computer technician tells me it's an issue with getting some new driver for the touchpad, and i think i had to do that already about a year ago when i still had my original HD running.
    So i went to the Toshiba.ch website and tried to find something.
    I found all their "verfication" stuff and got inside the system and it instantly returned about 45 drivers by the looks of my "un"-driving eyeys they all could have been for whatever, so i searched especially for "touch pad" and yes, there was one for my Synapsis touchpad and XP as well, so i downloaded it - or i should say i opened it in Win Zip and checked first on the "readme file - wow, that was some Portugese in there, and that's when i kind of begun to feel lost.
    I check in at Toshiba.ch, get a ton of drivers in my face i have no clue whether i am supposed to download them all or what, and when i finally pick what i think i need the whole thing seems to be in Portugese, what the crickey in the afternoon is this???
    Anyway, before i download and try to install stuff i have no clue about i was hoping someone would actually give me a better hint on what i have to do exactly to get my touchpad to scroll up and down again also in Chrome, IE and where ever else.
    I use Service Pack 3 on Win XP Pro and was told that's maybe why the old original driver for this laptop needs to be updated, but which file, where to get it, and how to properly install it please anyone???

    Thanks for that, you confirm what i actually found out myself in the meantime.
    The way i got this issue solved was that i first tried to download and install the Synaptics driver from the Toshiba site - that simply failed miserably, glad with no negative side effects at least.
    Nesxt i used what unfortunately is way easier that sites like the Toshiba overload, i used Google to simply find the Synaptics website and instantly got the link to their driver download - eh voila, that actually gave me a .exe file, not an endless array of zipped files like the stuff on the Toshiba site in endless language versions!!!
    This worked, tested everything out alread since a while.
    - Which now leaves me with the question about the second driver you mentioned,
    Alps Electric
    what is that one needed for??
    I have not seen this name on my lappy before, so totally unsure about whether it still needs this dispite things are working everywhere, i did not even have to go into the Device Settings of the Mouse / touchpad to change or rearrange anything in there after the direct download from Synapsis, but well informed is always best, so if you could let me know about that
    Alps thing would appreciate...

  • CS4 Text around a bottom curve but text straight up and down?

    I have to change the names on bottles that were shot and so I am trying to type the names. 1st I tried Photoshop and could not get the 3D to work and could not get the arc or the warp to work correctly.
    So I went over to Illustrator. I finally got it figured out how to get the text on the bottom of the curve and reading corectly... BUT... the text on the R side of the curve, curves into the curve instead of each letter staying straight up and down horizontally. Help please? Nothing like being short on time and having to figure out how to get the text on a curve with the letters staying straight up and down instead of curving into the curve. Thank you!!!

    OK. I did that but now I am trying to copy paste into my Photoshop file but when it comes out of Illustrator... It brings an odd white box that is really messing me up!!! Why won't it let me just copy the text? Why is Illustrator making an extra white box that is blocking my image? Thanks. See the 2 below.  1 is the bottle before I have gotten the name over and the other, is the bottle when I am trying to paste just the text in place. For some reason, Illustrator is adding a white box that is messing me up?  1 is how it should look. 2 is Illustrator is making an extra white box that is covering up most of my bottle.

  • I am having the problem when trying to take a panorama picture.   It may only take the first frame or doesn't even start at all when I press the shutter button. even though when i  hold the phone straight up and down, so that camera is at the top

    I am having the problem when trying to take a panorama picture. 
    It may only take the first frame or doesn't even start at all when I press the shutter button.
    even though when i  hold the phone straight up and down, so that camera is at the top on the back and the home button is on the bottom on the front.
    This problem is irritating me....?

    To take panorama
    - ensure that the panorama option is on
    - press the shutter button once
    - you will see a line with an arrow
    - move around in a circle  ( I keep the camera steady and turn myself around in a circle)
    - as you do this you will see the arrow moving across the screen as it captures pictures
    - at the end of the capture, you will be able to see your panorama picture
    I hope that this helps, do report back.

  • Trackpad is presenting a bug to open and close windows, mission control, and to move/roll the application (App) up and down.

    Totally out of the blue, my trackpad is presenting a "bug". Every time that I try to open and close my mission control, or in the moments that I move / roll up and downs the Applications Screen, my Mac freezes for less than a second.
    It never suffered any damage (NEVER!)! I am feeling very frustrated because I have no idea about what could cause such problem.
    My MacBook Air is running OS X 10.9.5.
    Any help will be very welcome!

    Well, it all really depends on the custom program and how it was written. Does it have an ActiveX interface? If it does, than that's the easiest way to go. If you put an automation refnum on the fron panel, you can right click and it and choose Select ActiveX Class>Browse. The browser will list all of the ActiveX type libraries that are registered on your system. If you can find one that refers to your custom program, then you should be able to use it's methods and properties to control. If it does not have an ActiveX interface, then things get much more difficult.

  • ISA credit memos and down payment does not display data  R/3 E-commerce 5.0

    Dear guru's
    The Billing doc search in the ISA searches Credit Memos and down payments. However, system don´t found documents, but business partner have credit memos and down payments.
    Some idea?

    Dear guru's
    The Billing doc search in the ISA searches Credit Memos and down payments. However, system don´t found documents, but business partner have credit memos and down payments.
    Some idea?

  • Program won't load, icon 'bounces' up and down and then...stops!

    Any help please? I click on my Sims 2 icon to load up the game and all of a sudden it's stopped working. The icon bounces up and down in the sidebar and then stops. I have plenty of space to run the game and it's only just started happening.

    Perhaps the game has become corrupted. Try reinstalling the game from the original install source and then apply any available online updates.

  • I loaded iTunes on a new laptop. I copied and pasted my albums to a 4G stick and down loaded them to the new laptop. Placing them in, Libraries – Music – iTunes and than in Itunes used File – add file to library. So far so good. For what ever reason one o

    I loaded iTunes on a new laptop. I copied and pasted my albums to a 4G stick and down loaded them to the new laptop. Placing them in, Libraries – Music – iTunes and than in Itunes used File – add file to library. So far so good. For what ever reason one of the CDs would not load onto the stick. I got the orginal CD and loaded directly to Itunes. Now when I look in  Libraries – Music – iTunes it’s not there but it is in and plays in iTunes. What should I have done or should I be doing? Thanks.

    It's not a unique situation - happens all the time, smaller hard drives getting filled up.
    It's also easy to fix. I just moved my itunes content to a bigger hard drive.
    First I made a backup of the itunes database file - iTunes Library.itl. Just in case anything went wrong.
    Nothing did go wrong, but I'd have it in case anything DID go wrong. That file holds ratings, playcounts, Date Added, and other metadata.
    Second, in itunes change the preferences > advanced tab to tell itunes to put everything on G:
    Set the itunes folder location to something like G:Media or G:iTunes
    This will affect all FUTURE additions to itunes and not do anything to the existing locations.
    Make sure the checkbox for "Keep itunes organized" is NOT checked. I also left the "Copy files when adding" unchecked.
    Third, to move all the files to G: without itunes losing the paths, run the File > Library > Organize > Consolidate command. This will need to run a while, so be patient as it copies all the files to the new G: location. This does NOT delete the originals. You will have to do that.
    Fourth, make sure everything in itunes is OK and you can play stuff in your library. If you're really cautious you can run a script to check for missing/dead tracks.

Maybe you are looking for

  • On start up I hear the chime but nothing comes on display

    On start up I hear the start up chime but can not see anything on display but very vague images

  • Range component in custom item renderer

    Hi, I am trying to put a spark Range component into the labelItemRenderer for flex mobile. Everytime I add it I get the error: "Skin for (long directory name for my range component) cannot be found". The custom item renderer is an actionscipt class b

  • Idoc views updation, Workflow, Performance tuning techniques!

    Hello, Greetings for the Day! Currently my client is facing following issues and they seek an help/attention to these issues. Following is the current landscape of an client. Sector – Mining SAP NW MDM 7.1 SP 09 SAP ECC EHP 5 SAP PI 7.0 List of Issue

  • Distorted when projected - why?

    I recently made a short film, and it played fine in Quicktime on my iMac.  When it was video projected at a film night however the image was distorted - it had horizontal lines running through it and the projector seemed to struggle with blocks of co

  • Perforce issue in loop

    Hi experts,    In my program I have used this loop to populate article text(makt-maktx) and ean number (mean-ean11) in records fetched from mara on the basis of matnr. in my test server mara contains 46k records and in marc there are 80k records corr