Loading and displaying an image

I have been able to do this with an applet quite easily
import java.applet.Applet;
import java.awt.Graphics;
import java.awt.Image;
// This is a simple example applet that loads an image and
// displays it.
public class DrawImage extends Applet
     Image image;
     public void init()
          image = getImage(getDocumentBase(), "cow1.jpg");
     public void paint(Graphics g)
          g.drawImage(image, 10, 10, this);
}I haven't been able to find a good source that explains how to do it just using swing and awt. The ones I have found are complicated or don't work. I am trying to program a tester program that will load an jpg image and redraw the panel then load another jpg image so it looks like its moving. I know you can do this just using the graphic in java but I would like to do it with a jpg image files. Can anyone help with simple code for this?

After lots of trial and error with certain classes and not knowing how to use certain methods correctly, I have this below code:
public class image_load extends Frame
     Image img;
     public static void main (String args[])
          Toolkit toolkit = Toolkit.getDefaultToolkit();
          img = toolkit.createImage("cow1.jpg");
          img = ImageIO.read();
          ImageIcon icon = new ImageIcon("cow1.jpg",
                                 "cow pic");
          JLabel label1 = new JLabel("Image and Text", icon, JLabel.CENTER);
          JFrame frame = new JFrame();
          //set frame to exit when closed
          frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
          frame.add(label1);     //add panel to frame
          frame.setSize(25,25);     //set size of frame to 300pix x300pix
          frame.setVisible(true);     //make frame visable
     public void paint(Graphics graphics) {
          graphics.drawImage(img, 0, 0, null);
}I get these errors from the code:
image_load.java:21: non-static variable img cannot be referenced from a static c
ontext
                img = toolkit.createImage("cow1.jpg");
                ^
image_load.java:23: non-static variable img cannot be referenced from a static c
ontext
                img = ImageIO.read();
                ^
image_load.java:23: cannot find symbol
symbol  : method read()
location: class javax.imageio.ImageIO
                img = ImageIO.read();
                             ^
3 errorsI have tried a contructor and other things. As for the imageIO.read error that only accepts in Buffered Images. For this I have this odd bit of code that needs changing to be able to work. Any more suggestions?
BufferedImage bufferedImage = new BufferedImage ( imageWidth,
                                                  imageHeight,
                                                  BufferedImage.TYPE_INT_BGR  );
          bufferedImage.createGraphics().drawImage( image, 0, 0, this);

Similar Messages

  • Load and Display Multiple Images in a Web Dynpro Table

    I am new to Web Dynpro and I am wondering if anyone can help me with an application that I am currently developing. I have a particular requirement to store images in a database table (not MIME repository) and then display them in a WD table element. An image can be of JPEG, PNG or TIFF format and is associated with an employee record.
    I want to create a view in my application that displays multiple images in a table, one image per row. I want to do this using Web Dynpro for ABAP, not Java. I have looked into pretty much all examples available for Web Dynpro and came to the conclusion that Components such as WDR_TEST_EVENTS and WDR_TEST_UI_ELEMENTS do not have any examples of images being stored in a database table and viewed in/from a Web Dynpro table element. Programs such as RSDEMO_PICTURE_CONTROL, DEMO_PICTURE_CONTROL and SAP_PICTURE_DEMO do not show this either.
    The images to be displayed in the Dynpro table are to come from a z-type table, stored in a column of data type XSTRING (RAW STRING). So I would also like to know how to upload these images into this z-type table using ABAP code (not Java).
    Your help would be greatly appreciated.
    Kenn

    Hi,
    May be this is the is the correct place to post your query.
    Web Dynpro ABAP
    Regards,
    Swarna Munukoti.
    Edited by: Swarna Munukoti on Jul 16, 2009 3:52 PM

  • Load and display image using CDC

    Hi everyone,
    Please help. I'm new to java. I need a simple routine to load and display an image from the file system into a CDC app on windows mobile 5. I'm usin creme 4.1.
    Thanx in advance

    Use the following as a guide:
    1. Get the image (path below must be absolute):
    public static Image getImage(String filename) throws ScanException {
    Image img = null;
    // Read paths from properties file
    StringBuffer buf = new StringBuffer("\\");
    buf.append(ScanUtility.getPathImages());
    buf.append("\\");
    buf.append(filename);
    buf.append(".jpg");
    File dataFile = new File(buf.toString());
    if(!dataFile.exists())
    throw new ScanException("Cannot locate the file:\n" + dataFile.getAbsolutePath());
    img = Toolkit.getDefaultToolkit().createImage(buf.toString());
    return img;
    2. Create a class to display the image (pass in the image, above):
    ImagePanel class source:
    import java.awt.*;
    import java.awt.image.*;
    public class ImagePanel extends Panel {
    private Image image = null;
    private Image scaledImage = null;
    private boolean imageComplete = false;
    public ImagePanel(Image img) {
    image = img;
    scaledImage = image.getScaledInstance(200, -1, Image.SCALE_DEFAULT);
    prepareImage(scaledImage, this);
    // Override the paint method, to render the image
    public void paint(Graphics g) {
    if(imageComplete) {
    g.drawImage(scaledImage, 0, 0, this);
    // Override imageUpdate method, to prevent repaint() from trying
    // to do anything until the image is scaled
    public boolean imageUpdate(Image img, int infoFlags, int x, int y, int w, int h) {
    if(infoFlags == ImageObserver.ALLBITS) {
    imageComplete = true;
    repaint();
    return super.imageUpdate(img, infoFlags, x, y, w, h);
    public void flush() {
    image.flush();
    scaledImage.flush();
    image = null;
    scaledImage = null;
    }

  • Loading And Displaying image From MYSQL

    Hello, How can I load and display picture stored into a MYSQL database in a Swing GUI using for example JLable component.

    establish a connection to ur sql, n
    retireve the record with the images or image url in the db.
    and then load it to a Image icon and set it to a JLabel.

  • Firefox can't load a Siemens Gigaset network camera but IE8 can. There is an error in the code from the cam. Could Firefox ignore this and display the image anyway ? eg. with Ignore / Abort.

    I run Windows-XP SP3 and I can't get the image from a Siemans Gigaset cam. There is an error in the cam code (a lacking rutine) . IE8 ignores this and displays the image anyway.
    Is it possible to get a notification like Ignore/Abort/ Continue ???

    Does the documentation for that camera, or for the software with it, say anything about ActiveX or about H.264?
    If so, it isn't compatible with Firefox - it doesn't do ActiveX and it doesn't support H.264 in the HTML5 standard. Microsoft just released a plugin for Firefox that adds H.264 support to Firefox, but IIRC that only covers Windows 7 - not WinXP.

  • PDF addresses not longer load and display PDF in Firefox and solutions suggest to other users with problem DON'T WORK (work fine in Chrome and Safari)

    This is an ongoing problem with other users. When putting a PDF in address window of Firefox and clicking go to address FIREFOX WILL NOT LOAD AND DISPLAY THE PDF. This problem has come up in questions from other users on your site. NONE OF THE SUGGESTED SOLUTIONS WORK! (trying either the Firefox PDF viewer or the Acrobat viewer as default viewer)
    I am using Firefox 23.0.1 (as some of the other users with the same problem). This was not a problem in the past with Firefox. Safari and Chrome continue load and display PDFs just fine from their addresses. This is a big problem as I now have to inform people who want to view my PDFs NOT TO USE FIREFOX BUT TO USE SAFARI OR CHROME.

    It appears that a link to a PDF on an internet page will not download in Firefox either!
    I went to this page:
    http://www.nasa.gov/connect/ebooks/earth_art_detail.html#.UjYEzrwsU08
    and tried to download the PDF link at the bottom of the page (Download: PDF 11.3 MB) It didn't work! Nothing happens. Tried it in Safari and it worked flawlessly.
    I have a PDF file of my work in the public_html folder on my URL. I give the address generated by that file to people who want to view my work---this works perfectly in Safari and Chrome. As to your other question, can't bookmark it if I can't get to it in Firefox.

  • How to load and display the external flv video files in dynamicly and the how to control the flv fil

    How to load and display the external flv video files in dynamicly using AS 3.0
    and  How to control the flv file  add the play paus button and add seekbar.
    I have using to load the flv file following code
    var flvPlaceHolder1:MovieClip = new MovieClip();
    var vid1:Video = new Video(734, 408);
    flvPlaceHolder1.addChild(vid1);
    addChild(flvPlaceHolder1);
    flvPlaceHolder1.x = 1059;
    flvPlaceHolder1.y = 152;
    var nc1:NetConnection = new NetConnection();
    nc1.connect(null);
    var ns1:NetStream = new NetStream(nc1);
    vid1.attachNetStream(ns1);
    var listener1:Object = new Object();
    listener1.onMetaData = function(evt:Object):void {};
    ns1.client = listener1;
    ns1.play("GV-1600 TURNING.flv");
    ns1.addEventListener(NetStatusEvent.NET_STATUS, statusChanged1);
    function statusChanged1(ns1:NetStatusEvent):void
             trace(ns1.info.code);
            if (ns1.info.code == 'NetStream.Buffer.Empty')
                 trace('the video has ended');
                 removeChild(flvPlaceHolder1);
                 //trace('removeChild');
                gotoAndPlay(1786);
    then how to add the play,paus ,full screen button    and   seekbar,volumebar.

    I have to Create the flash presentation for our company product
    In this presentation the left  side the text animation are displayed then right side the our product video is displayed.
    In this presentation i need the following option :
    1, The first product video and animation is finished then the next product is played
    2, then the video displayed  (size width and height 400x300) , I click this video to increase the size(ex:1000x700)
    3, then the playing video i control  it play, stop, paus button and volume bar, seek bar.
    4, then this presentation is displayed on 42 inches LCD TV so this full presentation is run full screen.
    I have finished first two steps 1 and 2
    the following are the screen short and code:-
    code :-
    var count=0;
    var flvPlaceHolder2:MovieClip = new MovieClip();   
    var vid2:Video = new Video(734, 408);
    flvPlaceHolder2.addChild(vid2);
    addChild(flvPlaceHolder2);
    flvPlaceHolder2.x = 1059;
    flvPlaceHolder2.y = 152;
    var nc2:NetConnection = new NetConnection();
    nc2.connect(null);
    var ns2:NetStream = new NetStream(nc2);
    vid2.attachNetStream(ns2);
    var listener2:Object = new Object();
    listener2.onMetaData = function(evt:Object):void {};
    ns2.client = listener2;
    ns2.play("GS-4000.flv");
    this.addEventListener(Event.ENTER_FRAME, BtnFadeIn2);
    function BtnFadeIn2(event:Event):void
        if (this.currentFrame == 387)
            /*flvPlaceHolder2.x = 30;
            flvPlaceHolder2.y = 140;
            vid2.width=1800;
            vid2.height=800;
            trace('Screen size is changed');*/
            if(count==0)
            flvPlaceHolder2.x = 30;
            flvPlaceHolder2.y = 140;
            vid2.width=1800;
            vid2.height=800;
            count++;
    ns2.addEventListener(NetStatusEvent.NET_STATUS, statusChanged2);
    function statusChanged2(ns2:NetStatusEvent):void
        trace(ns2.info.code);
        if (ns2.info.code == 'NetStream.Buffer.Empty')
                trace('the video has ended');
                 removeChild(flvPlaceHolder2);
                 //trace('removeChild');
                gotoAndPlay(433);
    flvPlaceHolder2.buttonMode=true;
    flvPlaceHolder2.addEventListener(MouseEvent.CLICK,home2);
    function home2(e:MouseEvent):void
        if(vid2.width==734 && vid2.height==408)
            flvPlaceHolder2.x = 30;
            flvPlaceHolder2.y = 140;
            vid2.width=1800;
            vid2.height=800;
        else
            flvPlaceHolder2.x = 1059;
            flvPlaceHolder2.y = 152;
            vid2.width=734;
            vid2.height=408;

  • How to Snap/Grab Image from 1394 camera and display the Image in CWIMAQVIEWER in VC++ ?

    Hi,
    I have :  -  IMAQ1394 2.0.1
                  -  NI Vision 7.1
    In VB, I can Snap/Grab Image from 1394 camera and display the Image in CWIMAQVIEWER :
        Dim Image0 As New CWIMAQImage
        imaq1394SnapCW(sid0,Image0)
        CWIMAQViewer1.Attach Image0
    Now,How can I do this in VC++6.0?
        I tried:
                  C_CWIMAQImage m_imgViewer1;
                  m_imgViewer1 = m_CWIMAQVision1.CreateCWIMAQImage();
                  m_CWIMAQViewer1.Attach(m_imgViewer1);
                  imaq1394SnapCW(Sid,m_imgViewer1);  <--there is no "imaq1394SnapCW "function in VC++,why?
        Please help me!
        Thank you!

    For people looking back at these old posts regarding
    CWIMAQViewer - it was not made to be used in the C environments and is made
    for VB.
    Refer to the following locations for displaying images in C
    environments:
    Start»All Programs»National Instruments»Vision»Documentation
    Start»All
    Programs»National Instruments»Vision»Text Based Examples
    Make
    sure that you look at the examples and documentation that is in
    reference to the C environments not the VB environments
    Vince M
    Applications Engineer

  • Browser can resolve, access, and display JPEG image, but ImageIcon can't.

    I've got this weird problem that only happens with images accessed through a customer's VPN:
    Microsloth Internet Imploder can resolve, access, and display a JPG image from a VPN URL, in the general form:
    http://intranet/part?FOOBAR.JPG which the browser apparently transmogrifies into
    http://mogrify.foo.com/images/scripts/cgi/detail.cgi?FOOBAR.JPG(as Jack Webb often said, the names have been changed to protect the innocent)
    Firefox can also resove, access, and display the image.
    But an ImageIcon, when fed either URL, quietly fails to get anything, No errors, no exceptions, but no image, either.
    The application, if it detects the failure of ImageIcon to come up with the image, somehow (not my code) defers to "Windoze Image and Fax Viewer," which locks up trying to resolve, access, and display the image.
    What could possibly be going on here?

    I'd love to have the luxury of saying, "You lost me at Windoze." Then again, to paraphrase a running gag from Airplane!, it looks like I picked the wrong week to quit hemlock.
    As my final message on my other thread on this topic indicates, the problem is that even though the URL ends in JPG, the server isn't really serving up a JPEG, but rather, an HTML page containing the JPEG.
    Knowing this, a solution (of sorts) presented itself: if the URL doesn't produce a displayable ImageIcon, try constructing a JEditorPane on the URL. The results aren't exactly pretty, and you do have to try the ImageIcon first, but it does work.
    JHHL

  • HT1600 I get the menu and can pick a movie but then it won't load and displays an error message

    I get the menu and can pick a movie but then it won't load and displays an error

    What version of iPhoto do you have installed?  Is if one of the versions shown as not compatible in this screenshot?
    If it is then go to the App Store and download iPhoto 9.5.  It will be free if you have an iPhoto 9 or later verson currently.
    OT

  • How can I simultaneously acquire and display an image on the front panel using a PCI-1408

    I have to acquire and display an image directely in the front panel of a *.vi using a PCI-1408. i have to know all informmations about this image because I want to create a calibration system.

    Hi Paola,
    if you own IMAQ Vision you can just have a look at the examples that comes with your board or you can look at: http://zone.ni.com/devzone/explprog.nsf/6c163603265406328625682a006ed37d/2abaefe05789961686256866007c0d22?OpenDocument.
    Without IMAQ Vision look at:
    http://zone.ni.com/devzone/explprog.nsf/6c163603265406328625682a006ed37d/22474456534202b086256aff005fc4f3
    (or search at ni.com for "IMAQ Display without IMAQ Vison)
    Please mail me if you need further help,
    Michael

  • Skype phone not loading and displaying contacts.

    Hi All,
    I have a Skype cordless phone that has the latest firmware installed. My proble is that it now no longer loads and displays any of my contacts. I can see my contacts using the PC client but not on the Skype phone. All the other Skype phone funstions continue to work. Can anyone please help.
    Thanks
    Pau,

    I have a similar issue with a new RTX4088 phone, as more than 20 online contacts show in my skype PC client, while only 3 or 5 of these show as online on the 4088 handset.
    The software version show as 0172 / 11.02.2014 / rtx4088 lp vo172...
    Has others noticed this issue?
    Ocean Shores, NSW, Australia

  • How to read local large JPEG files and display into Images Tile

    Hi all,
    I can read the local multiple files by FLEX/AIR FileListEvent
    and loader to read the large JPEG files but cannot display them
    into a TileList. Since it is a number of images files, how can I
    put them into a thumbnail TileList.
    Please kindly advise.
    Regards,
    Billy

    1. So I would like to know which is the {color:#3366ff}best way to load local images in ImageView{color}.I'm no expert, but is there a reason that you are using Swing to do the loading?
    2. secondly, currently the system displays all images only after the completion of creating all images. {color:#3366ff}How to display images as and when they are created.{color} So that the user has a feeling that the images are loading.JavaFX Image class let you display a lightweight placeholder, and you can bind the progress to some kind of visual indicator. I don't think you can display an image that is partially loaded.
    def PATHS: String[] = [
        "C://Ariel Atom//ariel-atom-1.jpg",
        "C://Ariel Atom//ariel-atom-2.jpg",
        "C://Ariel Atom//ariel-atom-3.jpg",
        "C://Ariel Atom//ariel-atom-5.jpg"
    function getImage(path: String): Image {
        Image {
            url: "file:///{path}"
            backgroundLoading: true
    Stage {
        title: "Image Tiles"
        width: 1024
        height: 800
        scene: Scene {
            content: [
                Tile {
                    columns: 2
                    tileWidth: 400
                    tileHeight: 400
                    content: for (i in [0..3]) {
                        ImageView {
                            image: getImage(PATHS)

  • Can an Acrobat form have a field that allows you to select and display an image?

    Hello,
      I'm trying to streamline my most frequent job duty. I work for a box plant and I spend most of my day creating or updating Print Cards. These are letter sized pages that contain the job information along the top and an image of the package laid flat below. What I'm trying to do is make the Print Card a form that I can fill in, and have the final field ask me to select the image. I would then browse for my package design and drop it into the specified field.
      Is this possible? It seems like it should be. I'm fairly illustrator savvy, but I've yet to really get my hands on Acrobat (though I get more excited about it the more research I do).
      Eventually, I want to turn this single form into a full portfolio that would be linked pdf versions of every form we currently use. The info would then be uploaded and assessable by anyone on our team. I don't know how to do half of that, but I'm learning.   So I guess, expect to see me post on this for a while.
    -Jefferson

    Yes, you can set up a button that has a layout other than "Label only" and  use the following as the Mouse Up JavaScript for the button:
    // Mouse Up script for button
    event.target.buttonImportIcon();
    You will then be prompted to select a file as the source of the button icon. You can choose form a number of file types. You should then set the button to read-only before sending the PDF.
    To trigger the import from a different button, bookmark, link, etc., the script would be:
    getField("image_button").buttonImportIcon();
    Replace "image_button" with the actual name of the button that will display the image.

  • Import and Display GIF images

    Hi,
    I'm trying to manage images in Abap program.
    Reading on this forum, I'm able to import BMP e TIFF files (via SE78) and display them into a customer control.
    Now I'm trying to manage also GIF images.
    I'm using tc SMW0 to import gif images but with no result.
    This is what I done:
    1. call SMW0
    2. select BINARY DATA
    3. Run (no parameters specified)
    4. New button
    5. Import the GIF file.
    The system display the "No MIME type assigned to object D:\logo.gif" and no images is added.
    What I have to do?
    Thanks
    Salvatore

    Hi Salvatore,
      To display the images in Container you need to
      maintain tem in Business documnets.
      Follow the below steps :
    1) Goto tcode OAER.
    2) Give class name, as type 'OT' and Key name.
    3) Execute it and here you create document and select
       screen in the Document types then upload the bmp or
       gif file and save it.
    4) After that use this in when displaying in Container.
    Thanks&Regards,
    Siri.
    Kindly award points if it is useful.
    Message was edited by: Srilatha T

Maybe you are looking for