How to save component to jpg without jframe

the code shows 2 methods to save component to jpg,
but if comment
f.getContentPane().add(lb);neither saveJPG_1() nor saveJPG_2() works.
can you explain why and how to work without jframe?
thanks.
public class Test1 {
      * @param args
      * @throws Exception
     public static void main(String[] args) throws Exception {
          new Test1().run();
     private void run() throws IOException {
          JLabel lb = new JLabel("Test Text");
          lb.setOpaque(true);
          JFrame f = new JFrame();          
          f.getContentPane().add(lb);
          f.pack();
          saveJPG_1(lb, new File("test1.jpg"));
          saveJPG_2(lb, new File("test2.jpg"));
          f.dispose();
     private void saveJPG_1(Component c, File file) throws IOException {
          Dimension dim = c.getPreferredSize();
          Image im = c.createImage(dim.width,dim.height);     
          c.paint(im.getGraphics());          
          ImageIO.write((RenderedImage)im, "jpg", file);
     private void saveJPG_2(Component c, File file) throws IOException {
          Dimension dim = c.getPreferredSize();
          BufferedImage im = new BufferedImage(dim.width,dim.height,BufferedImage.TYPE_INT_RGB);                    
          c.paint(im.getGraphics());
          ImageIO.write(im, "jpg", file);
}

Lazy loading is common place among variety of
systems.
Java GUI runtime must be doing it because on my
Linux/JDK 1.6(build 61), component c is null at:
c.paint(....);
when adding onto contentpane is commented out.Lazy loading means classes are loaded on demand and at the last moment possible. What makes you think that this allows for a variable to be null even after the component has been instantiated? And what does the Java "GUI runtime" have to do with it? It's the class loader that's responsible for this. It should be impossible for c to be null at that point in the code. You're using a beta JDK though right? Perhaps that's the culprit.
the code shows 2 methods to save component to jpg,
but if comment
f.getContentPane().add(lb);neither saveJPG_1() nor saveJPG_2() works.
can you explain why and how to work without jframe?
thanks.
public class Test1 {
      * @param args
      * @throws Exception
public static void main(String[] args) throws
s Exception {
          new Test1().run();
     private void run() throws IOException {
          JLabel lb = new JLabel("Test Text");
          lb.setOpaque(true);
          JFrame f = new JFrame();          
          f.getContentPane().add(lb);
          f.pack();
          saveJPG_1(lb, new File("test1.jpg"));
          saveJPG_2(lb, new File("test2.jpg"));
          f.dispose();
private void saveJPG_1(Component c, File file)
) throws IOException {
          Dimension dim = c.getPreferredSize();
          Image im = c.createImage(dim.width,dim.height);     
          c.paint(im.getGraphics());          
          ImageIO.write((RenderedImage)im, "jpg", file);
private void saveJPG_2(Component c, File file)
) throws IOException {
          Dimension dim = c.getPreferredSize();
BufferedImage im = new
ew
BufferedImage(dim.width,dim.height,BufferedImage.TYPE_
INT_RGB);                    
          c.paint(im.getGraphics());
          ImageIO.write(im, "jpg", file);
Can you display a JPanel on the screen without help? No. At some level it has to go back to a heavyweight widget. In this case the JFrame is that widget, so without it or a supplement you can't create the graphics context to create an Image of what that JPanel would look like displayed.

Similar Messages

  • How to save Pdf form localy without internet

    How to save Pdf form localy without internet?
    I thought in the beginning about advanced user rights and pure saving them on adobe reader but i saw legal notes about 500 user who can legaly save it localy and answer to me (bu they can`t answer to my client who paid me for doing this form).
    Other thing is to do Air Application which would collect data from Pdf Form and save it (localy without internet) to use it later.
    I thought about that second possibility but i can`t find any clue to do it myself.
    Any help will be appreciated...

    Hi,
    Are you downloading responses as PDF forms after forms are submitted? If so, FormsCentral doesn't provide an option to exclude empty fields and you won't be able to save PDF forms without empty fields.
    You can use this form to "vote" on popular feature requests, or to add a new one of your own:
    https://adobeformscentral.com/?f=XnF-KJVCovcEVQz9tZHYPQ
    Thanks,
    Wenlan

  • Officejet 6110xi, How to save scan as .jpg?

    officejet 6110xi, How to save scan as .jpg?

    Hello jpg0, and welcome to the HP Forums, I hope you enjoy your experience!
    I see you are looking into your scan settings.  I would love to try and help you, but I do need a little information first. I am linking a few HP Support documents below that will show you how to find which operating system you are using. Also, if you're using Windows, please include whether your operating system is 32-bit or 64-bit. With this information we can provide you with accurate information.
    Mac OS X: How Do I Find Which Mac OS X Version Is on My Computer?
    Which Windows operating system am I running?
    Is the Windows Version on My Computer 32-bit or 64-bit?
    Please let me know what you find, and thanks for posting on the HP Forums!
    Please click “Accept as Solution " if you feel my post solved your issue, it will help others find the solution.
    Click the “Kudos, Thumbs Up" on the right to say “Thanks" for helping!
    Jamieson
    I work on behalf of HP
    "Remember, I'm pulling for you, we're all in this together!" - Red Green.

  • How  to read Component profile.properties without using CAF?

    Do you know how to read DC WebDynpro Component profile.properties without using CAF.
    A Component.profile.properties is located under
    Scr/components/fullcomponentname/
    Thanks, Best regards
    Peter

    import com.sap.tc.webdynpro.services.sal.config.api.IWDConfiguration
    import com.sap.tc.webdynpro.services.sal.config.api.WDConfiguration;
    import com.sap.tc.webdynpro.services.sal.deployment.api.WDDeployableObject;
    import com.sap.tc.webdynpro.services.sal.deployment.api.WDDeployableObjectPart;
    import com.sap.tc.webdynpro.services.sal.deployment.api.WDDeployableObjectPartType;
    WDDeployableObjectPart myComponent = WDDeployableObject.getDeployableObjectPart
      "mycompany.com/myapp~mydc" // name of DC
      "com.mycompany.myapp.mydc.MyComponent" // full component name
      WDDeployableObjectPartype.COMPONENT
    IWDConfiguration config = WDConfiguration.getConfigurationByName
      myComponent
      "profile.properties" // not sure, try "profile" as well
    Exception handling ommited.
    Hope this helps. Just wondering what's for?
    Valery Silaev
    P.S. full disclosure: CAF developer, author of PropertyConfigurable components concept

  • Save vi to jpg without displaying vi

    So I have a vi that takes in a file and displays it on a graph, with all sorts of fancy options on it. One of those options is to save the graph to a jpg. When you go to save it as a jpg, it opens another vi with a special layout and sets up all sorts of text on the front panel of this subvi. Then it saves the front panel to a jpeg.
    I have another vi that is a batching program for my graphing vi. This vi takes in a directory of files, and then background loads the graphing vi, and proceeds to queue up commands and graph the files and save them. The graphing vi is set up so that when you save to jpg while batching, it does not load the front panel. This is done because if you're processing a huge list of files, you don't need a vi popping up a bunch of times.
    My problem is that if I don't pop the front panel of the save subvi, it doesn't draw the graph, and so even though it updates all the text and graph information (axis names and stuff like that), it doesn't draw the graph because I don't display it. Is there a way to get LabView to draw this graph without popping the front panel?
    The main reason I want to solve this is that the batching program actually handles several different kinds of graphing (I'm building it modularly so I'm solving this one vi at a time), and in the end I don't want several windows popping up every time I save a graph, per file batched.
    Thanks!

    I'm seeing the same thing you are...
    I made 2 VI's:
    "SendDatatoSubVI" creates an array of random data, and passes that data and a string to "FP-to-Image1"
    "FP-to-Image1" plots the data on a graph, and saves the front panel image to a .jpg file.
    If "FP-to-Image1" is in memory (but not necessarily open), the .jpg file saved has the data on the graph. If I close both VI's, then open just "SendDatatoSubVI" then the first time it is run, there is no data the graph. I have seen 2 ways to make it work every time:
    Option A) In the sub-vi's Window Appearance property, set the "Window runs transparently to 100%"
    Option B) In the sub-vi't Window Run-time Position property, set Position to "Minimized"
    In the main VI, be sure to set the SubVI Node Setup to "Show front panel when called" and "Close afterwards if originally closed"
    I'm using LabVIEW 8.5.
    Message Edited by LabViewGuruWannabe on 01-16-2008 07:15 PM
    Message Edited by LabViewGuruWannabe on 01-16-2008 07:16 PM
    Message Edited by LabViewGuruWannabe on 01-16-2008 07:16 PM
    Message Edited by LabViewGuruWannabe on 01-16-2008 07:19 PM
    Attachments:
    SendDatatoSubVI.vi ‏10 KB
    FP-to-Image1.vi ‏21 KB
    fpimage1.jpg ‏28 KB

  • How to save data in CallableObject without completing the action

    Hello,
    we have a process with actions with callable objects. Some of these actions cannot be completed within a short time, but still are an "atomic task". Thus we'd like to save the data entered so that it is there again when calling the action at a later time again. This would also make it possible for the employee of a team to really take the task (eg. by pressing a button "take this task") and for the other to see, who is in charge.
    How can data be written into the GP context (eg. LocalContext of the CallableObject), without completing the action (eg. by setting a result state)?
    We do not want to build LoopBlocks where the same Action is called and completed multiple times, each time adding an other "Iteration X"-entry in the navigation.
    Best regards,
    Manuel Schaffner

    Hi,
    I dont think there is any way of passing data back to GP context without completing the callable object. If you wish to save the data locally then you can probably use CAF business objects.
    Ashutosh

  • How to save a new jpg image from the clipboard

    It seems like it should be simple but I can't find anywhere this has been documented.
    I have an image on the clipboard and simply want to save it as a new image.
    I've been using Image Events and I can get a file saved but it's always empty.
    Can someone please post some sample code to do this?

    I'm sure there's a more elegant way to script this, but here is a script I just wrote real quick that should at least give you a start to an alternate way of dealing with clipboard data without having to launch Preview...
    <pre style="width:630px;height:auto;overflow-x:auto;overflow-y:hidden;"
    title="Copy this code and paste it into your Script Editor application.">--see if clipboard is a file
    set filePath to ""
    try
    set clipPath to the clipboard as «class furl»
    set filePath to clipPath as alias
    end try
    if filePath is not "" then
    set newFile to getFileName("copied")
    do shell script "cp " & quoted form of POSIX path of filePath & ¬
    space & quoted form of POSIX path of newFile
    return --end
    end if
    --see if clipboard is image data
    set jpegDATA to ""
    try
    set jpegDATA to the clipboard as JPEG picture
    end try
    if jpegDATA is not "" then
    set newFile to getFileName("new")
    set theFile to open for access newFile with write permission
    write jpegDATA to theFile
    close access theFile
    return --end
    end if
    beep 1
    display dialog ¬
    "No file or image data found on the clipboard." with icon ¬
    note buttons {"Whatever"} default button 1
    on getFileName(type)
    choose file name with prompt ¬
    "Select a name and location for the " & type & ¬
    " jpeg:" default location (path to desktop) default name ¬
    type & ".jpg"
    end getFileName</pre>
    Hope this helps...

  • How to save .psb in .jpg

    Hello, I'm need a help . so a creat a file .. in real size .. 140x800cm its with 2.72gb ( i didnt get to put the screen shot here ) so i had flattened the layers.. but i didnt get to save in jpg .. i need to print it as a adhesive... may somebody help me ?
    currently using photoshop cs6 extended, os lion 10.8.2., i7 quad 2.4ghz , 8gb ram

    Read up on the requirements for such stuff and how people are actually gonna use it. Nobody does (car) stickers at 300dpi. I really strongly suggest you read up on that stuff and that old resolution vs. pixel dimensions vs. physical dimensions... You have only made your life difficult by creating such a humungously large file for no apaprent need...
    Mylenium

  • I am in hurry,how to save  the xml file without attributes

    i have the following xml file with attributes,
    <?xml version="1.0"?>
    <Ve2.Configuration>
         <Ve2.Displaymanager>
              <type type="combobox">eVeDisplayStandardType</type>
              <setCounter type="bool">false</setCounter>
              <frames type="textfield">20</frames>
         </Ve2.Displaymanager>
    </Ve2.Configuration>
    but i want to save it without attributes, that means, my saved xml file look like this.:
    <?xml version="1.0"?>
    <Ve2.Configuration>
         <Ve2.Displaymanager>
              <type >eVeDisplayStandardType</type>
              <setCounter >false</setCounter>
              <frames20</frames>
         </Ve2.Displaymanager>
    </Ve2.Configuration>
    how can i do it with java.

    If you know the format of the XML file, then you can write a straight forward XSL file to transform it.
    Paul
    www.codetelligence.com

  • How to save an SVG file without opening it in a browser tab first?

    Sometimes I have to download very large SVG files. These files are generated dinamically by a web server, when I select some options in a web form. Thus, there is no link to click: an action on the web page causes Firefox to spawn a new tab and try to open the SVG file inside it. The file can be very large, and Firefox can get stuck in trying to display it, before I can right-click on the image and select "save as" to get the file I'm interested in.
    I would like that, upon requesting an SVG web resource, Firefox ask me how I want to deal with the resource: displaying it online, opening with an external application, or saving it - exactly in the same fashion as with PDF files.
    Thank you!

    The only way to get Firefox to offer to save the SVG image would be to force a content type that Firefox doesn't recognize as supported natively.
    *Mason: https://addons.mozilla.org/firefox/addon/mason/

  • How to save fillable pdf form *without* the blue highlight?

    Created a fillable pdf form.
    Clicked "remove highlight" and it went away.
    Saved file as extended other so I can fill in and save when opened.
    Open it and it still has all fields highlighted in the blue. How to I change this to be transparent?
    Thanks so much!
    Carolyn Witt

    Thanks for the respons... if that is the case how come when I open fillable pdf's in AA from other people there is no highlight. But when I open the one I just created, there is highlight. That's all on the same computer with the same preferences?

  • How to save files to disk without losing image quality

    Hi, I'm a Visual Basic developer and I'm doing an acquisition system with a CCD camera and 1408 IMAQ framegrabber. I need to save the images into a hard disk. My problem is that when i begin to save images to disk, the acquisition's performance come down (the images gets slow).
    Now I'm using the ActiveX CWImaq provideing by National Instruments.
    I would be grateful if you would send me any advice.
    regards.

    There is a really good tutorial on the developer zone called IMAQ Acquisition, Images, and Displaying in Visual Basic , which talks also about buffered image acquisition in Visual Basic.
    You can find built-in examples of how to do buffered image acquisition in the following folder with the default path: C:\Program Files\National Instruments\NI-IMAQ\Sample\VB\
    I hope this helps!
    Regards,
    Yusuf C.
    Applications Engineering
    National Instruments

  • How to save and retrieve jpg/gif format image in db2

    Here am facing problem to insert jpg/gif format image in my database. And at the same time i would like to know how to retrieve that and how to display that image in my html page. So please help me in this matter.

    In future JDBC questions should be posted into the JDBC Forum

  • How to save a large jpg from a small eps

    I created a logo in ai cs5 that is the size of 7w x 4h. But I wanted to be able to create a larger jpg. Since the vector format allows for the image to be scaled, is there a way to scale it larger, then create a jpg at this larger size? Or, is there a way to scale it to 500% and then save it as a new file with this enlarged size being 100%? I'm fairly new to AI, but have used PS for quite some time, so please be gentle.
    Thanks,
    Don

    Jacob,
    Thanks. That helped for the large jpg. I appreciate it.
    Don

  • How to save graph to jpg file ?could you give me a demo vi of lv6.1 ?thanks

    thanks

    You could use an "invoke node" for the graph with method "get image". See attached LV6.1 code.
    LabVIEW Champion . Do more with less code and in less time .
    Attachments:
    SaveJPG61vi.vi ‏29 KB

Maybe you are looking for