Drawing a JPEG

Hello,
I'm looking for some code that will draw a JPEG on an Applet. I've been told that the Graphics.drawImage() function should do it, but I need something to draw an ImageIcon, or something that'll take the file as a String (the filename) rather than as an Image. Is there a function or can I use a cast type to convert an ImageIcon to an Image?
Thanks,
- Jesse

Use the Applet method getImage().
Image i = getImage(getCodeBase(), "myImage.jpg");
I don't see why you need an ImageIcon here, but for future reference if you need to get the associated Image from an ImageIcon.
Image i = imageIcon.getImage();
** File must be on the server as opposed to the local machine otherwise you'll get a security exception.

Similar Messages

  • Image Previews In Aperture 3 - Canon 5D MK2

    The "previews" Aperture makes are exactly what the photo looks like in the camera and as I wanted/expected the photo to look like, but when the photo has time to "process", the image turns dull and bad looking. If I press "P" again, the photo does not return to the state it was. Sound confusing? Here is my import work flow.
    As I import my images, I keep "P" selected so I can zip through my images, rate and delete. When finished, I press "P" and that's when the images change. See attached images of before and after. I always check my histogram on the camera between shots and most of my shots are well exposed, but when I import them into Aperture...the images are typically 1-2 stops darker.
    I've been using Aperture since 1.0. This issue has been going on for quite some time, but my daughters birthday party this past weeked was the final straw.
    I have a Canon 5D MK2 with the 24-105mm 4.0L IS lens and shoot in RAW.
    Please help,
    Gene

    What William said  .  The parts of the Help page I sent you (the OP had posted onto another thread) that I wanted you to notice are this:
    How Aperture Displays Images in the Viewer
    When a version needs to be displayed in the Viewer, Aperture does the following:
    Aperture draws the thumbnail image (a JPEG image that is 1280 pixels in the longest dimension).
    Aperture draws the JPEG preview, if present.
    Aperture decodes the master and applies any adjustments to it.
    Once the last step is completed, the adjustment controls become available. Because the JPEG preview is created with all the adjustments for that version, it appears onscreen faster than the adjusted master would. The result is a sharp preview image that appears quickly in the Viewer.
    and this:
    “Use embedded JPEG from camera when possible” checkbox: Select this checkbox to have Aperture use the JPEG thumbnail produced by the camera, if available.
    For just-imported Images, Aperture uses the in-camera created JPEG until it makes its own.  This is almost certainly what you are seeing.  (You can change this at "Aperture➞Preferences➞Previews➞Post Import Processing".  I recommend selecting "Standard Previews".)
    The histogram on your camera is derived from an in-camera created JPEG.  It is somewhat congruent to the histogram of the converted RAW image, but the key word there is "somewhat".  Additionally, it reflects any in-camera settings you have.  The RAW file is strictly sensor data -- it is the recorded exposure, with no adjustments.
    Images from converted RAW files are frequently "dull" (manufacturers do all kinds of things to make their camera-baked JPEGs look "pleasing").  Aperture provides extensive and powerful tools for developing your Images.  When you record your exposures to RAW files, you should think of your camera as a data gathering tool.  The computer is your developer.  If you want the in-camera created JPEGs, there is no reason to record the sensor data to RAW files.
    There may be an additional problem with Canon 5D MK2 files.  Search the forum to see if this has been reported.
    Message was edited by: Kirby Krieger -- fleshed out the citations from the User Manual.

  • Transparent image

    I am using AWT to draw a jpeg onto a panel and then draw a bunch of lines and shapes on to the panel.
    So I get a background picture with a few lines and shapes overlaying the picture.
    New lines and shapes are drawn every time the user clicks on the panel � and some existing lines and shapes are removed � exposing the hidden parts of the background image.
    My problem is that every time the user clicks on the panel the whole background picture has to be repainted just for a few lines and shapes that overlay the picture (I use the paint() function to redraw the background image and all the other lines and shapes on top).
    Since the background image can be quite large at times (not always the same image), repainting the image can look very unattractive and annoying for the user.
    What I want to do is somehow avoid repainting the background image every time the user clicks the image, but rather only repaint the images and shapes in front
    or
    Only repaint the parts of the background image that are obscured by the overlaying lines and shapes that drawn on top.
    I have an internet site with an applet showing this problem at:
    www.cephx.com
    click demo and then click the pencil icon on the toolbar.
    Any suggestions on how to solve this problem?
    Thanks.
    Danny Abraham.

    I think using a layered pane for your background image might help:
    import java.awt.event.*;
    import javax.swing.*;
    import java.awt.*;
    public class TestBackgroundLayered extends JFrame
         public TestBackgroundLayered()
              ImageIcon image = new ImageIcon("????.jpg");
              JLabel background = new JLabel(image);
              background.setBounds(0, 0, image.getIconWidth(), image.getIconHeight());
              getLayeredPane().add(background, new Integer(Integer.MIN_VALUE));
              JPanel panel = new JPanel();
              panel.setOpaque(false);
              panel.add( new JButton( "Hello" ) );
              setContentPane( panel );
         public static void main(String [] args)
              TestBackgroundLayered frame = new TestBackgroundLayered();
              frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
              frame.setSize(300, 300);
              frame.setVisible(true);
    }

  • DrawImage() on JPanel help...

    Hello folks,
    Im a student, working on a project involving drawing pictures on JPanels. (Specifically, its a board game that has 50 spaces and a player piece, which is a JPEG, must be drawn on the panel and moved around to different spaces with the mouse.)
    I have a big JPanel as the board, and then 50 smaller JPanels as the spaces on the board. As far as the mouse movement detection, Im sure I can use a mouseMotionListener on the board panel, and compare where the player clicked with the coordinates of the spaces on the board. However, I am having trouble figuring out how to draw an image on the board panel. It would probably be easier to make my own custom panel that extends JPanel, but Im too far into it to go back and redo all of that. My question is, how would I draw a JPEG on a regular JPanel? I know I need to use an imageIcon and drawImage(), specifying the picture I want drawn and the coordinates of where I would like it to go - however, Im not sure where I should put these method calls. I've tried for quite a while without any luck... so any help would be appreciated.
    Eric

    Maybe this thread will give you an idea:
    http://forum.java.sun.com/thread.jsp?forum=57&thread=492100

  • JAVA Drawing Graphics Save as JPEG?

    My problem is this, I am trying to save my g2 graphic image to a jpg. This is how I have things setup, I will show code and my thoughts. What I need is help to figure out how I could save seperate .java files graphics g to the jpg format from a JFileChooser in a different .java file.
    HERE IS THE CODE FOR HOW GRAPH IS CREATED. graph.java
    I have a graph I am drawing in a seperate .java file and it is created like this:
    public class graph extends JPanel {
        public static Graphics2D g2;
        final int HPAD = 60, VPAD = 40;
        int[] data;
        Font font;
        public test() {
            data = new int[] {120, 190, 211, 75, 30, 290, 182, 65, 85, 120, 100, 101};
            font = new Font("lucida sans regular", Font.PLAIN, 8);       
            setBackground(Color.white);
        protected void paintComponent(Graphics g) {
            super.paintComponent(g);
            g2 = (Graphics2D)g;
            g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
                                RenderingHints.VALUE_ANTIALIAS_ON);
            g2.setFont(font);
            FontRenderContext frc = g2.getFontRenderContext();
            int w = getWidth();
            int h = getHeight();
            // scales
            float xInc = (w - HPAD - HPAD) / 10f;
            float yInc = (h - 2*VPAD) / 10f;
            int[] dataVals = getDataVals();
            float yScale = dataVals[2] / 10f;
    //        etc... (the rest is just drawing...blah...blah)
    }HERE IS THE CODE FOR HOW MY GRAPH IS DISPLAYED AND TRYING TO BE SAVED. results.java
    The graph I created is then displayed in a JPanel and there is a button in the results window to save the graph results. This is where I am having difficulty as I am trying to save the g2 from graph.java (declared public static...not sure if this a good idea) but anyway I want to save this as a jpg heres the code:
            resultPanel = new JPanel(new PercentLayout());
            graph drawing = new graph();
            resultPanel.add (
                drawing,
                new PercentLayout.Constraint(1,41,49,50));
            resultPanel.add (
                saveButton1,
                new PercentLayout.Constraint(1,94,25,5));
        public void actionPerformed(ActionEvent e) {
            if(e.getSource() == saveButton1) {
                doSaveGraph();
        public void doSaveGraph() {
            JFileChooser fileSaver;
            fileSaver = new JFileChooser(); // The file-opening dialog
            ExampleFileFilter filter = new ExampleFileFilter("jpg");
            filter.setDescription("JPEG Picture File");
            fileSaver.addChoosableFileFilter(filter);
            try {
                if(fileSaver.showSaveDialog(this) == JFileChooser.APPROVE_OPTION) {
                    File f = fileSaver.getSelectedFile();
                    BufferedImage img = new BufferedImage(672,600, BufferedImage.TYPE_INT_RGB);
          // SOMEWHERE IN HERE IS WHERE I NEED TO GRAB G2?  I AM NOT SURE WHAT TO DO HERE
                    //Graphics g = img.getGraphics();
                    //panel.paint(g);
                    BufferedOutputStream out = new BufferedOutputStream(new FileOutputStream(f));
                    JPEGImageEncoder encoder = JPEGCodec.createJPEGEncoder(out);
                    JPEGEncodeParam param = encoder.getDefaultJPEGEncodeParam(img);
                    param.setQuality(1f, true);
                    encoder.setJPEGEncodeParam(param);
                    encoder.encode(img);
                    System.out.println("It worked");
                else{}
            catch (Exception e) {
                e.printStackTrace();
    ...If you can help me I will be very happy, and give you 10 dukes! LOL and I appreciate the help!

    import java.awt.*;
    import java.awt.event.*;
    import java.awt.font.*;
    import java.awt.geom.*;
    import java.awt.image.BufferedImage;
    import java.io.*;
    import javax.imageio.ImageIO;
    import javax.swing.*;
    public class SavingGraphics
        public static void main(String[] args)
            GraphicsCreationPanel graphicsPanel = new GraphicsCreationPanel();
            GraphicsSaver saver = new GraphicsSaver(graphicsPanel);
            JFrame f = new JFrame();
            f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            f.getContentPane().add(saver.getUIPanel(), "North");
            f.getContentPane().add(graphicsPanel);
            f.setSize(400,400);
            f.setLocation(200,200);
            f.setVisible(true);
    class GraphicsCreationPanel extends JPanel
        String text;
        Font font;
        public GraphicsCreationPanel()
            text = "hello world";
            font = new Font("lucida bright regular", Font.PLAIN, 36);
            setBackground(Color.white);
        protected void paintComponent(Graphics g)
            super.paintComponent(g);
            Graphics2D g2 = (Graphics2D)g;
            g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
                                RenderingHints.VALUE_ANTIALIAS_ON);
            int w = getWidth();
            int h = getHeight();
            g2.setPaint(Color.blue);
            g2.draw(new Rectangle2D.Double(w/16, h/16, w*7/8, h*7/8));
            g2.setPaint(Color.orange);
            g2.fill(new Ellipse2D.Double(w/12, h/12, w*5/6, h*5/6));
            g2.setPaint(Color.red);
            g2.fill(new Ellipse2D.Double(w/6, h/6, w*2/3, h*2/3));
            g2.setPaint(Color.black);
            g2.setFont(font);
            FontRenderContext frc = g2.getFontRenderContext();
            LineMetrics lm = font.getLineMetrics(text, frc);
            float textWidth = (float)font.getStringBounds(text, frc).getWidth();
            float x = (w - textWidth)/2;
            float y = (h + lm.getHeight())/2 - lm.getDescent();
            g2.drawString(text, x, y);
    class GraphicsSaver
        GraphicsCreationPanel graphicsPanel;
        JFileChooser fileChooser;
        public GraphicsSaver(GraphicsCreationPanel gcp)
            graphicsPanel = gcp;
            fileChooser = new JFileChooser(".");
        private void save()
            if(fileChooser.showSaveDialog(null) == JFileChooser.APPROVE_OPTION)
                File file = fileChooser.getSelectedFile();
                String ext = file.getPath().substring(file.getPath().indexOf(".") + 1);
                BufferedImage image = getImage();
                try
                    ImageIO.write(image, ext, file);
                catch(IOException ioe)
                    System.out.println("write: " + ioe.getMessage());
        private BufferedImage getImage()
            int w = graphicsPanel.getWidth();
            int h = graphicsPanel.getHeight();
            BufferedImage bi = new BufferedImage(w, h, BufferedImage.TYPE_INT_RGB);
            Graphics2D g2 = bi.createGraphics();
            g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
                                RenderingHints.VALUE_ANTIALIAS_ON);
            graphicsPanel.paint(g2);
            g2.dispose();
            return bi;
        public JPanel getUIPanel()
            JButton save = new JButton("save");
            save.addActionListener(new ActionListener()
                public void actionPerformed(ActionEvent e)
                    save();
            JPanel panel = new JPanel();
            panel.add(save);
            return panel;
    }

  • HELP - CONVERTING A JPEG IMAGE INTO A LINE DRAWING

    PLEEEASE HELP ME!!!
    sorry to be thick - im only a beginner   ---   is there any way to covert a jpeg image into like a line drawing where there is a block colour background and solid lines that make up the picture like you sometimes get in brochures - somthing different to just the effects that are availible in the filter gallery...
    thanks
    LUK

    As far as I recall there's no magic/easy "convert to vector drawing" functionality in Photoshop, though there are some things you can do to help smooth rough edges (e.g., Filter - Noise - Median).  There are also some things you can do, if you want to get fancy, based on converting selections to paths, but that can get kind of involved and likely requires manual path editing afterward.
    I have heard there are some pretty decent vector conversion functions in other Adobe apps...  Adobe Illustrator, perhaps?  Someone who uses Illustrator may want to chime in here; I don't have that package.
    -Noel

  • How can i convert a jpeg into a line drawing/sketch?

    Hey just wondering what is the best tool and is Illustrator the best program  - to convert a standard JPEG image into a line drawing?
    Someone please help! Thank you

    Try VectorMagic (Google will find it for you). You can use it for free a few times on the web, or  you can buy a license. You can control the level of detail and the number of colours to use, and it will write an AI file.
    (I have no affiliation, I just think it works well).

  • Drawing  text in a jpeg image

    Hi,
    I want to draw a string in a jpeg image file.The file will contain only that string.Anybody can help me suggesting the best way or any available program is there for it.
    Thanks in advance.
    Papu

    You can use the image functions in PHP to get the size of JPEG, GIF, PNG, SWF, TIFF and JPEG2000 images, and if you have the GD library (available at http://www.boutell.com/gd/) you will also be able to create and manipulate images.
    good lock
    ciprian
    http://www.astroclaire.com

  • Saving an Appleworks 6 Drawing as a JPEG

    I want to save an Appleworks 6 Drawing document (Joe Bloggs) as a JPEG. When I do so (by the way, the menu calls it 'JPEG (QT) ) the icon that comes up on the desktop is called 'Joe Bloggs.O]'. But the icon is the normal JPG icon. And when I send it, the recipient says it's not a JPEG but a DOC.
    Until today, recipients have had no complaints.
    Help, please?

    AppleWorks uses the QuickTime translators to convert draw & paint documents to other picture formats. Because AppleWorks just doesn't understand OS X extensions, you can get some strange results. The easiest thing to do is just save & then fix the extensions in the Finder.

  • Problem in saving a grafic as a jpeg,the grafic is drawed on a jpanel!

    I can't save a grafic as a jpeg!
    When i save the jpanel content i get a blank picture!
    Can someone give an example ?
    Thanks in advance!
    Message was edited by:
    kynamar

    private void save_jpg()
    //pScale  - method that draw's the grafic on the jpanel
    pScale(datanal(tabel.getRowCount(),col_1,coloane_selectate.get(coloanele.nextElement())),pane);
    BufferedImage myImage = new BufferedImage(pane.getWidth(),pane.getHeight(),BufferedImage.TYPE_INT_RGB);
    Graphics2D g2 = myImage.createGraphics();
    pane.paint(g2);
         try {
             OutputStream out = new FileOutputStream("1grafic.jpg");
             JPEGImageEncoder encoder = JPEGCodec.createJPEGEncoder(out);
    JPEGEncodeParam param =encoder.getDefaultJPEGEncodeParam(myImage);
              //the first parameter here is the "quality v file size" trade-off
              //play with this value (0-1) to determine the best results for you
              param.setQuality(0.9f, true);
              encoder.encode(myImage, param);
              out.flush();
              out.close();
           } catch (Exception ec) {
             System.out.println(ec);
           }

  • I have an A0 ai drawing - but cant export as jpeg... any ideas?

    I have an A0 ai drawing - but cant export as jpeg... any ideas?

    I think you're probaly exceeding the size limit for that kind of export - I can't recall exactly what it is but that's a pretty big jpeg.
    Can I just ask why you need to make such a large image file?

  • Drawing JPEGs/GIFs directly on JFrames

    Hey all,
    Is it possible to draw an image DIRECTLY onto an instance of the JFrame class, rather than writing a subclass of a component? I suspect that a solution to my problem might have something to do with the getGraphics() method of JFrame.
    Mike.

    Have you looked into your own suggestion? Doesn't the Graphics object returned from getGraphics() provide a drawImage() method?

  • Can I draw *.bmp, *.png in java.awt.canvas ?

    In paint method of my program, I get image from Toolkit like this:
    public class CanCanvas extends Canvas{
    //In loadImage method
    Toolkit.getDefaultToolkit().getImage(
                        getClass().getClassLoader().getResource(
                                  resource.getString("bg.jpg")));
    //.... In paint method
    if (image != null && image.size() > 0) {
                   for (int j = 0; j < image.size(); j++) {
                        Image image1 = (Image) image.elementAt(j);
                        Rectangle rectangle = (Rectangle) imgLocation.elementAt(j);
                        g.drawImage(image1, rectangle.x, offset + rectangle.y,
                                  rectangle.width, rectangle.height, null);
                        i = i <= rectangle.y + rectangle.height + 7 ? rectangle.y
                                  + rectangle.height + 7 : i;But there is something very strange, if my image is *.jpg or *.gif, it runs ok, otherwise -*.bmp, *.png-, it can't draw the image.
    Would anyone tell me why ? Is the reason java.awt.canvas ?
    Thanks in advance ^ ^

    If you'd bother to read the documentation of the methods you're using, you'd know:
    http://java.sun.com/j2se/1.4.2/docs/api/java/awt/Toolkit.html#getImage(java.lang.String)
    Returns an image which gets pixel data from the specified file, whose format can be either GIF, JPEG or PNG.

  • Need help to create report with jpeg/gif image

    Hello,
    I need help with creating a form with a special jpeg/gif seal. I never done this Java. Until now, I created all forms with ansi C++ with HP escape characters to draw lines, boxs, and text. This form will contain boxes which is populated with database information read from a text file.
    Since this form contains a special seal on the upper right, I don't think it can be done with old fashion ansi C++. How can I create a form with Java and create it as a simple exe to just print the form to a specified printer.
    Thanks,
    John

    Hi,
    I am creating a form with boxes (lines and text). What is special about this form is that it has an image jpeg or gif at the top right corner. Is is a state department seal. Up to this form, I had used ansi C++ and print out escape HP character to print out the lines, boxes, and text. I have no idea how to print out the image. I am new to JAVA and only 1 class in it. Is there sample code out there to create this type of form with the image? I need a starting point.
    Thanks,
    John

  • Anyone else having trouble opening CMYK PDFs from Photoshop CC with JPEG 'high' compression?

    (Cross-post from the Photoshop forum, where I was asked to post in the Acrobat forum: http://forums.adobe.com/message/5553829 )
    When I save a PDF file in Photoshop CC in CMYK color with JPEG compression (quality = high), it will save without any errors. However, when I open the file in Acrobat (11.0.3), I get an "Out of Memory" pop up error. I press Ok, and the document is just displayed as a blank white image.
    I'm using Win7 64-bit, Photoshop CC 64-bit. Plenty of memory (24GB) and allocated RAM in preferences, and I've done some troubleshooting that leads me to believe the error is not due to system memory, but rather a specific bug in the software. I have Photoshop CS6 on the same machine, and if I open the PSD, save as PDF with the above settings, everything is fine when I open it using Acrobat. This seems to just be for Photoshop CC, not CS6.
    Here is the troubleshooting I've done so far:
    PDF format, RGB color, any other settings --> Acrobat can open the file.
    PDF format, CMYK, no compression --> Acrobat can open the file.
    PDF format, CMYK, JPEG compression [medium] --> Acrobat can open the file.
    PDF format, CMYK, JPEG compression [high] --> Acrobat can NOT open the file because it encounters the "out of memory" error.
    PDF format, CMYK, JPEG compression [maximum] --> Acrobat can open the file.
    This is silly. I don't get it. Can anyone else confirm this problem for me?
    Updated:
    Like you said, there isn't enough information to rule out an issue with Photoshop CC, as the same action using Photoshop CS6 results in a usable file.
    New information (while making files for uploading):
    The error only occurs with CMYK files of larger dimensions. On a 500x500px image, Acrobat throws out "A drawing error has occured". a 2500x2500px image runs into the "Out of memory" error. In either case, Acrobat cannot successfully open the file generated by Photoshop CC, while it can if it was made using Photoshop CS6.
    RGB PDF JPEG HIGH - PsCC - No Error.pdf
    https://drive.google.com/uc?export=&confirm=no_antivirus&id=0B9lLW1Ml0 0iQc2ltUXhqVTRVaWs
    CMYK PDF JPEG HIGH - 500x500px - PsCC - Acrobat drawing error.pdf
    https://drive.google.com/uc?export=&confirm=no_antivirus&id=0B9lLW1Ml0 0iQZ3M2SS1PbEJuN0k
    CMYK PDF JPEG HIGH - 2500x2500px - PsCC - Acrobat out of memory error.pdf
    https://drive.google.com/uc?export=&confirm=no_antivirus&id=0B9lLW1Ml0 0iQd2dxWm9xWjk3bEE

    Another observation for what it is worth (not a solution again). I was able to open all 3 PDFs in Irfanview as graphics. The properties of the image were
    The major changes for the others within the JPegs was the number of pixels (133X133) and the size (1.4inX1.4in). There is also a reduction in the number of colors.
    Just for information, I opened the big JPeg in Acrobat (9.5.5) and it opened fine. However, it looks like the color space was changed as shown below:
    Even if I change the input to use CMYK and not RGB, it looks like it gets converted to RGB. I haven't spent time to figure out the preflight analysis properly, but at least this may give you some info back.

Maybe you are looking for