Saving the graphics2d to JPEG

Hi All,
I need a desperate solution for this problem. I am not able to save the contents of the Graphics2D content into an JPEG/GIF. could you pls tell me where I am going wrong.
private void pathCoordinates(int iOne, int jOne, int iTwo, int jTwo,
                    double y1Diff, double x1Diff,
                  double y2Diff, double x2Diff,
                 int seriesNum, int activeTime){
   Graphics2D g2d;       
   Point2D vOne1 = at.transform(new Point2D.Double(2*jOne-1,2*iOne-1), null);
    Point2D vOne2 = at.transform(new Point2D.Double(2*jOne+1,2*iOne+1), null);
    Point2D vTwo1 = at.transform(new Point2D.Double(2*jTwo-1,2*iTwo-1), null);
    Point2D vTwo2 = at.transform(new Point2D.Double(2*jTwo+1,2*iTwo+1), null);
    double xOne = Math.floor(Math.min(vOne1.getX(),vOne2.getX()));
    double yOne = Math.floor(Math.min(vOne1.getY(),vOne2.getY()));   
    double xTwo = Math.floor(Math.min(vTwo1.getX(),vTwo2.getX()));
    double yTwo = Math.floor(Math.min(vTwo1.getY(),vTwo2.getY()));
    xOne = xOne + x1Diff + 54;
    yOne = yOne + y1Diff + 54;
    xTwo = xTwo + x2Diff + 54;
    yTwo = yTwo + y2Diff + 54;   
    Point2D.Double p1 = new Point2D.Double(xOne ,yOne );
    Point2D.Double p2 = new Point2D.Double(xTwo ,yTwo );
    debug("X1 = " + xOne + " Y1 = " + yOne  + " X2 = " + xTwo + " Y2 = " + yTwo);
    Shape line = new Line2D.Double(xOne ,yOne, xTwo ,yTwo);
         red = (int) (256 * Math.random());         
     green = (int) (256 * Math.random());          
     blue = (int) (256 * Math.random());          
    g2d = (Graphics2D)this.getGraphics();
    g2d.setPaint(new Color(red,green,blue));   
    g2d.setStroke(new BasicStroke(3));   
    g2d.draw(line);
    drawArrowHeads(yOne ,xOne, yTwo ,xTwo, g2d);
    GraphicsConfiguration gc = g2d.getDeviceConfiguration();
    // I tried this options too.. didnt work. gives me either a white or a
    // Black image.
    //  g2d.setColor(Color.white);
    //  g2d.fillRect(0, 0, width, height);
    BufferedImage image = gc.createCompatibleImage(width,height, BufferedImage.TYPE_INT_RGB);
    Graphics g = image.createGraphics();   
    g.setColor(Color.white);
    g.fillRect(0,0,width, height);
    g.dispose();
    try {
        OutputStream out = new BufferedOutputStream(new FileOutputStream("screen.jpg"));
        ImageIO.write(image, "jpeg", out);
    }catch(IOException e){
         debug(e.getLocalizedMessage());
    Timer timer = new Timer();   
    timer.schedule(new TrackingTimerTask(), activeTime);
  }thanks in advance
Domnic

import java.awt.*;
import java.awt.event.*;
import java.awt.geom.*;
import java.awt.image.BufferedImage;
import java.io.*;
import java.util.Random;
import javax.imageio.ImageIO;
import javax.swing.*;
public class Dynamics
    public Dynamics()
        DynamicPanel dynamicPanel = new DynamicPanel();
        ImageSupport imageSupport = new ImageSupport(dynamicPanel);
        Updater updater = new Updater(dynamicPanel, imageSupport);
        JFrame f = new JFrame();
        f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        f.getContentPane().add(updater.getUIPanel(), "North");
        f.getContentPane().add(dynamicPanel);
        f.setSize(400,400);
        f.setLocation(200,200);
        f.setVisible(true);
        dynamicPanel.setImage(imageSupport.createImage());
    public static void main(String[] args)
        new Dynamics();
class DynamicPanel extends JPanel
    BufferedImage image;
    protected void paintComponent(Graphics g)
        g.drawImage(image, 0, 0, this);
    public void setImage(BufferedImage bi)
        image = bi;
        repaint();
class Updater
    DynamicPanel dynamicPanel;
    ImageSupport imageSupport;
    Random seed;
    int R;
    BufferedImage image;
    public Updater(DynamicPanel dp, ImageSupport is)
        dynamicPanel = dp;
        imageSupport = is;
        seed = new Random();
        R = 75;
    private void addLine()
        Point p1 = getLocation(0);
        Point p2 = getLocation(0);
        updateImage(new Line2D.Double(p1.x, p1.y, p2.x, p2.y));
    private void addCircle()
        Point p = getLocation(R);
        updateImage(new Ellipse2D.Double(p.x - R/2, p.y - R/2, R, R));
    private void addSquare()
        Point p = getLocation(R);
        updateImage(new Rectangle2D.Double(p.x - R/2, p.y - R/2, R, R));
    private Point getLocation(int pad)
        Point p = new Point();
        p.x = pad/2 + seed.nextInt(imageSupport.bi.getWidth() - pad);
        p.y = pad/2 + seed.nextInt(imageSupport.bi.getHeight() - pad);
        return p;
    private void updateImage(Shape s)
        Graphics2D g2 = imageSupport.bi.createGraphics();
        g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
                            RenderingHints.VALUE_ANTIALIAS_ON);
        g2.setPaint(Color.black);
        g2.draw(s);
        g2.dispose();
        dynamicPanel.repaint();
    public JPanel getUIPanel()
        final JButton
            line   = new JButton("line"),
            circle = new JButton("circle"),
            square = new JButton("square"),
            save   = new JButton("save");
        ActionListener l = new ActionListener()
            public void actionPerformed(ActionEvent e)
                JButton button = (JButton)e.getSource();
                if(button == line)
                    addLine();
                if(button == circle)
                    addCircle();
                if(button == square)
                    addSquare();
                if(button == save)
                    imageSupport.save();
                    dynamicPanel.setImage(imageSupport.createImage());
        line.addActionListener(l);
        circle.addActionListener(l);
        square.addActionListener(l);
        save.addActionListener(l);
        JPanel panel = new JPanel();
        panel.add(line);
        panel.add(circle);
        panel.add(square);
        panel.add(save);
        return panel;
class ImageSupport
    DynamicPanel dynamicPanel;
    BufferedImage bi;
    public ImageSupport(DynamicPanel dp)
        dynamicPanel = dp;
    public BufferedImage createImage()
        int w = dynamicPanel.getWidth();
        int h = dynamicPanel.getHeight();
        bi = new BufferedImage(w, h, BufferedImage.TYPE_INT_RGB);
        Graphics2D g2 = bi.createGraphics();
        g2.setPaint(Color.white);
        g2.fillRect(0, 0, w, h);
        g2.dispose();
        return bi;
    public void save()
        try
            ImageIO.write(bi, "jpg", new File("dynamics.jpg"));
        catch(IOException ioe)
            System.err.println("write: " + ioe.getMessage());
}

Similar Messages

  • Edit in Adobe Photoshop CS without saving the file

    When I do "Edit in Adobe Photoshop CS" of a RAW file, LR saves a TIFF or PSD file first, then opens it with PS CS. LR should give an option to forward the picture to PS CS through some in-memory inter-process communication, as opposed to saving the photo from LR and re-open it from PS CS. It might be much faster.
    In case, I understand LR would not give the option to stack the edited file with the RAW file.

    David Hill DEH
    >all I want to do is run an action in PS that converts to jpg with a particular filter applied.
    Then turn it into a droplet (you do know how to do that?) and put it in the Exprt Actions Folder and call for it in a Export Preset set for the JPEG you want.
    LR will then on Export run the droplet and save to the folder of your choice.
    Don
    Don Ricklin, MacBook 1.83Ghz Duo 2 Core running 10.4.9 & Win XP, Pentax *ist D
    http://donricklin.blogspot.com/

  • Is it possible when saving the psd file to have an automatic jpg file saved at the same time?

    My work involves preparing images for printing lightboxes and window installations.  My clients require to pre-approve the photos before printing.
    I usually save my files as psd but since the files are very large in this format I usually save another copy as a jpg file that has a much smaller file size.  This makes it possible for me to add these to a presentation and and send them to my client.
    Is it possible when saving the psd file to have an automatic jpg file saved at the same time?  Or do I still have to do this manually?

    If you save the document manually as a PSD file in Phtoshop not from within an Action, Script, Plugin or Droplette.  You may be able to write a Photoshop that would do as save as Jpeg,  And you should be able trigger its execution by setting up a Script Save event using the Script event manager.  When You do a manual save  the script should be triggered.  I wrote may be able to for I have never tried to write that script or set up a Script Manager Save event.  I have only use open events.

  • Saving out .tiff to .jpeg using "Save As"

    Hi peoples,
    I hope you can help me with this saving out issue i have,
    If i open a .tiff from lightroom into photoshop cs6 with LR adjustments, I click "save as" .JPEG in a new location, I am now editing the .jpeg and not the tiff.
    Yet if I open the same .tiff from file explorer and not LR and "save as" .jpeg in a new location, I am still editing the .tiff (This is what i want because i want to create an action which will save multi jpegs into different locations, with various color profiles, i want to ensure these jpegs are the best quality possible, therefore i want them saved from the .tiff as the source and not another .jpeg!)
    Hope you understand
    Thanks for your help

    skywalker2014 wrote:
    Hi peoples,
    I hope you can help me with this saving out issue i have,
    If i open a .tiff from lightroom into photoshop cs6 with LR adjustments, I click "save as" .JPEG in a new location, I am now editing the .jpeg and not the tiff.
    No in both cases your editing a Photoshop Document.  Photoshop is not a file editor. It  open files into a document and it save files from documents. When you save a file the document you were exiting is still open in Photoshop.  The document may have layers  Tiff file camnalso have layers however if a tiff file is layered LR can not handle these layers it does not support layers.  I have no use for lightroom one reason is it lack of layers support.
    skywalker2014 wrote:
    Yet if I open the same .tiff from file explorer and not LR and "save as" .jpeg in a new location, I am still editing the .tiff (This is what i want because i want to create an action which will save multi jpegs into different locations, with various color profiles, i want to ensure these jpegs are the best quality possible, therefore i want them saved from the .tiff as the source and not another .jpeg!)
    Again Photoshop Open files into documents and works on documents.  If you use save as  and save a Jpeg fron a document you opened from a Tiff.  The Save As would not delete the Tiff file there would be two image file on you disk for the image, The original Tiff file and the new saved jpeg.  The image may or may not look the same it depends on what you did in Photoshop before saving the jpeg and wither or not you also save out an updated tiff after you saved the jpeg.

  • Saving RAW edits as JPEG - is it okay if...?

    Just wanted to get some expert opinion on whether saving RAW edits as JPEG is advisable.
    I understand that every time you save a JPEG, there is some loss/degradation, whereas TIFF is loss less. However, given the huge size of TIFF tiles, my thinking is that saving them as JPEG is okay as long as if I want to make subsequent edits, I revert to the original (RAW) and re-do the edits.
    Is there any downside to this logic?

    iPhoto does not keep resaving the same JPG over and over. Instead it applies the new edits to the original file and recreates a new JPG. So no matter how many times you edit the file, you are only one generation removed from the RAW file.
    iPhoto keeps tracks of your edits in a list and reapplies them when you open the file to view.
    Patrick
    edit: here is a reference article...
    http://docs.info.apple.com/article.html?path=iPhoto/7.0/en/11464.html
    Message was edited by: PT

  • "Save As" is saving the date years back.. not current date..??

    I just upgraded to Elements 10 and I've found this problem...
    When I create a scrapbook page and and go to save it as "Save As" for both my PSD & JPG files, it is saving the file date that my background layer was added to my Elements Organizer, no the actual date that I created the page.
    Example:  I created a page last night, I named "JFK.jpg".  When I got to Explorer to upload to Shutterfly and look for the file with details, it shows: JFK.jpg  1709kb    JPEG Fomat    03/28/2008 7:24AM
    I always sort by date to find my most recent pages and this is driving me crazy!!  Please help!  Any Suggestions???

    Two possibilities.
    First create a formula that will give you the date as a text cell.
    If you dates are in the B column then you could add
    =TEXT(B1;"YYYY-MM-DD")
    in the C column. This will then export correctly for you.
    This way means moving columns around of course.
    Second - the format of the data is controlled by your global language settings.
    Tools > Options > Language Settings > Language
    Use the Local Settings drop down to select a local that gives your the format you need. It is a thought any way.

  • Trying to make the jump from JPEG to RAW...

    Hi all, I'm trying to make the jump from JPEG to RAW, and am hoping you might be able to help with a few questions.
    When I open JPEGs in Lightroom's Develop module, the settings are mostly zero by default. But when I open RAW files, some of the settings seem to have non-zero default to values.
    Am I correct to think these settings are from metadata saved into the RAW file when I took the picture? eg, the camera saves the White Balance settings as metadata within the RAW file, even though the White Balance settings don't actually affect the image data itself. And so when I open that RAW file in Lightroom, it'll apply the White Balance as recorded within the file, making that a non-zero default.
    Is that about right?
    Does Lightroom similarly 'pre-set' other values when importing RAW files? (I ask because I seem to have non-zero settings for Blacks, Sharpening, as well as the Color slider under Noise Reduction.)
    Meaning: I'm not quite sure "how much work" Lightroom is doing by default when I import RAW files, and how much I need to do to at least reproduce what my camera would do in making a JPEG.
    For example, even though Color under Noise Reduction is given a value -- Luminance, also under under Noise Reduction, is left at zero. And the picture looks a bit grainy. Would my camera have processed some Luminance Noise Reduction? If so, is there a way to get Lightroom to help get that pre-set too?
    Basically, is there a rule of thumb for how a novice should import a RAW file and have it reasonably "at least as good" as what the JPEG would have been?
    Thanks very kindly, -Scott

    Given that the camera ships with so many special effect presets -- is there no built-in preset that could be named "Auto Camera" so to speak? Or might it be possible import such a preset that somebody else has made?
    Lightroom, nor any other third party raw processing program will not read the camera settings beyond simple stuff such as white balance. So you cannot do this. If you go raw, you really have to change your mindset and completely ignore the in-camera jpeg styles. Just set it to a neutral style and learn what the preview on the camera means for the actual raw data. You will find that this gives you orders of magnitude more creative freedom afterwards as you will not be stuck with a burned in interpretation.
    So (for me) even just making my own presets -- let alone making separate presets for every ISO -- all that seems a bit daunting.
    There really is no need to at all. I don't use presets for example. I think they are a waste of time as it is extremely rare that two images need exactly the same treatment. You really are just choosing a different starting point. I start all my raw at a relatively neutral setting (but using a camera profile generated from a colorchecker!) and blast through a shoot very quickly. You'll learn how to recognize what modifications to the Develop settings images need and just do it. Then typically I use auto-sync or manual sync to modify similar shots (say a series of head shots taken shortly after each other). I work differently as most of my photography is landscape, but a typical workflow for many photographers that do more people/style/event stuff is to import all the raw and start culling them with pick/reject flags and refine collection. You'll arrive at a subset that is worth looking  at more closely and to finetune their development. The conservative default rendering helps you here because you'll quickly see what images are simply badly exposed, not in correct focus, etc. and you can reject them.
    Think of your raw as the unprinted negative. It represents a nascent image. One that still has to form completely. A jpeg is like a polaroid. The image style is pretty much chosen for you by the film maker. There is very little you can do to it afterwards without it breaking down. Raw gives you much more freedom but it does come with a learning curve and it is more tasking for your equipment. Many people including many pros are simply not interested (or don't see the pay off) in this part of the creative photographic process and just shoot jpeg, which is a fine approach (just not mine). Lightroom can help you there too to quickly find the best images in a series, keyword, caption, and disseminate.

  • PSE7 is not saving the edits I make to my pictures

    I'm working in the Editor and I am saving the edits I make as a jpeg file.  I then go back to Organizer and my edits were not saved.
    Any ideas why this might be happening?

    Usually, File->Catalog->Repair and Optimize will fix the problem for future edits

  • I have scanned a photo and saved it as a jpeg

    I saved the photo as a jpeg on my desktop and tried to import it from there to iPhoto.  This is the message I got.  /Users/JohnandBarbaraKnox/Desktop/Joaninchair.jpg       I then rescanned it and tried to scan it to iPhoto and the same message came up.  I have never had this problem before.  What dod I do?

    What color profiles is the scan? It must be RGB (sRGB is recommended) for iPhoto
    What is the error message you get. You only gave the path to the file
    LN

  • Error while Saving the report

    Hi,
    i have created some reports which are working fine,
    but now i am facing some errors while saving the files.
    Also the reports does show only one record while there are many records in the database.
    The error messages are as follows:
    REP-1051; Unable to save document to file ' F:\Database\Reports\report1.rdf '.
    REP-1070: Error while opening or saving a document.
    Please help me to find out the exact problem.
    Also tell me how can i show all the pages of Database records in a report( while one record on each page)

    As for the error while saving, you have only one possible thing to try. It it doesn't work, you're sunk.
    Assuming the report was not being newly created, i.e. that it was opened from a file on your system, then rename that file to something else (Report_001_OLD.rdf, for example). Then try to save it - Reports will think it is a new file to be saved rather than an existing file to be updated.
    Again, if that doesn't work, and if you do not have the auto-save option turned on, then you're sunk. You will have just lost all of the work you've put into that report.
    As you'll discover, Reports is not the most robust application ever written.

  • Error while saving the billing document

    Dear All,
    I am getting an Error- "No taxes on sales/purchase are allowed for account 870205 L002, AB is not allowed" when i save the billing document. when i go to the conditions tab under item data in the billing document after saving the document and try to view the detail for the discount condition type it shows that the discount condition type has a tax code AB assigned to it.
    I am using the same pricing procedure in another company code where it works fine and I don't get any error. Besides here on viewing the same discount condition type there is no tax code assigned.
    Can anybody explain what could be the possible reason?
    I searched for the solution in the forum and came to know that if I go to FS00 and assign * to Tax Category under control data then it works fine and i don't encounter the problem after saving the billing document.
    Although i have found the solution But what troubles me is that when the same pricing procedure works fine in the first company code without assigning * to the tax category then why do i need to assign * in the second company company code to be able to save the billing document.
    Thanks and Regards
    Deepak Joshi

    First of all let me ask you to indicate the name correctly.
    Secondly,  the root cause to the issue what you have indicated is in FS00 and you need to compare the settings in both the company codes.  
    Finally, the issue is not because of your pricing procedure but because of some missing FI settings.  Thats all I can say now based on the information you have provided.
    thanks
    G. Lakshmipathi

  • Error while saving the request

    Dear all,
    When i am saving the request through transaction FKKORD1 transaction .I am getting the following dump.Please let me know how to resolve this issue.
    Runtime Errors         GETWA_NOT_ASSIGNED
    Date and Time          07.01.2010 13:40:12
    Short text
         Field symbol has not yet been assigned.
    What happened?
         Error in the ABAP Application Program
         The current ABAP program "SAPLFMCA_ORDER" had to be terminated because it has
         come across a statement that unfortunately cannot be executed.
    srinivas
    Error analysis
         You attempted to access an unassigned field symbol
         (data segment 32776).
         This error may occur if
         - You address a typed field symbol before it has been set with
           ASSIGN
         - You address a field symbol that pointed to the line of an
           internal table that was deleted
         - You address a field symbol that was previously reset using
           UNASSIGN or that pointed to a local field that no
           longer exists
         - You address a global function interface, although the
           respective function module is not active - that is, is
           not in the list of active calls. The list of active calls
           can be taken from this short dump.

    Hi,
    Check notes 1178507, 1302885 and 1328721.
    Regards,
    Eli

  • Using Adobe Photoshop CS2 version 9 and have updated it, but when stacking photos, it comes up with PSD, whereas I want Jpeg, and I change the format to Jpeg and the box then comes up with cannot save as there is a program error. Be very grateful for help

    Using Adobe Photoshop CS2 version 9 and have updated it, but when stacking photos, it comes up with PSD, whereas I want Jpeg, and I change the format to Jpeg and the box then comes up with cannot save as there is a program error. Be very grateful for help with this, please.

    jpg does not support Layers.
    Just to make sure, what exactly do you mean by "stacking photos" and what do you want to achieve thereby?

  • Not saving the data in two tables

    Hello,
    its my production problem, i have an update form where you can update the records and these
    records will sit in the temp tables until the final approval from the supervisor.
    In this update form i have two table where i am saving the data one is dup_emp to save the
    officer data and another is the dup_address to save the officer where he worked data.
    in this form address form is pop up screen where you can update and gets back to the original
    form where you can see all the other fields. my problem is if a user hit the cancel button on
    address form example the user doesnt want to update any information on that screen so user
    cancel that screen, and comes to the other screen where the user makes the changes to the
    appropriate fields and hits the SAVE button. in this case its saving only to the dup_emp table
    data not the address data from the address form to dup_address table for the same record.
    if the user cancels in both the screens cancel button it should delete the record from both the
    tables but cancel in form and saves in another form it should save the record in both the
    tables.
    here is my code from both cancel buttons from both the forms.
    this is code is from address form cancel button.
    delete from dup_address
    where address_id=:address_id
    and parent_table_name='emp';
    commit;
    CLEAR_BLOCK;
    go_block('DUP_EMP');
    This code is from dup form of the cancel button
    declare
    temp_address_id varchar2 (12);
    begin
    delete from dup_emp
    where secondemp_id =:dup_emp.secondemp_id;
    delete from dup_address
    where parent_t_id=:global.secondemp
    and parent_table_name='emp';
    commit;
    clear_block;
    go_block('secondaryemp');
    END;

    Hi,
    As Aravind mentioned, it's nothing related to workflow. You have to find a BADI in tcode PA30 that could be used after the infotype is updated. So, you can use FM SAVE_TEXT.
    Regards,

  • Print program is not getting triggered when saving the application

    Hi all,
    My requirement is when i save the invoice using VF01 the print program should get triggered.
    The print program is not getting triggered when saving the application even when i have configured the outtype and have attached the print program.
    The setting "send immediately (when saving application)" is also checked.
    I need to configure it for VF01 transaction.
    The error message displayed was " please maintain output device in master data".
    Regards,
    Umesh

    Hi Umesh
    Please check if you have missed any of the following:
    1. Defining Access Sequence(can use existing).
    2. Defining Output Condition Type(can use existing). - Assigning the Driver Program and Form in processing routine.
    3. Output Determination Procedure
    4. Assign Output Procedure to Billing Types
    Kind Regards
    Eswar

Maybe you are looking for