Presentation is loading. Please wait.

Presentation is loading. Please wait.

Using the JImageViewer classes. JImageViewer classes JImageViewer class JImageViewer class ImagePanel class ImagePanel class Image class Image class.

Similar presentations


Presentation on theme: "Using the JImageViewer classes. JImageViewer classes JImageViewer class JImageViewer class ImagePanel class ImagePanel class Image class Image class."— Presentation transcript:

1 Using the JImageViewer classes

2 JImageViewer classes JImageViewer class JImageViewer class ImagePanel class ImagePanel class Image class Image class

3 JImageViewer classes JImageViewer class JImageViewer class main program entry point main program entry point construct one w/ image file name and a new window w/ an image will appear construct one w/ image file name and a new window w/ an image will appear menus & menu callbacks menus & menu callbacks implements ActionListener implements ActionListener contains: contains: mImagePanel mImagePanel mImage mImage

4 JImageViewer classes ImagePanel class ImagePanel class displays image via paint method displays image via paint method double buffered double buffered draws image into temporary buffer draws image into temporary buffer draws location string into temporary buffer draws location string into temporary buffer then draws temporary buffer then draws temporary buffer contains reference to JImageViewer “parent” via mParent contains reference to JImageViewer “parent” via mParent implements MouseMotionListener implements MouseMotionListener updates mMouseX and mMouseY updates mMouseX and mMouseY does NOT listen to clicks does NOT listen to clicks must implement MouseListener to receive mouse clicks (and a whole bunch of other events) must implement MouseListener to receive mouse clicks (and a whole bunch of other events)

5 JImageViewer classes Image class Image class constructor & image data members constructor & image data members given an image file name, the ctor loads the image into the member data given an image file name, the ctor loads the image into the member data

6 JImageViewer classes Image class Image class members: members: mW & mH (width and height of image) mW & mH (width and height of image) mMin & mMax (min and max scalar pixel value) mMin & mMax (min and max scalar pixel value) mIsColor mIsColor True if color True if color False if gray False if gray mImage mImage 1D int array of pixel values 1D int array of pixel values Each int is either Each int is either a single gray value or a single gray value or an rgb (red/green/blue) value an rgb (red/green/blue) value Cannot be drawn by Java Cannot be drawn by Java mOriginalImage mOriginalImage original image data original image data mScreenImage mScreenImage image data actually drawn in window image data actually drawn in window

7 JImageViewer classes Image class Image class mImage mImage 1D int array of pixel values 1D int array of pixel values each int is either each int is either a single gray value or a single gray value or an rgb value an rgb value What is mImage.length? What is mImage.length? If color, how can we get at the individual rgb values? If color, how can we get at the individual rgb values? Each rgb int contains contains: Each rgb int contains contains: 8 bits for red 8 bits for red 8 bits for green 8 bits for green 8 bits for blue 8 bits for blue sometimes an 8 bits alpha blending value is present as well sometimes an 8 bits alpha blending value is present as well How many different colors can we represent? How many different colors can we represent? What is gray in terms of rgb? What is gray in terms of rgb? How many different shades of grary can we represent? How many different shades of grary can we represent?

8 Representing color So given an integer containing an argb value, how can we get at the individual component values? So given an integer containing an argb value, how can we get at the individual component values? B is the least significant (8 bit) byte. B is the least significant (8 bit) byte. Bits 7..0 Bits 7..0 G is bits 15..8 G is bits 15..8 R is bits 23..16 R is bits 23..16 A is bits 31..24 A is bits 31..24

9 Representing color B is the least significant (8 bit) byte. B is the least significant (8 bit) byte. bits 7..0 bits 7..0 int b = mImage[i] & ?; int b = mImage[i] & ?;

10 Representing color B is the least significant (8 bit) byte. B is the least significant (8 bit) byte. bits 7..0 bits 7..0 int b = mImage[i] & 0xff; int b = mImage[i] & 0xff;

11 Representing color G is bits 15..8 G is bits 15..8 int g = mImage[i] ?; int g = mImage[i] ?;

12 Representing color G is bits 15..8 G is bits 15..8 int g = (mImage[i] & 0xff00) >> 8; int g = (mImage[i] & 0xff00) >> 8;

13 Representing color R is bits 23..16 R is bits 23..16 int r = mImage[i] ?; int r = mImage[i] ?;

14 Representing color R is bits 23..16 R is bits 23..16 int r = (mImage[i] & 0xff0000) >> 16; int r = (mImage[i] & 0xff0000) >> 16;

15 Color Given individual rgb values (as 3 int/bytes), how do we “pack” them into a single int? Given individual rgb values (as 3 int/bytes), how do we “pack” them into a single int? int r = 12; int r = 12; int g = 14; int g = 14; int b = 92; int b = 92; int rgb = ?; int rgb = ?;

16 Color Given individual rgb values (as 3 int/bytes), how do we “pack” them into a single int? Given individual rgb values (as 3 int/bytes), how do we “pack” them into a single int? int r = 12; int r = 12; int g = 14; int g = 14; int b = 92; int b = 92; int rgb = (r<<16) | (g<<8) | b; int rgb = (r<<16) | (g<<8) | b;

17

18 Color Say we process our image data and wish to change the image that appears on the screen? Say we process our image data and wish to change the image that appears on the screen? Where is the image data? Where is the image data? Where is the displayed image? Where is the displayed image?

19 Color Say we process our image data and wish to change the image that appears on the screen? Say we process our image data and wish to change the image that appears on the screen? Where is the image data? Where is the image data? In mImage in the Image class. In mImage in the Image class. Where is the displayed image? Where is the displayed image? In mScreenImage in the Image class. In mScreenImage in the Image class.

20 Displaying image data mScreenImage in the Image class is of type BufferedImage. mScreenImage in the Image class is of type BufferedImage. It is what appears in the window. It is what appears in the window. Allocated by: Allocated by: mScreenImage = new BufferedImage( mW, mH, BufferedImage.TYPE_INT_RGB ); It is set/changed by: It is set/changed by:mScreenImage.setRGB( 0, 0, mW, mH, mImage, 0, mW );

21 Displaying image data mScreenImage.setRGB( 0, 0, mW, mH, mImage, 0, mW ); mImage must be in rgb format mImage must be in rgb format What do we do for gray data? What do we do for gray data? Gray data may be more than 8 bits! Gray data may be more than 8 bits!


Download ppt "Using the JImageViewer classes. JImageViewer classes JImageViewer class JImageViewer class ImagePanel class ImagePanel class Image class Image class."

Similar presentations


Ads by Google