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

📄 ch7.htm

📁 JAVA Developing Professional JavaApplets
💻 HTM
📖 第 1 页 / 共 5 页
字号:
<HTML><HEAD><TITLE>developer.com - Reference</TITLE><META NAME="Author" CONTENT="developer.com"><META NAME="Keywords" CONTENT="javascript, ActiveX, VRML, Push, channel,push channel, applet, directory, news, community, developer, internet,intranet, java, java applet, J++, javabeans, java products, tools, javatools, JDK, java development kit, java development environment, JIT,JavaPlan, enterprise tools, JVM, Java Virtual Machine, Java resources, API,browser, java documentation, CDF, Common Desktop Format, RDF, ResourceDescription Framework, Netcaster, Netcast, Castanet, meta-language, metadata,solaris, Solaris, SUN, CGI, Perl, Oracle, database, network, Netscape API,Apache, apache, SSL, mSQL, Netscape, Fasttrack, FastTrack,industry standard, ActiveX bridge, web, internet, site, sitedesign, microsoft, active server pages, asp, iis, nt, win95, 95, html, cgi,frontpage, business, corporate, vbscript, javascript, activex, isapi,database, access, sql, server, www, 3.0, 3.01, 3.02, 3.03, 3.04, 4.0,4.0b2, 4.01, 4.03, 4.04, connection, online, commerce, publisher,publishing, publish, webmaster, dynamic html, dhtml, windows 98, netscape,netscape software, shareware, magazines, jobs, japan, free, freeware, freestuff"><META NAME="description" CONTENT="Developer.com is the leading onlineservice for developers. It includes Gamelan, the official directory for Java, as wellas news, information, tutorials, and directories for other Internet technologiesincluding ActiveX, JavaScript, perl, VRML, Java Beans, push technologies, andother Internet and intranet technologies. Developer.com is also the home ofDeveloper Direct, the Professional Developer's Store, where developers canpurchase and download thousands of Web, authoring and other developmentproducts at some of today's lowest prices."><META NAME="distribution" CONTENT="global"><META NAME="resource-type" CONTENT="document"><META NAME="language" CONTENT="en"></HEAD><BODY BACKGROUND="/images/curve_r-wide.gif" BGCOLOR="#FFFFFF" TEXT="#000000" LINK="#DD0000" VLINK="#999999" ALINK="#FF0000"><TABLE><TR><TD VALIGN=TOP WIDTH=120><A HREF="/" ><IMG SRC="/images/masthead_r.gif" WIDTH="100" HEIGHT="78" BORDER="0"ALT="Developer.com Logo"></a></TD><TD><a target="resource window" href="http://adserver.developer.com/cgi-bin/accipiter/adclick.exe/AREA=DCBAN.REF/DT=null"><img src="http://adserver.developer.com/cgi-bin/accipiter/adserver.exe/AREA=DCBAN.REF/DT=null" HEIGHT="60" WIDTH="468" ALT="Click here to support our advertisers"><BR><CENTER>Click here to support our advertisers</CENTER></a></TD></TR></TABLE><!--outer table--><TABLE><!--outer table--><TR><!--outer table--><TD VALIGN="TOP"><!--navbar info --><table><tr><td><A HREF="http://www.developerdirect.com/" ><IMG SRC="/images/button_s.gif" width="15" height="11" BORDER="0"><FONT FACE="Arial, Helvetica" SIZE="-1" color="#000000"><b>SHOPPING</b></font></a></td></tr><tr><td><A HREF="/community/jobs/c_jobs.html"><IMG SRC="/images/button_d.gif" width="15" height="11" BORDER="0"><FONT FACE="Arial, Helvetica" SIZE="-1" color="#000000"><B>JOB BANK</B></font></a></td></tr><tr><td><A HREF="http://www.classifieds2000.com/cgi-cls/display.exe?Developer+computer+searchcomputercategories"><IMG SRC="/images/button_d.gif" width="15" height="11" BORDER="0"><FONT FACE="Arial, Helvetica" SIZE="-1" color="#000000"><B>CLASSIFIEDS</B></font></a></td></tr><tr><td><A HREF="/directories/directories.html"><IMG SRC="/images/button_d.gif" width="15" height="11" BORDER="0"><FONT FACE="Arial, Helvetica" SIZE="-1" color="#000000"><B>DIRECTORIES</B></font></a></td></tr><tr><td><A HREF="/reference/"><IMG SRC="/images/button_r.gif" width="15" height="11" BORDER="0"><FONT FACE="Arial, Helvetica" SIZE="-1" color="#000000"><B>REFERENCE</B></font></a><br><a href="/reference/r_library.html"><FONT FACE="Arial, Helvetica" SIZE="-1" color="#000000">Online Library</a></font></td></tr><tr><td><A HREF="/classroom/"><IMG SRC="/images/button_r.gif" width="15" height="11" BORDER="0"><FONT FACE="Arial, Helvetica" SIZE="-1" color="#000000"><B>LEARNING CENTER</B></font></a></td></tr><tr><td><A HREF="/journal/"><IMG SRC="/images/button_n.gif" width="15" height="11" BORDER="0"><B><FONT FACE="Arial, Helvetica" SIZE="-1" color="#000000">JOURNAL</font></B></a></td></tr><tr><td><A HREF="/news/"><IMG SRC="/images/button_d.gif" width="15" height="11" BORDER="0"><FONT FACE="Arial, Helvetica" SIZE="-1" color="#000000"><b>NEWS CENTRAL</b></font></a></td></tr><tr><td><A HREF="/downloads/"><IMG SRC="/images/button_d.gif" width="15" height="11" BORDER="0"><FONT FACE="Arial, Helvetica" SIZE="-1" color="#000000"><b>DOWNLOADS</b></font></a></td></tr><tr><td><A HREF="/community/" ><IMG SRC="/images/button_c.gif" width="15" height="11" BORDER="0"><FONT FACE="Arial, Helvetica" SIZE="-1" color="#000000"><B>COMMUNITY</B></font></a></td></tr><tr><td><A HREF="/calendar/"><IMG SRC="/images/button_d.gif" width="15" height="11" BORDER="0"><FONT FACE="Arial, Helvetica" SIZE="-1" color="#000000"><b>CALENDAR</b></font></a></td></tr><tr><td><A HREF="/about/"><IMG SRC="/images/button_a.gif" width="15" height="11" BORDER="0"><FONT FACE="Arial, Helvetica" SIZE="-1" color="#000000"><b>ABOUT US</b></a></font></td></tr></table><table><tr><td><form action="/subscribe/list.cgi" method=post ><img src="/images/rule.gif" width="100" height="2"><br><B><FONT FACE="Arial, Helvetica" SIZE="-1">Journal:</b></font><br><input name='email' value='your e-mail' size="11"><input type='hidden'  name='state' value='Subscribe'></td></tr><tr><td><input type='submit' value='Subscribe'><br><font size="-1">Get the weekly email highlights from the most popular journal for developers!<br><a href="http://www.developer.com/subscribe.html">Current issue</a><img src="/images/rule.gif" width="100" height="2"><input type='hidden' name='name' value='New Subscriber'></FORM></td></tr></table><!--/navbar--><font size="-1"><A HREF="http://www.developer.com">developer.com</a><BR><A HREF="http://www.developerdirect.com">developerdirect.com</a><BR><A HREF="http://www.htmlgoodies.com">htmlgoodies.com</a><BR><A HREF="http://www.javagoodies.com">javagoodies.com</a><br><A HREF="http://www.jars.com">jars.com</a><BR><a href="http://www.intranetjournal.com">intranetjournal.com</a><br><a href="http://www.javascripts.com">javascripts.com</a><br></font><!--outer table--></TD><!--outer table--><TD VALIGN="TOP"><BLOCKQUOTE><P><img src="/images/header_r.gif" width="440" height="50"><P><MAP NAME ="header_r2.gif.map"><AREA SHAPE ="RECT"      HREF ="/reference/author.html"      COORDS ="361,0,440,29"><AREA SHAPE ="RECT"      HREF ="/reference/basic.html"      COORDS ="254,0,360,29"><AREA SHAPE ="RECT"      HREF ="/reference/help.html"      COORDS ="183,0,251,29"><AREA SHAPE ="RECT"      HREF ="/reference/cool.html"      COORDS ="100,0,181,29"><AREA SHAPE ="RECT"      HREF ="/reference/mybook.html"      COORDS ="0,0,100,29"></MAP><MAP NAME ="header_r1.gif.map"><AREA SHAPE ="RECT"      HREF ="/reference/personalize.html"      COORDS ="339,0,439,29"></MAP><p><font face="Arial,Helvetica" size="-1" color="#006666"><A HREF="/reference/r_library.html"><B>All Categories</A> :</B><b><A HREF="/reference/r_java.html">Java</A></b></font><p>   <META NAME="GENERATOR" CONTENT="Mozilla/3.0b5aGold (WinNT; I) [Netscape]"><H1><FONT COLOR=#FF0000>Chapter 7</FONT></H1><H1><B><FONT SIZE=5 COLOR=#FF0000>Java and Images</FONT></B></H1><P><HR WIDTH="100%"></P><P><H3 ALIGN=CENTER><FONT COLOR="#000000"><FONT SIZE=+2>CONTENTS<A NAME="CONTENTS"></A></FONT></FONT></H3><UL><LI><A HREF="#DisplayingImages" >Displaying Images</A><UL><LI><A HREF="#LoadingJavaImages" >Loading Java Images</A><LI><A HREF="#ImageDisplay" >Image Display</A><LI><A HREF="#ImageObservers" >Image Observers</A></UL><LI><A HREF="#TrackingImageLoading" >Tracking Image Loading</A><LI><A HREF="#TheConsumerProducerModel" >The Consumer/Producer Model</A><LI><A HREF="#JavaColorModels" >Java Color Models</A><UL><LI><A HREF="#DefaultRGB" >Default RGB</A><LI><A HREF="#DirectColor" >Direct Color</A><LI><A HREF="#IndexColor" >Index Color</A></UL><LI><A HREF="#ChapterProjectDisplayingaWindowsBM" >Chapter Project: Displaying a Windows BMP Image</A><UL><LI><A HREF="#UsingImageTypesNotSupportedbyJava" >Using Image Types Not Supported by Java</A><LI><A HREF="#MemoryImages" >Memory Images</A><LI><A HREF="#LoadingForeignImages" >Loading Foreign Images</A><LI><A HREF="#BMPFileFormat" >BMP File Format</A><LI><A HREF="#ReadingUnsignedBinaryinJava" >Reading Unsigned Binary in Java</A><LI><A HREF="#CreatingtheColorTable" >Creating the Color Table</A><LI><A HREF="#ConstructingtheImage" >Constructing the Image</A></UL><LI><A HREF="#Summary" >Summary</A></UL><HR><P>Images offer the best way to work with Java graphics; as a matterof fact, everything in the AWT seems centered on the concept ofimages. This chapter shows you how to use Java for generatingimages. It leads off with rendering and tracking a simple imageand continues by explaining the fundamental model behind Javaimages. The chapter ends by writing a class to display image formatsnot directly supported by Java.<H2><A NAME="DisplayingImages"><FONT SIZE=5 COLOR=#FF0000>DisplayingImages</FONT></A></H2><P>Images are nothing more than a collection of colors and theirlayout, but they are useful because, with an auxiliary paint program,you can create sophisticated visual effects that can be capturedand displayed in your applets.<P>Java arrives with built-in support for two types of images: GIFand JPEG. The GIF standard (Graphics Interchange Format) is maintainedby CompuServe. It uses an excellent compression scheme (LZW) torepresent a large image in a small file. JPEG (Joint PhotographicExperts Group) is an international standard mainly used for photographicmaterial. It uses a discrete cosine transform (DCT) to removeextraneous material your eye doesn't really notice, so a veryefficient compression scheme can be used. The cosine transformis &quot;lossy,&quot; meaning it loses some information when applied.LZW, on the other hand, is &quot;lossless.&quot; It turns outthat the information removed by a cosine transform is preciselythe photographic detail that your eye does not see.<H3><A NAME="LoadingJavaImages">Loading Java Images</A></H3><P>Both these formats can be easily loaded by your applets:<BLOCKQUOTE><TT>Image newImage = getImage(<I>URL</I>);<BR>Image newImage = Toolkit.getDefaultToolkit().getImage(<I>filenameor URL</I>);</TT></BLOCKQUOTE><P>The first line may be used only from a subclass of Applet, butline two can be called by either an applet or application. Each<TT>getImage()</TT> method returnsimmediately, without actually loading the image. To retrieve theimage, you must try to display it; this is done to keep memoryconsumption down. For example, sometimes an applet might referto an image, but not actually make use of it. Therefore, untilthe image is really needed, it will remain on the server.<BR><P><CENTER><TABLE BORDERCOLOR=#000000 BORDER=1 WIDTH=80%><TR VALIGN=TOP><TD><B>Note</B></TD></TR><TR VALIGN=TOP><TD><BLOCKQUOTE>The <TT>getImage()</TT> method does not cause your image to be loaded. The image remains on the server until you try to display it.</BLOCKQUOTE></TD></TR></TABLE></CENTER><P><P>The Applet class provides two versions of <TT>getImage()</TT>:<UL><LI><TT>public Image getImage(URL imgLocation);</TT><LI><TT>public Image getImage(URL baseLocation,String filename);</TT></UL><P>The second call is the one most commonly used because appletscan load only from the server they originated on. The methodsto get either the URL of the page or the applet code's URL canthen be combined with the filename of the image to construct acomplete path:<BLOCKQUOTE><TT>Image newImage = getImage(getDocumentBase(),&quot;image.gif&quot;);</TT></BLOCKQUOTE><P>or

⌨️ 快捷键说明

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