⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 315-319.html

📁 dshfghfhhgsfgfghfhfghgfhfghfgh fg hfg hh ghghf hgf hghg gh fg hg hfg hfh f hg hgfh gkjh kjkh g yj f
💻 HTML
字号:
<HTML>
<HEAD>
<META name=vsisbn content="1558515682"><META name=vstitle content="Java Digital Signal Processing"><META name=vsauthor content="Douglas A. Lyon"><META name=vsimprint content="M&T Books"><META name=vspublisher content="IDG Books Worldwide, Inc."><META name=vspubdate content="11/01/97"><META name=vscategory content="Web and Software Development: Programming, Scripting, and Markup Languages: Java"><TITLE>Java Digital Signal Processing:An Introduction to Image Processing</TITLE>
<!-- HEADER --><STYLE type="text/css">  <!-- A:hover  { 	color : Red; } --></STYLE><META NAME="ROBOTS" CONTENT="NOINDEX, NOFOLLOW">
<!--ISBN=1558515682//-->
<!--TITLE=Java Digital Signal Processing//-->
<!--AUTHOR=Douglas A. Lyon//-->
<!--PUBLISHER=IDG Books Worldwide, Inc.//-->
<!--IMPRINT=M & T Books//-->
<!--CHAPTER=7//-->
<!--PAGES=315-319//-->
<!--UNASSIGNED1//-->
<!--UNASSIGNED2//-->

<CENTER>
<TABLE BORDER>
<TR>
<TD><A HREF="310-315.html">Previous</A></TD>
<TD><A HREF="../ewtoc.html">Table of Contents</A></TD>
<TD><A HREF="319-323.html">Next</A></TD>
</TR>
</TABLE>
</CENTER>
<P><BR></P>
<P>The following example of the use of <I>IntDialog</I> can be found in the <I>AudioFrame</I> class.</P>
<!-- CODE SNIP //-->
<PRE>
IntDialog spDialog = new IntDialog(
                   "start Position Of Samples To Graph dialog",
                   "Enter start position:",
                   startPositionOfSamplesToGraph
                   );
</PRE>
<!-- END CODE SNIP //-->
<P>Where
</P>
<!-- CODE SNIP //-->
<PRE>
       private ObservableInt startPositionOfSamplesToGraph;
</PRE>
<!-- END CODE SNIP //-->
<P>is declared in <I>AudioFrame</I> as a class variable.</P>
<H4 ALIGN="LEFT"><A NAME="Heading10"></A><FONT COLOR="#000077">Dialog Boxes in the ImageFrame</FONT></H4>
<P>The <I>ImageFrame</I> class, which resides in the <I>lyon.ipl</I> package, is used to hold and display instances that contain image data. It is also used to dispatch events and manage dialog boxes that prompt the user for parameters. All the dialog boxes contain instances of <I>Observable</I> classes. Following is a list of the <I>Observable</I> class variables in the <I>ImageFrame</I> and the <I>Dialog</I> instance creation that depends on them. Lines 1 and 2 contain two <I>ObservableDouble</I> instances, each provided with a label (because they are named) and a value.</P>
<!-- CODE //-->
<PRE>
private ObservableDouble
        multKonst  = new ObservableDouble(1.0, "mult:");
private ObservableDouble
        addKonst  = new ObservableDouble(0.0, "add:");
private ObservableInt threshholdKonst
        = new ObservableInt(128, "Threshold:");
private ObservableInt scaleKonst
        = new ObservableInt(1, "Scale:");
private DoubleDialog multDialog
        = new DoubleDialog("Multiply Dialog",
          "* k", multKonst);
private DoubleDialog addDialog
        = new DoubleDialog("Add Dialog",
          "+ offset", addKonst);
private IntDialog threshDialog
        = new IntDialog("Threshold Dialog",
          "Threshold constant", threshholdKonst);
private IntDialog scaleKonstDialog
        = new IntDialog("Scale Dialog",
          "Integer Scale constant", scaleKonst);
</PRE>
<!-- END CODE //-->
<P>When an instance of the <I>ImageFrame</I> class is made, the <I>IntDialog</I> and <I>DoubleDialog</I> instances appear on the screen. At that point, the user can override the defaults in the dialog boxes and click <B>OK</B>. The image processing operation is invoked and uses the updated values. For example:</P>
<!-- CODE SNIP //-->
<PRE>
public void linearComb() {
     pp.linearComb(multKonst.getValue(),addKonst.getValue());
     updateDisplay(pp);
}
</PRE>
<!-- END CODE SNIP //-->
<H3><A NAME="Heading11"></A><FONT COLOR="#000077">The Image Class</FONT></H3>
<P>In Java, an image is stored in an instance of the <I>Image</I> class, which resides in the <I>java.awt</I> package. The <I>Image</I> class is designed with the intention that images are produced by I/O bound systems (network-based systems). The <I>Image</I> class has provisions to take <I>ImageObserver</I> instances in many of its methods. The <I>ImageObserver</I> instance is registered for notification after an image becomes available.</P>
<H4 ALIGN="LEFT"><A NAME="Heading12"></A><FONT COLOR="#000077">Class Summary</FONT></H4>
<!-- CODE //-->
<PRE>
package java.awt;
import java.awt.image.ImageProducer;
import java.awt.image.ImageObserver;

public abstract class Image {
 public abstract int getWidth(ImageObserver observer);
 public abstract int getHeight(ImageObserver observer);
 public abstract ImageProducer getSource();
 public abstract Graphics getGraphics();
 public abstract Object getProperty(String name, ImageObserver observer);
 public static final Object UndefinedProperty = new Object();
public abstract void flush();
}
</PRE>
<!-- END CODE //-->
<H4 ALIGN="LEFT"><A NAME="Heading13"></A><FONT COLOR="#000077">Class Usage</FONT></H4>
<P>The <I>Image</I> class uses the observer-observable model. The Image class is an abstract class and so can not be instanced. Recall from Chapter 3 that every <I>Component</I> implements an <I>ImageObserver</I>. This means that we can pass an instance of the <I>Component</I> to the <I>image.getWidth</I> invocation to obtain a callback. The callback will occur in the form of an <I>imageUpdate</I> method invocation on the interested <I>ImageObserver</I> instance.</P>
<P>Suppose the following variables are predefined:</P>
<!-- CODE SNIP //-->
<PRE>
Image image;
ImageObserver imageObserver;
ImageProducer imageProducer;
int height, width;
Graphics graphics;
String name;
</PRE>
<!-- END CODE SNIP //-->
<P>To get the width of the image, use this code:
</P>
<!-- CODE SNIP //-->
<PRE>
width = image.getWidth(imageObserver);
</PRE>
<!-- END CODE SNIP //-->
<P>It returns -1 if the image is not ready and notifies <I>Observer</I> when the image becomes ready.</P>
<P>To get the height of the image, use this code:</P>
<!-- CODE SNIP //-->
<PRE>
height = image.getHeight(imageObserver);
</PRE>
<!-- END CODE SNIP //-->
<P>It returns -1 if the image is not ready and notifies <I>Observer</I> when the image becomes ready.</P>
<P>To get the instance that produces the image pixels:</P>
<!-- CODE SNIP //-->
<PRE>
imageProducer = image.getSource();
</PRE>
<!-- END CODE SNIP //-->
<P>To get a graphics instance for an off-screen image:
</P>
<!-- CODE SNIP //-->
<PRE>
graphics = image.getGraphics();
</PRE>
<!-- END CODE SNIP //-->
<P>To get an image property by name:
</P>
<!-- CODE SNIP //-->
<PRE>
object = image.getProperty(name, imageObserver);
</PRE>
<!-- END CODE SNIP //-->
<P>If the image is not available, <I>getProperty</I> returns null and notifies <I>imageObserver</I> later. <I>Image.UndefinedProperty</I> is a static final <I>Object</I> instance that is returned when the property is undefined.</P>
<P>To destroy all the resources used by an image that will probably not be used for a while, use this:</P>
<!-- CODE SNIP //-->
<PRE>
image.flush();
</PRE>
<!-- END CODE SNIP //-->
<H3><A NAME="Heading14"></A><FONT COLOR="#000077">The ImageObserver Interface</FONT></H3>
<P>The <I>ImageObserver</I> interface resides in the <I>java.awt.image</I> package. An instance of a class that implements the <I>ImageObserver</I> interface registers as having an interest in the contents of an <I>ImageProducer</I> instance. When the contents are altered, the <I>ImageObserver</I> instance is notified by the <I>ImageProducer</I> instance using the <I>imageUpdate</I> method invocation.</P>
<H4 ALIGN="LEFT"><A NAME="Heading15"></A><FONT COLOR="#000077">Class Summary</FONT></H4>
<!-- CODE //-->
<PRE>
package java.awt.image;
import java.awt.Image;
public interface ImageObserver {
 public boolean imageUpdate(Image img, int infoflags, int x, int y, int
 width, int height);
 public static final int WIDTH = 1;
 public static final int HEIGHT = 2;
 public static final int PROPERTIES = 4;
 public static final int SOMEBITS = 8;
 public static final int FRAMEBITS = 16;
 public static final int ALLBITS = 32;
 public static final int ERROR = 64;
 public static final int ABORT = 128;
}
</PRE>
<!-- END CODE //-->
<P><BR></P>
<CENTER>
<TABLE BORDER>
<TR>
<TD><A HREF="310-315.html">Previous</A></TD>
<TD><A HREF="../ewtoc.html">Table of Contents</A></TD>
<TD><A HREF="319-323.html">Next</A></TD>
</TR>
</TABLE>
</CENTER>

<hr width="90%" size="1" noshade><div align="center"><font face="Verdana,sans-serif" size="1">Copyright &copy; <a href="/reference/idgbooks00001.html">IDG Books Worldwide, Inc.</a></font></div>
<!-- all of the reference materials (books) have the footer and subfoot reveresed --><!-- reference_subfoot = footer --><!-- reference_footer = subfoot --></BODY></HTML><!-- END FOOTER -->

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -