1 / 21

Using the JImageViewer classes

Using the JImageViewer classes. JImageViewer classes. JImageViewer class ImagePanel class Image class. JImageViewer classes. JImageViewer class main program entry point construct one w/ image file name and a new window w/ an image will appear menus & menu callbacks

amil
Download Presentation

Using the JImageViewer classes

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. Using the JImageViewer classes

  2. JImageViewer classes • JImageViewer class • ImagePanel class • Image class

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

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

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

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

  7. JImageViewer classes • Image class • mImage • 1D int array of pixel values • each int is either • a single gray value or • an rgb value • What is mImage.length? • If color, how can we get at the individual rgb values? • Each rgb int contains contains: • 8 bits for red • 8 bits for green • 8 bits for blue • sometimes an 8 bits alpha blending value is present as well • How many different colors can we represent? • What is gray in terms of rgb? • 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? • B is the least significant (8 bit) byte. • Bits 7..0 • G is bits 15..8 • R is bits 23..16 • A is bits 31..24

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

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

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

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

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

  14. Representing color • R is bits 23..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? • int r = 12; • int g = 14; • int b = 92; • int rgb = ?;

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

  17. Color • 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 displayed image?

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

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

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

More Related