1 / 9

Images

Images. Creating Image objects Create an in-memory drawing surface Downloaded from GIF or JPEG files Create your own ImageProducer. Creating a Drawing Surface. Use the Component class method: createImage () public void paint(Graphics g) { Dimention dim = getSize();

mulan
Download Presentation

Images

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Images • Creating Image objects • Create an in-memory drawing surface • Downloaded from GIF or JPEG files • Create your own ImageProducer

  2. Creating a Drawing Surface • Use the Component class method: createImage() public void paint(Graphics g) { Dimention dim = getSize(); Image img = createImage(dim.width, dim.height); } Convas c = new Canvas(); Image img = c.createImage(w, h);

  3. Drawing on the surface • You must obtain a Graphics object attached to the in-memory Image object • Use the Image objects getGraphics() method Image img = creatImage(w, h); Graphics gImg = img.getGraphics(); gImg.drawLine(10, 20); gImg.dispose();

  4. Displaying an Image • Use the Graphics method drawImage() to transfer an image onto the Graphics’ surface boolean drawImage(Image imgObj, int left, int top, ImageObserver imgOb) Image img = createImage(w, h); // draw on the surfzce g.drawImage(img, x, y, null); g.drawImage(img, x, y, this);

  5. Double-Buffered Graphics • Good for animation • Apply the operations to in-memory Image • Draw Image to the screen

  6. Double Buffering Image buffer = creatImage(w, h); Graphics bg= buffer.getGraphics bg.drawLine(…) screen.drawImage(buffer, 0, 0, null);

  7. Loading Images • All Java VMs can support GIF and JPEG graphic files • Done in applications by the toolkit Tookit def = Toolkit.getDefaultToolkit(); Image img = def.getImage(“MyFile.dat”); Image img = def.getImage(url)

  8. Downloading Process • Images must be loaded to be drawn • With URLs this involves downloading acros the Internet • Get updates about a downloading process • Through an ImageObserver interface

  9. ImageObserver • The Component class implements ImageObserver • The component implementation simple calls repaint() whenever more data is available

More Related