Using the JImageViewer classes
description
Transcript of Using the JImageViewer classes
![Page 1: Using the JImageViewer classes](https://reader036.fdocuments.in/reader036/viewer/2022062409/56814fb9550346895dbd7287/html5/thumbnails/1.jpg)
Using the JImageViewer Using the JImageViewer classesclasses
![Page 2: Using the JImageViewer classes](https://reader036.fdocuments.in/reader036/viewer/2022062409/56814fb9550346895dbd7287/html5/thumbnails/2.jpg)
JImageViewer classesJImageViewer classes JImageViewer classJImageViewer class ImagePanel classImagePanel class Image classImage class
![Page 3: Using the JImageViewer classes](https://reader036.fdocuments.in/reader036/viewer/2022062409/56814fb9550346895dbd7287/html5/thumbnails/3.jpg)
JImageViewer classesJImageViewer classes JImageViewer classJImageViewer class
main program entry pointmain program entry point construct one w/ image file name and a new window construct one w/ image file name and a new window
w/ an image will appearw/ an image will appear menus & menu callbacksmenus & menu callbacks
implements ActionListenerimplements ActionListener contains:contains:
mImagePanelmImagePanel mImagemImage
![Page 4: Using the JImageViewer classes](https://reader036.fdocuments.in/reader036/viewer/2022062409/56814fb9550346895dbd7287/html5/thumbnails/4.jpg)
JImageViewer classesJImageViewer classes ImagePanel classImagePanel class
displays image via paint methoddisplays image via paint method double buffereddouble buffered
draws image into temporary bufferdraws image into temporary buffer draws location string into temporary bufferdraws location string into temporary buffer then draws temporary bufferthen draws temporary buffer
contains reference to JImageViewer “parent” via contains reference to JImageViewer “parent” via mParentmParent
implements MouseMotionListenerimplements MouseMotionListener updates mMouseX and mMouseYupdates mMouseX and mMouseY does NOT listen to clicksdoes NOT listen to clicks
must implement MouseListener to receive mouse must implement MouseListener to receive mouse clicks (and a whole bunch of other events)clicks (and a whole bunch of other events)
![Page 5: Using the JImageViewer classes](https://reader036.fdocuments.in/reader036/viewer/2022062409/56814fb9550346895dbd7287/html5/thumbnails/5.jpg)
JImageViewer classesJImageViewer classes Image classImage class
constructor & image data membersconstructor & image data members given an image file name, the ctor loads the image given an image file name, the ctor loads the image
into the member datainto the member data
![Page 6: Using the JImageViewer classes](https://reader036.fdocuments.in/reader036/viewer/2022062409/56814fb9550346895dbd7287/html5/thumbnails/6.jpg)
JImageViewer classesJImageViewer classes Image classImage 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) mIsColormIsColor
True if colorTrue if color False if grayFalse if gray
mImagemImage 1D int array of pixel values1D int array of pixel values Each int is eitherEach int is either
a single gray value ora single gray value or an rgb (red/green/blue) valuean rgb (red/green/blue) value
Cannot be drawn by JavaCannot be drawn by Java mOriginalImagemOriginalImage
original image dataoriginal image data mScreenImagemScreenImage
image data actually drawn in windowimage data actually drawn in window
![Page 7: Using the JImageViewer classes](https://reader036.fdocuments.in/reader036/viewer/2022062409/56814fb9550346895dbd7287/html5/thumbnails/7.jpg)
JImageViewer classesJImageViewer classes Image classImage class
mImagemImage 1D int array of pixel values1D int array of pixel values each int is eithereach int is either
a single gray value ora single gray value or an rgb valuean 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 red8 bits for red 8 bits for green8 bits for green 8 bits for blue8 bits for blue sometimes an 8 bits alpha blending value is present as wellsometimes 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?
![Page 8: Using the JImageViewer classes](https://reader036.fdocuments.in/reader036/viewer/2022062409/56814fb9550346895dbd7287/html5/thumbnails/8.jpg)
Representing colorRepresenting color
So given an integer containing an argb So given an integer containing an argb value, how can we get at the individual value, how can we get at the individual component values?component values?B is the least significant (8 bit) byte.B is the least significant (8 bit) byte.
Bits 7..0Bits 7..0
G is bits 15..8G is bits 15..8R is bits 23..16R is bits 23..16A is bits 31..24A is bits 31..24
![Page 9: Using the JImageViewer classes](https://reader036.fdocuments.in/reader036/viewer/2022062409/56814fb9550346895dbd7287/html5/thumbnails/9.jpg)
Representing colorRepresenting color
B is the least significant (8 bit) byte.B is the least significant (8 bit) byte.bits 7..0bits 7..0 int b = mImage[i] & ?;int b = mImage[i] & ?;
![Page 10: Using the JImageViewer classes](https://reader036.fdocuments.in/reader036/viewer/2022062409/56814fb9550346895dbd7287/html5/thumbnails/10.jpg)
Representing colorRepresenting color
B is the least significant (8 bit) byte.B is the least significant (8 bit) byte.bits 7..0bits 7..0 int b = mImage[i] & 0xff;int b = mImage[i] & 0xff;
![Page 11: Using the JImageViewer classes](https://reader036.fdocuments.in/reader036/viewer/2022062409/56814fb9550346895dbd7287/html5/thumbnails/11.jpg)
Representing colorRepresenting color
G is bits 15..8G is bits 15..8 int g = mImage[i] ?;int g = mImage[i] ?;
![Page 12: Using the JImageViewer classes](https://reader036.fdocuments.in/reader036/viewer/2022062409/56814fb9550346895dbd7287/html5/thumbnails/12.jpg)
Representing colorRepresenting color
G is bits 15..8G is bits 15..8 int g = (mImage[i] & 0xff00) >> 8;int g = (mImage[i] & 0xff00) >> 8;
![Page 13: Using the JImageViewer classes](https://reader036.fdocuments.in/reader036/viewer/2022062409/56814fb9550346895dbd7287/html5/thumbnails/13.jpg)
Representing colorRepresenting color
R is bits 23..16R is bits 23..16 int r = mImage[i] ?;int r = mImage[i] ?;
![Page 14: Using the JImageViewer classes](https://reader036.fdocuments.in/reader036/viewer/2022062409/56814fb9550346895dbd7287/html5/thumbnails/14.jpg)
Representing colorRepresenting color
R is bits 23..16R is bits 23..16 int r = (mImage[i] & 0xff0000) >> 16;int r = (mImage[i] & 0xff0000) >> 16;
![Page 15: Using the JImageViewer classes](https://reader036.fdocuments.in/reader036/viewer/2022062409/56814fb9550346895dbd7287/html5/thumbnails/15.jpg)
ColorColor
Given individual rgb values (as 3 Given individual rgb values (as 3 int/bytes), how do we “pack” them into a int/bytes), how do we “pack” them into a single int?single int? int r = 12;int r = 12; int g = 14;int g = 14; int b = 92;int b = 92; int rgb = ?;int rgb = ?;
![Page 16: Using the JImageViewer classes](https://reader036.fdocuments.in/reader036/viewer/2022062409/56814fb9550346895dbd7287/html5/thumbnails/16.jpg)
ColorColor
Given individual rgb values (as 3 Given individual rgb values (as 3 int/bytes), how do we “pack” them into a int/bytes), how do we “pack” them into a single int?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;
![Page 17: Using the JImageViewer classes](https://reader036.fdocuments.in/reader036/viewer/2022062409/56814fb9550346895dbd7287/html5/thumbnails/17.jpg)
![Page 18: Using the JImageViewer classes](https://reader036.fdocuments.in/reader036/viewer/2022062409/56814fb9550346895dbd7287/html5/thumbnails/18.jpg)
ColorColor
Say we process our image data and wish Say we process our image data and wish to change the image that appears on the to change the image that appears on the screen?screen?
Where is the image data?Where is the image data?Where is the displayed image?Where is the displayed image?
![Page 19: Using the JImageViewer classes](https://reader036.fdocuments.in/reader036/viewer/2022062409/56814fb9550346895dbd7287/html5/thumbnails/19.jpg)
ColorColor
Say we process our image data and wish Say we process our image data and wish to change the image that appears on the to change the image that appears on the screen?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.
![Page 20: Using the JImageViewer classes](https://reader036.fdocuments.in/reader036/viewer/2022062409/56814fb9550346895dbd7287/html5/thumbnails/20.jpg)
Displaying image dataDisplaying image data
mScreenImage in the Image class is of mScreenImage in the Image class is of type BufferedImage.type BufferedImage.
It is what appears in the window.It is what appears in the window.Allocated by:Allocated by:
mScreenImage = new BufferedImage(mScreenImage = new BufferedImage(mW, mH, BufferedImage.TYPE_INT_RGB );mW, mH, BufferedImage.TYPE_INT_RGB );
It is set/changed by:It is set/changed by:mScreenImage.setRGB( mScreenImage.setRGB(
0, 0, mW, mH, mImage, 0, mW );0, 0, mW, mH, mImage, 0, mW );
![Page 21: Using the JImageViewer classes](https://reader036.fdocuments.in/reader036/viewer/2022062409/56814fb9550346895dbd7287/html5/thumbnails/21.jpg)
Displaying image dataDisplaying image data
mScreenImage.setRGB(mScreenImage.setRGB(
0, 0, mW, mH, mImage, 0, mW );0, 0, mW, mH, mImage, 0, mW );mImage must be in rgb formatmImage must be in rgb formatWhat 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!