Getting an area out of an image

Hi there!
I have a JPanel which displays an image and a small rectangle that can be dragged around with the mouse.
I need to create a new image that has just the size and the position of my rectangle and display that copy in another JLabel or panel.
(Just like this) one.
Tutorial says:
Graphics.drawImage(Image img,
                   int dx1, int dy1, int dx2, int dy2,
                   int sx1, int sy1, int sx2, int sy2,
                   ImageObserver observer)But I don't see how I can copy that area to another image.
How to do that?

If you are using a BufferedImage do the following to the source image and then manipulate the returned BufferedImage how you like.
BufferedImage getSubimage(int x, int y, int w, int h)Returns a subimage defined by a specified rectangular region. The returned BufferedImage shares the same data array as the original image.
Parameters:
x, y - the coordinates of the upper-left corner of the specified rectangular region
w - the width of the specified rectangular region
h - the height of the specified rectangular region
Returns:
a BufferedImage that is the subimage of this BufferedImage.
Throws:
RasterFormatException - if the specified area is not contained within this BufferedImage.

Similar Messages

  • When I copy a CD onto my macbook pro I sometimes get several songs that are "out" of the album.  How do I get them all together in one album?  Any help will be much appreciated!

    When I copy a CD onto my macbook pro I sometimes get several songs that are "out" of the album.  How do I get them all together in one album?  Any help will be much appreciated as I cannot seem to find the solution to this problem in the troubleshooting section of iTunes.

    Generally all you need do is give tracks from the same album a common Album Artist. See Grouping tracks into albums. The images need an update but the basic info. still holds.
    tt2

  • 2008.04-RC Images are out

    http://www.archlinux.org/news/389/
    A new batch of install images is currently syncing to mirrors.
    FTP images have been made available tonight, while CORE images
    will be pushed tomorrow night in order to distribute the load.
    This marks the first release (well ok... release candidate)
    based on a true live Arch system. That is, what's on the
    images is just a plain old base installation which just
    happens to boot off of a CD or USB stick.
    Whoah... did you just say USB stick? Why yes I did! That's
    right, from here on out we'll be offering bootable USB disk
    images that can act as a live system or installer.
    The installer script itself is roughly the same as it's always
    been. The most noticable change is the use of UUIDs instead of
    sdX/hdX entries by default. A more detailed changelog
    should be visible on projects.archlinux.org soon-ish.
    If you get the chance, please give the images a spin. You can
    find them on our mirrors, in the
    iso directory. Please file bugs if you encounter any problems.
    By the way, the "RC" status of these images should not be a
    turn-off if you're looking to install Arch, there's a very
    good chance they'll work just fine for you.
    Ready. Set. Go!

    Mikko777 wrote:
    <trimmed>
    On with install: Two choices to boot, I have no idea what the legacy ide boot option is/does. Then there is two login options arch and root, yet no idea what arch login is used for.
    Second try: Selects the mount points, that i made in first attempt. Now this could be better since having sda1-4 doesn't say much so i guessed they were made in same order that in autopartitioner. Seeing partition sizes would make mounting easier imho.
    Now I noticed I still have US keymap and i wonder if I could've changed it before starting installation, well its a minor annoyance.
    Installs whole base. Proceeds to hwdetect, it does its job. So previous arch installs worked without changing config files, they seem to be there now too. Fstab looks quite empty tho. No sda mount points here.
    Proceeds to install grub. There still seems to be the vga=773 help text was hoping to see the new v86d as default.
    Gets scared by the uuids, those prolly make manual editing / fixing of grub pretty impossible.
    Reboot: Sees old uglier grub again, would've wanted to see the same Grub as in archinstaller. Overlord changed to core dump again
    So fstab was indeed wrong. Root seems to be mounted readonly, Sucks
    du -cH /  is Total=462M and 113M in /var (didn't keep downloaded packages)
    So it works. Now if there would be fbcondecor/ splash option, new kernel and ext4 in filesystem choices ah it would be perfect.
    ah and yes fstab would've been populated :'(
    The legacy-ide boot option is for those machines (like my desktop!) that tend to suck under the new pata subsystem. You would probably know if you needed it (mostly SiS chipsets).
    Trying not to come down on you hard, but this is the typical cries for "more more more!" that we really want to make a conscious effort to stay away from- an installer should be lean and mean, which a touch of color. Want a graphical grub installer on your host system? Use grub-gfx from community, just like we did, but we aren't going to force that on everyone. People come to Arch because we don't patch the heck out of our packages. Want v86d? Well I don't, so its not going to be default. But no one is stopping you from installing and using it, and it saves us the hassle of misconfiguration woes.
    With that said, thanks for all the feedback- Simo and I are glad to see people are trying these out. Are most people using the ISO image still, or have people ventured to using the USB images?

  • My photos are out of chronological order after the os 5 upgrade.   How can I get them back in order?

    My photos are out of chronological order after the os 5 upgrade.   How can I get them back in order?
    If its not possible, how do I go back to the old  os?

    I had tried that several times with no luck.  Late last night I was finally able to get through  to the Verizon technical support who then called in Apple technical support.  It took 1 1/2 hours for them to figure it out and guide me through a fix.  So here's the deal .......... I use Yahoo mail and had left the "contacts" button in the on position.  Apparently Yahoo likes to go into your contacts and gather information and can leave it in shambles.  My advice is, go to settings, then mail, contacts, calendars.  Select any and all of your email accounts and go in and turn off their access to your information.  Leave it on for Icloud but none of the others.

  • IOS5.0.1 constant error "iPhone can not make or receive calls.  Restore from iTunes":  I get this message and the phone will no longer work (happend once while on airplain mode and now once while in wifi only area, out of cell range).  help!

    All- I get this message ("iPhone can not make or receive calls. Restore from iTunes" (happend once while on airplain mode and now once while in wifi only area, out of cell range)). iPhone 4.  Newest OS.  Never happened with old OS! Cycling phone on/off does not help.  Ignoring message causes phone to cycle off then on.  After first time this happened, I restored.  Six days later...same problem!  Clearly a new fix is necessary.  Suggestions? 

    I have not tried that...I will look up the process so that I can do it correctly (and still transfer all of my files, contacts, etc).  Any suggestions?  What is the advantage of restoring as a new device..is this more akin to a complete wipe of a hard drive?

  • My music is organized on my computer but the songs under the albums are out of order on my ipod, they weren't before, i've restored, still out of order. what do i do to get them in order?

    My music is organized on my computer but the songs under the albums are out of order on my ipod, they weren't before, i've restored, still out of order. what do i do to get them in order?

    Have you tried creating a playlist for your album, then
    select the playlist in iTunes.
    right-click the playlist name -> select +copy to play order+. -> sync.

  • I have just downloaded Mac OS X 10.9 and Pages 5. When I open any pre-existing document in the new Pages the format is zoomed to 125%, the headers are out of position, the margins are changes, and inserted images are also relocated. What can I do?

    I have just downloaded Mac OS X 10.9 and Pages 5. When I open any pre-existing document in the new Pages the format is zoomed to 125%, the headers are out of position, the margins are changes, and inserted images are also relocated. What can I do?

    Have you tried resetting the SMC ?     >  Resetting the System Management Controller (SMC)

  • I just upgraded to the latest software for my pages.  When I opened an old document it stripped out all the images I had in my tables.  How do I get them back

    I just upgraded to the latest software for my pages.  When I opened an old document it stripped out all the images I had in my tables.  How do I get them back

    Don't save. Close the documents.
    Pages '09 should still be in your Applications/iWork folder.
    Pages 5 will damage/alter older files, something Apple didn't tell its users.
    Pages 5 is a severely stripped down version with over 90+ features removed.
    We recommend trashing/archiving Pages 5 after Exporting any files you may have saved back to Pages '09.
    Also rate/review Pages 5 in the App store.
    Peter

  • We are trying to transfer files from PS Elements 13 to our web builder.  We are getting a '?' in the top left hand corners of some of the image boxes. It seems that we are unable to transfer images with this ? on the image.  We have spent a long time taki

    We are trying to 'reconnect' files.  we seem incapable to do so, for some reason.  Try as we might, we aren't able to do it.  can anyone help?

    Please see other thread
    Re: We are trying to transfer files from PS Elements 13 to our web builder.  We are getting a '?' in the top left hand corners of some of the image boxes. It seems that we are unable to transfer images with this ? on the image.  We have spent a long time

  • How do I get rid of the annoying yellow banner saying "some plugins are out of date on this page."

    Since 5/22/12 I have an annoying yellow banner in Firefox (and other web pages) stating that "some plugins are out of date on this page.") How do I get rid of this? I've checked my plugins and I'm fine for my Mac OS (10.4.1).

    Sounds similar to this thread from yesterday: [https://support.mozilla.org/en-US/questions/927963 How do I stop getting the prompt to update plugins? | Firefox Support Forum | Firefox Help]. Do any of the suggestions there help?

  • How do I get my songs out of the cloud?  Seems like there are issues and won"t let me sync..

    How can I get my songs out of the cloud?  Seems like there are issues, any new purchased songs are not syncing with Ipod 3rd generations.

    Do you have the original installation disc(s) that shipped with your MacBook? You're just going to have to start from scratch - as I doubt that you can recover any files without paying a fortune. Insert the installations disc, reformat your hard drive and then install the OS that came with your computer. Continue updating to 10.6.8 and then redownload and reinstall Mountain Lion again.
    That's really the only way you're going to get your machine up and running again. I would also consider buying an inexpensive external drive to use as a backup in case your brother decides to do something stupid again.
    Clinton

  • I cannot get out of the French ITunes Store to get to the USA store. I did find the US  flag on my IPad in I tunes at bottom of music page and switched to US flag !) but when I go back to trying to update my Apps I still get: you are in the French Store!!

    I cannot get out of the French ITunes Store to get to the USA store. I did find the US  flag on my IPad in I tunes at bottom of music page and switched to US flag !) but when I go back to trying to update my Apps I still get: you are in the French Store!! Aquavero

    See  >  Change your iTunes Store country
    Here  >  http://support.apple.com/kb/HT1311
    Settings > iTunes & App Stores > Apple ID: > View Apple ID > Country/Region = Change Country / Region

  • When using fireshot, my extensions are duplicating. I get a .jpg.jpg on every image downloaded

    When using fireshot, my extensions are duplicating. I get a .jpg.jpg on every image downloaded

    Try Fireshot support for help with their software. <br />
    http://screenshot-program.com/fireshot/ <br />
    http://screenshot-program.com/sup/index.php?a=vforum&f=12

  • I have a brand new Nano Ipod 7th Generation.  I can't get any sound out of earphones.  Yes, have pushed the cord all the way in.  Screen shows tunes are playing, but I can't hear anything.  Volume bar shows volume all the way up.  Now what?

    No sound out of earphones.  Yes, cord is all the way in the jack.  Screen shows tune is "playing", but I can't get any sound out.  Help

    If this is the case, I recommend to visit Apple store to request for replacement. Cheers!

  • I have to save as CMYK for print, but the colours are out of whack..

    hey all,
    I am designing something for a CD cover that is going to be printed at a print shop, They say they want their images in CMYK and prefer it in a PDF or highest quality JPEG....
    So I have been working in CMYK, everything looks fine in photoshop, but when I save out to a JPG the whole thing gets dark and colours get horribly over saturated.
    here you can see the image on the left is what happens when I save out directly from my CMYK file in photoshop. there is a big loss in detail in the darker areas and colours are over saturated. the image on the right is what I get if I convert to mode>RGB and then save the JPG. .. . .this is what I want it to look like....
    my problem is the print shop requests the image in CMYK, but I want them to print like it looks in the RGB version
    any help would be greatfully appreciated! Thankyou!
    also here are the actual .jpegs as saved from photoshop
    the CMYK version:
    and the RGB version:
    edit: I don't know too much about colour profiles, and the print shop hasn't provided one on their site, so I picked the default one - Working CMYK, U.S WebCoated (SWOP v2)
    edit: these are the file formats the printers say they take on their site:
    PDF - 300 dpi - (preferred), Tiff, Highest resolution JPG, EPS
    I don't really have any experience with the other formats but I presume I would get the same colour results

    Thanks all for the replies.
    Just to be clear the file is already in CMYK (U.S web coated SWOPv2), I understand now its probably smarter to work in RGB and then convert at the end but hadn't done so in this case.
    If I change image mode to RGB (or vice versa) i notice a tiny shift in the colours on my monitor but nothing as dramatic as what im seeing in those CMYK Jpeg/TIFF's.
    John Danek -
    there are probably more than 20 layers in there, my colour settings should all be default because ive never even looked in there before, but here is a screenshot of the dialogue box
    and the bit depth is 8-bits per channel
    If I save it out as a CMYK .pdf then it looks fine, presumably because im opening it in Adobe acrobat reader so it can see the embedded profile. So I think this is the problem after all, thanks Chris Cox and gator soup for clearing that up!
    I have emailed the printers and asked if they can read my embedded profiles correctly with their software (presumably they can) and asked for them to recommend an ICC colour profile but have yet to hear back from them.

Maybe you are looking for