progarmming through java presentation on images group no:3 presented by: anthony narzary...

32
PROGARMMING THROUGH JAVA Presentation on IMAGES Group No:3 Presented By: Anthony Narzary (DC2012MCA0002) Chandra Gupta Bora (DC2012MCA0009) Dipankar Saikia (DC2012MCA0010) Jiaur Rahman (DC2011MCA0012)

Upload: michael-bradley

Post on 12-Jan-2016

216 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: PROGARMMING THROUGH JAVA Presentation on IMAGES Group No:3 Presented By: Anthony Narzary (DC2012MCA0002) Chandra Gupta Bora (DC2012MCA0009) Dipankar Saikia

PROGARMMING THROUGH JAVA

Presentation onIMAGES

Group No:3

Presented By:

Anthony Narzary (DC2012MCA0002)

Chandra Gupta Bora (DC2012MCA0009)

Dipankar Saikia (DC2012MCA0010)

Jiaur Rahman (DC2011MCA0012)

Page 2: PROGARMMING THROUGH JAVA Presentation on IMAGES Group No:3 Presented By: Anthony Narzary (DC2012MCA0002) Chandra Gupta Bora (DC2012MCA0009) Dipankar Saikia

TOPICS

• File Formats, Image Fundamentals, Creating Images

• Loading And Displaying Images

• Image Observer

• Media Tracker

Page 3: PROGARMMING THROUGH JAVA Presentation on IMAGES Group No:3 Presented By: Anthony Narzary (DC2012MCA0002) Chandra Gupta Bora (DC2012MCA0009) Dipankar Saikia

Image, File format

Presented by: Anthony NarzaryId:DC2012MCA0002

Page 4: PROGARMMING THROUGH JAVA Presentation on IMAGES Group No:3 Presented By: Anthony Narzary (DC2012MCA0002) Chandra Gupta Bora (DC2012MCA0009) Dipankar Saikia

Image • An image is simply a rectangular graphical object.• Images are a key component of web design.• The inclusion of the <img> tag in the Mosaic browser at NCSA

(National Center for Supercomputer Applications) is what caused the Web to begin to grow explosively in 1993.

• Images are objects of the Image class, which is part of the java.awt package.

• Images are manipulated using the classes found in the java.awt.image package.

• The java.awt.image classes:

CropImageFilter

MemoryImageSource

FilteredImageSource

PixelGrabber

ImageFilter

RGBImageFilter

Page 5: PROGARMMING THROUGH JAVA Presentation on IMAGES Group No:3 Presented By: Anthony Narzary (DC2012MCA0002) Chandra Gupta Bora (DC2012MCA0009) Dipankar Saikia

File Formats

• The image file formats are: GIF: Graphics Interchange Format

• The GIF image format was created by CompuServe in 1987 to make it possible for images to be viewed while online, so it was well suited to the Internet.

• GIF images can have only up to 256 colors each.• The GIF format supports animation and is still widely used to

provide image animation effects.

Page 6: PROGARMMING THROUGH JAVA Presentation on IMAGES Group No:3 Presented By: Anthony Narzary (DC2012MCA0002) Chandra Gupta Bora (DC2012MCA0009) Dipankar Saikia

JPEG: Joint Photographic Experts Groups

• The JPEG format was created by a group of photographic experts to store full-color-spectrum, continuous-tone images.

• These images, when properly created, can be of much higher fidelity as well as more highly compressed than a GIF encoding of the same source image.

• Nearly every digital camera can save images in the JPEG/JFIF format, which supports 8-bit grayscale images and 24-bit color images (8 bits each for red, green, and blue).

Page 7: PROGARMMING THROUGH JAVA Presentation on IMAGES Group No:3 Presented By: Anthony Narzary (DC2012MCA0002) Chandra Gupta Bora (DC2012MCA0009) Dipankar Saikia

Image Fundamentals

• There are three common operations that occur when we work with images:

creating an image

loading an image

displaying an image. Creating an Image Object: The createImage( ) method has

the following two forms:• Image createImage(ImageProducer imgProd)• Image createImage(int width, int height)

Page 8: PROGARMMING THROUGH JAVA Presentation on IMAGES Group No:3 Presented By: Anthony Narzary (DC2012MCA0002) Chandra Gupta Bora (DC2012MCA0009) Dipankar Saikia

• Image createImage(ImageProducer imgProd): This form returns an image produced by imgProd, which is an

object of a class that implements the ImageProducer interface.

• Image createImage(int width, int height): This form returns a blank (that is, empty) image that has the

specified width and height Here is an example:

Canvas c = new Canvas();

Image test = c.createImage(200, 100);• This creates an instance of Canvas and then calls the

createImage( ) method to actually make an Image object. At this point, the image is blank.

Page 9: PROGARMMING THROUGH JAVA Presentation on IMAGES Group No:3 Presented By: Anthony Narzary (DC2012MCA0002) Chandra Gupta Bora (DC2012MCA0009) Dipankar Saikia

LOADING AND DISPLAYING IMAGES

PRESENTED BY CHANDRA GUPTA BORAH(DC2012MCA0009)

Page 10: PROGARMMING THROUGH JAVA Presentation on IMAGES Group No:3 Presented By: Anthony Narzary (DC2012MCA0002) Chandra Gupta Bora (DC2012MCA0009) Dipankar Saikia

LOADING AN IMAGE

To load image the following methods are used:

A)Image getImage(URL url)B) Image getImage(URL url, String imageName)• Both returns an Image object.

Page 11: PROGARMMING THROUGH JAVA Presentation on IMAGES Group No:3 Presented By: Anthony Narzary (DC2012MCA0002) Chandra Gupta Bora (DC2012MCA0009) Dipankar Saikia

Displaying an Image• Once the image is created, the image has to bedisplayed.• The following method of the Graphics classdisplays the image

boolean drawImage(Image imgObj, int left, int top, ImageObserver imgOb)

Page 12: PROGARMMING THROUGH JAVA Presentation on IMAGES Group No:3 Presented By: Anthony Narzary (DC2012MCA0002) Chandra Gupta Bora (DC2012MCA0009) Dipankar Saikia

Example for loading and displaying an image:import java.awt.*;import java.applet.*;public class SimpleImageLoad extends Applet{Image img;public void init() {img = getImage(getDocumentBase(), getParameter("img"));}public void paint(Graphics g) {g.drawImage(img, 0, 0, this);}}

Page 13: PROGARMMING THROUGH JAVA Presentation on IMAGES Group No:3 Presented By: Anthony Narzary (DC2012MCA0002) Chandra Gupta Bora (DC2012MCA0009) Dipankar Saikia

HTML Applet Code

<applet code=“SimpleImageLoad.class” height=200 width=200><param name=“img” value=“sunset.jpg”></param></applet>

Page 14: PROGARMMING THROUGH JAVA Presentation on IMAGES Group No:3 Presented By: Anthony Narzary (DC2012MCA0002) Chandra Gupta Bora (DC2012MCA0009) Dipankar Saikia

IMAGE OBSERVER

PRESNTED BY

DIPANKAR SAIKIA

[DC2012MCA0010]

Page 15: PROGARMMING THROUGH JAVA Presentation on IMAGES Group No:3 Presented By: Anthony Narzary (DC2012MCA0002) Chandra Gupta Bora (DC2012MCA0009) Dipankar Saikia

• Image Observer is an interface used to receive notification as an image is being generated.

• It defines only one method: image Update( ).

• Using an image observer allows us to perform other actions, such as show a progress indicator or an attract screen, as we are informed of the progress of the download..

IMAGE OBSERVER

Page 16: PROGARMMING THROUGH JAVA Presentation on IMAGES Group No:3 Presented By: Anthony Narzary (DC2012MCA0002) Chandra Gupta Bora (DC2012MCA0009) Dipankar Saikia

The image Update( ) method has this general form:

boolean image Update (Image imgObj, int flags, int left, int top, int width, int height )

• Here, imgObj is the image being loaded. • flags is an integer that communicates the status of the update report.

• The four integers left, top, width, and height represent a rectangle that contains different values depending on the values passed in flags.

• imageUpdate( ) should return false if it has completed loading, and true if there is more image to process.

Page 17: PROGARMMING THROUGH JAVA Presentation on IMAGES Group No:3 Presented By: Anthony Narzary (DC2012MCA0002) Chandra Gupta Bora (DC2012MCA0009) Dipankar Saikia

Bit Flags of the imageUpdate( ) flags Parameter

Page 18: PROGARMMING THROUGH JAVA Presentation on IMAGES Group No:3 Presented By: Anthony Narzary (DC2012MCA0002) Chandra Gupta Bora (DC2012MCA0009) Dipankar Saikia

Example of imageUpdate()

public boolean imageUpdate(Image img, int flags, int x, int y, int w, int h){

if ((flags & ALLBITS) == 0){

System.out.println("Still processing the image."); return true;}else{

System.out.println("Done processing the image.");return false;

}}

Page 19: PROGARMMING THROUGH JAVA Presentation on IMAGES Group No:3 Presented By: Anthony Narzary (DC2012MCA0002) Chandra Gupta Bora (DC2012MCA0009) Dipankar Saikia

Default implementation of imageUpdate()

The default implementation of imageUpdate( ) in Applet has several problems.

First, it repaints the entire image each time any new data arrives. Thiscauses flashing between the background color and the image.

Second, it uses a feature of Applet.repaint( ) to cause the system toonly repaint the image every tenth of a second or so. This causes ajerky, uneven feel as the image is painting.

Finally, the default implementation knows nothing about images thatmay fail to load properly. getImage( ) always succeeds even when theimage specified does not exist. This will be detected only whenimageUpdate( ) occurs.

Page 20: PROGARMMING THROUGH JAVA Presentation on IMAGES Group No:3 Presented By: Anthony Narzary (DC2012MCA0002) Chandra Gupta Bora (DC2012MCA0009) Dipankar Saikia

Solution to Problems

Eliminate flickering:

overrides update( ) so that it calls paint( ) without painting the background color first.The background is set via setBackground( ) in init( ), so the initial color is painted just once.Also, it uses a version of repaint( ) that specifies the rectangle in which to paint.The system will set the clipping area such that nothing outside of this rectangle is painted.This reduces repaint flicker and improves performance.

Page 21: PROGARMMING THROUGH JAVA Presentation on IMAGES Group No:3 Presented By: Anthony Narzary (DC2012MCA0002) Chandra Gupta Bora (DC2012MCA0009) Dipankar Saikia

Eliminate jerky, uneven display:

painting every time it receives an update.These updates occur on a scan line-by-scan line basis, so an image that is 100 pixels tall will be "repainted" 100 times as it loads.

Handles error caused by the desired file not being found:

Examine the flags parameter for the ABORT bit. If it is set, the instance variable error is set to true and then repaint( ) is called.The paint( ) method is modified to print an error message over a bright red background if error istrue.

Page 22: PROGARMMING THROUGH JAVA Presentation on IMAGES Group No:3 Presented By: Anthony Narzary (DC2012MCA0002) Chandra Gupta Bora (DC2012MCA0009) Dipankar Saikia

MEDIA TRACKER

PRESENTED BY JIAUR RAHMAN (DC2012MCA0012)

Page 23: PROGARMMING THROUGH JAVA Presentation on IMAGES Group No:3 Presented By: Anthony Narzary (DC2012MCA0002) Chandra Gupta Bora (DC2012MCA0009) Dipankar Saikia

MEDIA TRACKER

• Image Observer interface is difficult to

understand and manage for multiple images to be loaded.

• MEDIA TRACKER is a simpler form of image observer.

• Here images can be loaded synchronously. • A Media Tracker is an object that will check

the status of an arbitrary number of images in parallel.

Page 24: PROGARMMING THROUGH JAVA Presentation on IMAGES Group No:3 Presented By: Anthony Narzary (DC2012MCA0002) Chandra Gupta Bora (DC2012MCA0009) Dipankar Saikia

REGISTERING AN IMAGE•To use Media Tracker , addImage( ) method is used to track the loading status of an image.•addImage( ) has the following general forms: void addImage(Image imgObj, int imgID) void addImage(Image imgObj, int imgID, int width, int height) Here, imgObj is the image being tracked. imgID is identification number . ID numbers do not need to be unique . we can use the same number with several images as apart of a group. width and height is the dimensions of the object.

Page 25: PROGARMMING THROUGH JAVA Presentation on IMAGES Group No:3 Presented By: Anthony Narzary (DC2012MCA0002) Chandra Gupta Bora (DC2012MCA0009) Dipankar Saikia

CHECKING AN IMAGE

When an image is loaded we can check the status of an image by calling checkID( ). boolean checkID(int imgID) Here, imgID specifies the ID of the image. The method returns true if all images that have the specified ID have been loaded .Otherwise, it returns false. We can use the checkAll( ) method to see if all imagesbeing tracked have been loaded.MediaTracker is used when a group of images are loaded.

Page 26: PROGARMMING THROUGH JAVA Presentation on IMAGES Group No:3 Presented By: Anthony Narzary (DC2012MCA0002) Chandra Gupta Bora (DC2012MCA0009) Dipankar Saikia

SAMPLE PROGRAM

import java.util.*;import java.applet.*;import java.awt.*;public class TrackedImageLoad extends Applet implements Runnable{

MediaTracker tracker;int tracked;int frame_rate = 5;int current_img = 0;Thread motor;static final int MAXIMAGES = 10;Image img[] = new Image[MAXIMAGES];String name[] = new String[MAXIMAGES];boolean stopFlag;

Page 27: PROGARMMING THROUGH JAVA Presentation on IMAGES Group No:3 Presented By: Anthony Narzary (DC2012MCA0002) Chandra Gupta Bora (DC2012MCA0009) Dipankar Saikia

public void init(){

tracker = new MediaTracker(this);StringTokenizer st = new

StringTokenizer(getParameter("img"),"+");while(st.hasMoreTokens() && tracked <= MAXIMAGES){

name[tracked] = st.nextToken();img[tracked] = getImage(getDocumentBase(),name[tracked]

+".jpg");tracker.addImage(img[tracked], tracked);tracked++;

}}

Page 28: PROGARMMING THROUGH JAVA Presentation on IMAGES Group No:3 Presented By: Anthony Narzary (DC2012MCA0002) Chandra Gupta Bora (DC2012MCA0009) Dipankar Saikia

public void paint(Graphics g) {

String loaded = "";int donecount = 0;for(int i=0; i<tracked; i++){

if (tracker.checkID(i, true)){

donecount++;loaded += name[i] + " ";

}}Dimension d = getSize();int w = d.width;int h = d.height;if (donecount == tracked){

frame_rate = 1;Image i = img[current_img++];int iw = i.getWidth(null);

Page 29: PROGARMMING THROUGH JAVA Presentation on IMAGES Group No:3 Presented By: Anthony Narzary (DC2012MCA0002) Chandra Gupta Bora (DC2012MCA0009) Dipankar Saikia

int ih = i.getHeight(null);g.drawImage(i, (w - iw)/2, (h - ih)/2, null);if (current_img >= tracked)current_img = 0;

}else{

int x = w * donecount / tracked;g.setColor(Color.black);g.fillRect(0, h/3, x, 16);g.setColor(Color.white);g.fillRect(x, h/3, w-x, 16);g.setColor(Color.black);g.drawString(loaded, 10, h/2);

}}

Page 30: PROGARMMING THROUGH JAVA Presentation on IMAGES Group No:3 Presented By: Anthony Narzary (DC2012MCA0002) Chandra Gupta Bora (DC2012MCA0009) Dipankar Saikia

public void start() {

motor = new Thread(this);stopFlag = false;motor.start();

}public void stop() {

stopFlag = true;}public void run() {

motor.setPriority(Thread.MIN_PRIORITY);while (true) {

repaint();try {

Thread.sleep(1000/frame_rate);} catch (InterruptedException e) { };if(stopFlag)return;

}}

}

Page 31: PROGARMMING THROUGH JAVA Presentation on IMAGES Group No:3 Presented By: Anthony Narzary (DC2012MCA0002) Chandra Gupta Bora (DC2012MCA0009) Dipankar Saikia

/** <applet code="TrackedImageLoad" width=300 height=400>* <param name="img"* value="vincent+leonardo+matisse+picasso+renoir+seurat+vermeer">* </applet>*/

Page 32: PROGARMMING THROUGH JAVA Presentation on IMAGES Group No:3 Presented By: Anthony Narzary (DC2012MCA0002) Chandra Gupta Bora (DC2012MCA0009) Dipankar Saikia

THAN

KS