How do copy an image from a JComponent?

Hi,
i have a JComponent (in a swing based application) where I draw something on. Now Id like to copy an Image from the JComponent's painting area (no matter if the JComponent is shown or not). How do I get an image of the clipping region?
Is there something like myComponent.getImage(x,y,width,height)?
thanx

Not sure what you are wanting but this might help you,you prob are going to need this for one
http://www.acme.com/java/software/Acme.JPM.Encoders.GifEncoder.html
Here is some code using the package from the link up above.The code below will get that image and copy it and save that image to a file
import java.awt.*;
import javax.swing.*;
import java.io.*;
import Acme.JPM.Encoders.GifEncoder;
class junk extends JFrame{
public junk() {
  super();
  setSize(400,400);
  setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); 
  setVisible(true);
public void paint(Graphics g) {
  Image im = createImage(200,200);
  Graphics gg = im.getGraphics();
  gg.fillRect(0,0,200,200);
  g.drawImage(im,0,0,this);
  pgetImage(im);
  public void pgetImage(Image imm){
   try{
   File file = new File("Mypic.gif");
   FileOutputStream out = new FileOutputStream(file);
   GifEncoder cod = new GifEncoder(imm, out);
   cod.encode();
   out.close();
  }catch(Exception oo){oo.printStackTrace();}
public static void main(String agrs[]) {
     junk ji = new junk();
} good luck

Similar Messages

  • How to copy an image from a photo onto another photo

    Im trying to figure out how to cut and paste an image from one photo onto another. I tried exporting the main photo to a pages document and then inserting the other image, but cant seem to get it to work. Is there an easy way to do this?

    You'll need an image editor for the job:
    In order of price here are some suggestions:
    Seashore (free)
    _[The Gimp|http://www.gimp.org/macintosh>_ also free
    Graphic Coverter ($45 approx)
    Acorn ($50 approx)
    [Pixelmator|http://www.pixelmator.com> ($60 approx.)
    Photoshop Elements ($75 approx)
    There are many, many other options. Search on MacUpdate.
    You can set Photoshop (or any image editor) as an external editor in iPhoto. (Preferences -> General -> Edit Photo: Choose from the Drop Down Menu.) This way, when you double click a pic to edit in iPhoto it will open automatically in Photoshop or your Image Editor, and when you save it it's sent back to iPhoto automatically. This is the only way that edits made in another application will be displayed in iPhoto.
    Regards
    TD

  • How to copy DNG images from MacBook Pro onto a flashdrive and paste them into my pictures on my iMac

    When I tried to do this, I couldn't get the image on the flashdrive to open in photoshop. Each time I tried I got a message that said photoshop had crashed. When the flashdrive is plugged into the MacBook the image files look like images. When the flashdrive is plugged into my new iMac (Maverick) the image files just show the DNG icon. Both computers have the Creative Cloud.

    iTunes: How to move [or copy] your music to a new computer [or another drive] - http://support.apple.com/kb/HT4527
    Quick answer if you use iTunes default preferences settings:  Copy the entire iTunes folder (and in doing so all its subfolders and files) intact to the other drive.  Start iTunes with the option (shift on Windows) key held down and guide it to the new location of the library.
    So, you can see your whole iTunes folder on the memory stick after copying from the PC?

  • How to copy/clone images from cameraUI?

    hi,
    i'm using the cameraUI for taking photos. after taking a photo, i can add it to a movieclip. so far so good.
    the problem now is, that i want to add the image to another movie at the same time for using this movie as a mask within the loaded photo...
    function showMedia( loader:Loader ):void
              bg.addChild( loader );
              loader.width = 960;
              loader.height = 640;
              loader.x=0;
              loader.y=0;
      bg2.addChild( loader );
      loader.width = 960;
      loader.height = 640;
      loader.x=0;
      loader.y=0;
      bg2.mask = myMask;
    unfortunatelly, this doesn't work. it's only possible adding the image to ONE of both movie clips at a time.
    in the example, the image will be displayed as a child of "bg2", "bg" is empty. i've tried to copy or clone "loader"
    but that did not work anyway. it would be great if someone has a simple solution for this issue.
    thanks!
    michael
    solution found: (probably not the best one, however - it works)
    function showMedia( loader:Loader ):void
              bg.addChild( loader );
              loader.width = 960;
              loader.height = 640;
              loader.x=0;
              loader.y=0;
              var bitmap_data:BitmapData = new BitmapData(stage.stageWidth,stage.stageHeight);
              bitmap_data.draw(stage);
      var bm:Bitmap = new Bitmap(bitmap_data); 
              bg_zoom.addChild(bm);
              bg_zoom.x = 0;
              bg_zoom.y = 0;
              bg_zoom.scaleX = 2;
              bg_zoom.scaleY = 2;
    Message was edited by: michael_1974

    Assuming you've referenced the graphics in the first file … you can copy/paste into the new file; you could create a list of referenced graphics (LOF) to help you locate the graphics in the first book more easily. Or, depending on the content of the two books, you could duplicate .fm chapters from the first book and rewrite the text round the graphics :-}
    Scripting is unexplored territory for me, but I imagine it should be possible to type in just the name of each graphics files and then use a script to do the work of setting up the reference?

  • How can I stop other people copying my images from my web site.

    How can I stop other people copying my images from my web
    site.
    I use dreamweaver CS3 for the mac

    both are a waste of time. Fornication with a leaky condom.
    Pointless and not
    worth the effort. Or worse!
    the obfuscation JavaScript will get the site to not be
    listed in any search
    engines because they can't "see" the page or any links on it.
    You would be
    "protecting" the images but no one would find them.
    And all of those obfuscation JS things can be reverse
    engineered. In most
    cases- it's not worth it to prove it can be broken other than
    to prove it
    can be done. The images are nothing special in almost any
    site using one of
    those $29.95 applications.
    Have you done the basics? Turned off directory browsing or
    put a default
    index page in every folder? A few years ago i ran across a
    site with one of
    those block right click scripts on it. Dumb curiosity- opened
    a picture, and
    looked around the directory. All open directories. A block
    right click
    script and every folder on the site was open.
    /photos/private/girlfriend/hottub
    Nuff said. The blocking script made me curious enough to poke
    around the
    directories.
    Alan
    Adobe Community Expert, dreamweaver
    http://www.adobe.com/communities/experts/

  • How do I copy an image from one Keynote presentation to another one?

    I have a previously saved presentation on Keynote in iCloud. I created it from my desktop at work. Some of the images I used for the presentation I want to use again in another presentation, onlh this time I am working off my laptop and don't have the same access to those images. Is it possible to copy/paste images from one Keynote presentation into another? I can't even seem to click on the image and save it.
    Any suggestions?

    Clicking and dragging does not work.
    Click on the image and Copy and Paste
    or
    Inspector > Metrics > File Info > click on the icon of the file and drag it to your desktop
    You can then drag that file back in wherever you want.
    Peter

  • How do I import images from my hard drive without losing resolution? My original files after import are significantly smaller. What should I do?

    How do I import images from my hard drive without losing resolution? My original files after import are significantly smaller. What should I do?

    Hi Keith, and all others chiming in, I do have the correct option checked in advanced settings telling iPhoto to copy the images into the library. What is a refernced library? Perhaps this is where I am getting confused. I exported my entire photo library from an old iMac5 to my external hard drive, from there I attempted to import the entire library to my new iMac. Am I overlooking an obvious and easy way to import from the hard drive to the new iMac--I dragged the entire photo pholder from the hard drive to the open window of iPhoto on the new computer. Now, I only get preview file sizes in iPhoto, unless I have my external drive open. Perhaps I need to import the original images from the hard drive in a different way...?! (This is making me feel pretty stupid.)

  • How do I remove images from Notes app?

    How do I remove images from Notes app?
    I sometimes find that, when cutting and pasting text from the web, an image is also copied (pretty much at all times I try and avoid this, but sometimes the selection process doesn't allow for fine enough control - e.g. a whole block of content may be selected, rather than just the few words I'm trying to copy).
    I then find, once it's part of my note, that I cannot select the unwanted image and remove it. Can anyone tell me if this is something that can be done, and if so... how?
    Thanks, Sebastain

    Hi Drew & Kilgore*
    Thanks for your replies. I also have and use Simplenote, although I went off it for a while, when it started crashing all the time on me. It seems to be more stable again now, so I'll start using it more regularly again, perhaps.
    I am, obviously, disappointed that one can't simply select ANY object within a Notes document and choose to delete it. As I rather suspected, the only solution is an annoying workaround. Apple stuff seems to get more like this as time goes by. At least in my experience.
    I solved the issue my own way in the end, but I guess it was close to your 1st idea DR, and your 2nd option, KT: I basically cut and pasted everything above, and then everything below, the image, and pasted both chunks of text into a new note. So it took two passes, and left me with the original note just displaying the image, which I then trashed.
    Tapping to the right of the image followed by deletion was what I hoped & expected would work. But instead the image stayed put and the text below the cursor would simply slide along the right hand side, moving upwards as I deleted! Most bizarre, to my mind at least.
    Anyway thanks for the feedback. But, for anyone else that might want to know how to do this, the answer is: NO, you can't select and delete an image once it's in one of your notes!
    * I quite recently watched the rather strange Bruce Willis / Nick Nolte 'Breakfast of Champions' movie... I think I still prefer the book to the film!

  • I am a new iPad user and cannot figure out how to copy and paste from a website to pages. Any insight?

    I am a new iPad user. I cannot figure out how to copy and paste from a website to a pages document, and vice versa. Any ideas?

    Long press on the text you would like to select (tapping and holding) and then release after the magnifying glass shows up. This will select a single word. Then use the blue dots and drag them to select a region of test. Then press "copy". Open pages, and long press and release where you would like to paste. Then select "paste". That should paste the text.
    If the text doesn't select within the browser, it might be an uncopyable format. Like if the text was within an image, naturally you would be unable to select it. The only thing to do there is long press the image and selecting "save image", adding it to your camera roll. Then you could insert the image within pages.

  • How can I import images from iphoto with the albums and folders?

    How can I import images from iphoto without losing the albums and folders I already created?

    In Organizer, you can choose File>get Photos and Videos>From iPhoto.
    Importing from iPhoto'09: If in iPhoto, you organize your media using photo references, that is, the media actually does not reside inside iPhoto library package, and are referenced through original locations, Organizer does not create new copies of those media and just refer to the original location. but if your iPhoto media reside inside iPhoto library, Organizer creates a copy all media in your pictures folder, also imports albums and tags and other metadata.
    Importing from iPhoto'011: In this case, Organizer always creates a copy of your photos in your pictures folder which resides inside iPohto package. It does not import the albums and other metadata like star rating, caption etc.
    Hope this information helps!
    regards,
    vaishali

  • How can I download images from my iphone to adobe bridge cs5

    How can I download images from my iphone to adobe bridge cs5?  I don't want to use iPhoto.

    "How can I download photos from my iphone to mac?"
    Same way as with any other digital camera.
    "Do I need to use Iphoto? "
    Yes.
    "Why doesn't my Mac come with Iphoto application? "
    It does. All macs come with iphoto.
    Copying personal photos and videos from iOS devices to your computer

  • How can I extract images from Numbers?

    Sounds a bit stupid but how do you extract images from Apples 'Numbers 3' on a Mac?  I have a client that sends images in XLS files, that normally in Word I would Alt Click and 'save as...'
    I was trying to stop using Word but this simple little feature will make all the difference.
    Can anyone point me in the right direction.
    Thanks,
    Dave

    Hi Wayne,
    Thank you for your response.  Sadly if you do this it copies in to the MACs clipboard as a snap shot of the image at the dimensions in Numbers.
    Eg. 
    An image I've extracted from the document via Excel saved out at it's original dimensions 1024 x 300px, even though it was placed, then scaled down to 300px wide on the sheet.
    Same image copied then pasted in to an image editor (as I couldn't paste into finder) was only 300px wide.
    The feature I need is to be able to save out the original image placed in the Numbers sheet.
    Anyone with ideas on this?

  • How do I get images from Aperture into print shop for mac?

    Friends,
    I have Print Shop for Mac and Aperture. How do I get images from Aperture into Print Shop? I'musing managed images with previews. Is there any option besides exporting to the desktop and importing?
    Thanks!
    Steve

    if you have previews turned on in Aperture and they're all genereated, you can simply drag-n-drop them into any application (just about). drag-n-drop is essentially the same as copy/paste as long as the application is setup to accept "drops" onto its windows.
    otherwise, if you're running Leopard (10.5) as your version of Mac OS X, when you import (or whatever it is in PrintShop), you should get a file selection dialog. from here, scroll down the left-hand side bar set of icons. near the bottom is a group called "Media". click on the triangle to open the group, choose Photos, and from here you should see an Aperture icon. click this and you'll see your whole library (or at least the portion of it that you have previews generated for. select the photo you want and viola!
    scott

  • Why can't I copy an image from photoshop, i can't paste it in anoter computer program ?

    Why can't I copy an image from photoshop, i can't paste it in anoter computer program ?

    Denis Beelog wrote:
    Why can't I copy an image from photoshop, i can't paste it in anoter computer program ?
    Assuming Windows...
    You can, assuming you select around the pixels you want to copy, and the selected region isn't too large.
    There are a variety of ways you can get the copy operation wrong, e.g., by not having the proper layer selected or similar.
    And there's a secret setting to enable Photoshop to export its clipboard no matter how large the selected pixel set is.  Note the setting I have bolded below.  Keep in mind that by making this setting you may be subjecting all the software on your computer that registers to receive clipboard data to datasets that are larger than it might expect.  In other words, there could be a downside.  That being said, I haven't had any problems on my Windows 8 system.
    # Photoshop "special items" user-specific configuration file
    #  Must be named PSUserConfig.txt and be put here:
    #   %USERPROFILE%\AppData\Roaming\Adobe\Adobe Photoshop CC 2014\Adobe Photoshop CC 2014 Settings\PSUserConfig.txt
    #  All possible entries:
    #   AllowAsyncIO
    #   AllowOverScrolling
    #   AllowUserConfigFile
    #   ClipboardMaximumSize
    #   DragBoundingBoxOpacityPercent
    #   EnableGestureRotation
    #   FileStreamDefaultSize
    #   ForceProgress
    #   FullPreviewMaxSize
    #   GPUAllowGLXP64
    #   GPUAllowPBOs
    #   GPUCheckerBoardNodeInBlitPipe
    #   GPUDiableMainWindow
    #   GPUDisallowAdvancedGLRendering
    #   GPUDisallowAppleClientStorage
    #   GPUDisallowCanvasImposters
    #   GPUForceLinearCheckerBoardNodeInBlitPipe
    #   GPUIgnoreMemoryRequirements
    #   GPUShouldNotScootATISelections
    #   GPUUseAceNodeInBlitPipe
    #   GPUUseFloatTextures
    #   GPUUseVBLSync
    #   MemoryAlignment
    #   PDFAllowHugeFiles
    #   PDFPresentationAllowHugeFiles
    #   PreserveEXIFMakerNotes
    #   RecentFilesSlowTimeout
    #   SpringKoadedKeyTime
    #   SyncSmartUploads
    #   TrackPadAllowGestures
    #   UseStagingServer
    #   UseSystemStylus
    #   VMCompressPages
    #   VMDisableBuffering
    #   VMForceBuffering
    # Enable Overscrolling:
    AllowOverScrolling 2
    # Remove the clipboard export size cap
    ClipboardMaximumSize 0
    -Noel

  • How to capture an image from my usb camera and display on my front panel

    How to capture an image from my usb camera and display on my front panel

    Install NI Vision Acquisition Software and NI IMAQ for USB and open an example.
    Christian

Maybe you are looking for

  • Losing calls, calls breaking up on an iPhone 5s

    My phone has been dropping calls, with 3+ bars on it and sometimes I break up on people, again with 3 or more bars. What is going on? The other day I was on the phone and my call dropped and I couldn't call back or receive calls. Is it the phone or t

  • Error while transfering PO in extended Scenario -- error 06 053 in R/3

    Hi, while transfering a PO from SRM to R/3 in extended Scenario we get an error in RZ20(SRM): "No selectable items exist for purchase requisition xxx" --> error number 06 053 Whats happening here? The PR is released in R/3 and yet not transfered into

  • Need Help with Migration...Please

    Hello, I need help!  I just bought a new MacBook Pro.  In house, I have a two year old iMac running Mavericks (all updated) and an iPhone and iPad (both running the most current OS).  I also have the iMac connected to a Time Capsule.  Here are my que

  • Oracle forms and reports in SQL Server

    My company has developed a application in Oracle forms and reports that works with a Oracle database. In the database also exist a lot of triggers, procedures, functions and packages. The application is working perfectly with the Oracle database but

  • Add a Help Link to a Discoverer Portlet

    How can I add a Help Link in a Discoverer Portlet? Even if I have checked the 'Show Help Link on Portlet Headers' in the Portlet Display Options this does not appear in the Portlet.