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

📄 extending the api.htm

📁 是一部关于java高级图像处理的的一本入门书
💻 HTM
📖 第 1 页 / 共 5 页
字号:
    <TABLE cellPadding=3 border=3>
      <CAPTION><FONT size=-1><B></B></FONT></CAPTION>
      <TBODY>
      <TR vAlign=top>
        <TD rowSpan=2><EM>Parameters</EM>:<EM></EM> 
          <P></P>
        <TD><CODE>ras</CODE> 
          <P></P>
        <TD>A read-only <CODE>Raster</CODE> source. 
          <P></P>
      <TR vAlign=top>
        <TD><CODE>bounds</CODE> 
          <P></P>
        <TD>The bounding <CODE>Rectangle</CODE> for the iterator, or null. 
          <P></P></TR></TBODY></TABLE></A>
    <P></P></DD></DL><A name=57770>
  <H3>14.4.4 <IMG src="Extending the API.files/space.gif">Example 
  RectIter</H3></A><A 
  href="http://java.sun.com/products/java-media/jai/forDevelopers/jai1_0_1guide-unc/Extension.doc.html#57929">Listing 
  14-3</A> shows an example of the construction of a new <CODE>RectIter</CODE>.
  <P><CAPTION><FONT size=-1><B><A name=57929>
  <CENTER><FONT size=-1><B><I>Listing 14-3 </I><IMG 
  src="Extending the API.files/sm-blank.gif" border=0> Example 
  RectIter</B></FONT></CENTER></A>
  <P></B></FONT></CAPTION>
  <HR>
  <TR valign="top"><TD rowspan="9" colspan="1"><PRE>     import java.awt.Rectangle;
     import java.awt.image.ColorModel;
     import java.awt.image.DataBuffer;
     import java.awt.image.PixelInterleavedSampleModel;
     import java.awt.image.SampleModel;
     import java.util.Random;
     import javax.media.jai.*;
     import javax.media.jai.iterator.*;
</PRE><TR valign="top"><TR valign="top"><TR valign="top"><TR valign="top"><TR 
  valign="top"><TR valign="top"><TR valign="top"><TR valign="top"><TR 
  valign="top"><TD rowspan="2" colspan="1"><PRE>     class RectIterTest {
</PRE><TR valign="top"><TR valign="top"><TD rowspan="5" colspan="1"><PRE>         int width = 10;
         int height = 10;
         int tileWidth = 4;
         int tileHeight = 4;
</PRE><TR valign="top"><TR valign="top"><TR valign="top"><TR valign="top"><TR 
  valign="top"><TD rowspan="4" colspan="1"><PRE>         public static void main(String[] args) {
             new RectIterTest();
         }
</PRE><TR valign="top"><TR valign="top"><TR valign="top"><TR valign="top"><TD 
  rowspan="2" colspan="1"><PRE>         public RectIterTest() {
</PRE><TR valign="top"><TR valign="top"><TD rowspan="3" colspan="1"><PRE>             Random rand = new Random(1L);
             Rectangle rect = new Rectangle();
</PRE><TR valign="top"><TR valign="top"><TR valign="top"><TD rowspan="8" 
  colspan="1"><PRE>             int[] bandOffsets = { 2, 1, 0 };
             SampleModel sampleModel =
                 new PixelInterleavedSampleModel(DataBuffer.TYPE_BYTE,
                                                 tileWidth, tileHeight,
                                                 3, 3*tileWidth,
                                                 bandOffsets);
             ColorModel colorModel = null;
</PRE><TR valign="top"><TR valign="top"><TR valign="top"><TR valign="top"><TR 
  valign="top"><TR valign="top"><TR valign="top"><TR valign="top"><TD 
  rowspan="4" colspan="1"><PRE>             TiledImage im = new TiledImage(0, 0, width, height, 0, 0,
                                            sampleModel,
                                            colorModel);
</PRE><TR valign="top"><TR valign="top"><TR valign="top"><TR valign="top"><TD 
  rowspan="3" colspan="1"><PRE>             int[][][] check = new int[width][height][3];
             int x, y, b;
</PRE><TR valign="top"><TR valign="top"><TR valign="top"><TD rowspan="4" 
  colspan="1"><PRE>             for (int i = 0; i &lt; 10; i++) {
                 rect.x = rand.nextInt(width);
                 rect.width = rand.nextInt(width - rect.x) + 1;
</PRE><TR valign="top"><TR valign="top"><TR valign="top"><TR valign="top"><TD 
  rowspan="3" colspan="1"><PRE>                 rect.y = rand.nextInt(height);
                 rect.height = rand.nextInt(height - rect.y) + 1;
</PRE><TR valign="top"><TR valign="top"><TR valign="top"><TD rowspan="2" 
  colspan="1"><PRE>     System.out.println("Filling rect " + rect + " with " + i);
</PRE><TR valign="top"><TR valign="top"><TD rowspan="2" colspan="1"><PRE>     WritableRectIter witer = RectIterFactory.createWritable(im,
                                                             rect);
</PRE><TR valign="top"><TR valign="top"><TD rowspan="12" colspan="1"><PRE>                 b = 0;
                 witer.startBands();
                 while (!witer.finishedBands()) {
                     y = rect.y;
                     witer.startLines();
                     while (!witer.finishedLines()) {
                         x = rect.x;
                         witer.startPixels();
                         while (!witer.finishedPixels()) {
                             witer.setSample(i);
                             check[x][y][b] = i;
</PRE><TR valign="top"><TR valign="top"><TR valign="top"><TR valign="top"><TR 
  valign="top"><TR valign="top"><TR valign="top"><TR valign="top"><TR 
  valign="top"><TR valign="top"><TR valign="top"><TR valign="top"><TD 
  rowspan="4" colspan="1"><PRE>                             ++x;
                             witer.nextPixel();
                         }
</PRE><TR valign="top"><TR valign="top"><TR valign="top"><TR valign="top"><TD 
  rowspan="4" colspan="1"><PRE>                         ++y;
                         witer.nextLine();
                     }
</PRE><TR valign="top"><TR valign="top"><TR valign="top"><TR valign="top"><TD 
  rowspan="5" colspan="1"><PRE>                     ++b;
                     witer.nextBand();
                 }
             }
</PRE><TR valign="top"><TR valign="top"><TR valign="top"><TR valign="top"><TR 
  valign="top"><TD rowspan="6" colspan="1"><PRE>             rect.x = 0;
             rect.y = 0;
             rect.width = width;
             rect.height = height;
             RectIter iter = RectIterFactory.createWritable(im, rect);
</PRE><TR valign="top"><TR valign="top"><TR valign="top"><TR valign="top"><TR 
  valign="top"><TR valign="top"><TD rowspan="5" colspan="1"><PRE>             b = 0;
             iter.startBands();
             while (!iter.finishedBands()) {
                 System.out.println();
</PRE><TR valign="top"><TR valign="top"><TR valign="top"><TR valign="top"><TR 
  valign="top"><TD rowspan="4" colspan="1"><PRE>                 y = 0;
                 iter.startLines();
                 while (!iter.finishedLines()) {
</PRE><TR valign="top"><TR valign="top"><TR valign="top"><TR valign="top"><TD 
  rowspan="6" colspan="1"><PRE>                     x = 0;
                     iter.startPixels();
                     while (!iter.finishedPixels()) {
                         int val = iter.getSample();
                         System.out.print(val);
</PRE><TR valign="top"><TR valign="top"><TR valign="top"><TR valign="top"><TR 
  valign="top"><TR valign="top"><TD rowspan="6" colspan="1"><PRE>                         if (val != check[x][y][b]) {
                         System.out.print("(" + check[x][y][b] + ")  ");
                         } else {
                             System.out.print("     ");
                         }
</PRE><TR valign="top"><TR valign="top"><TR valign="top"><TR valign="top"><TR 
  valign="top"><TR valign="top"><TD rowspan="4" colspan="1"><PRE>                         ++x;
                         iter.nextPixel();
                     }
</PRE><TR valign="top"><TR valign="top"><TR valign="top"><TR valign="top"><TD 
  rowspan="5" colspan="1"><PRE>                     ++y;
                     iter.nextLine();
                     System.out.println();
                 }
</PRE><TR valign="top"><TR valign="top"><TR valign="top"><TR valign="top"><TR 
  valign="top"><TD rowspan="5" colspan="1"><PRE>                 ++b;
                 iter.nextBand();
             }
         }
     }
</PRE><TR valign="top"><TR valign="top"><TR valign="top"><TR valign="top">
  <HR>

  <P><A name=56033>
  <H2>14.5 <IMG src="Extending the API.files/space.gif">Writing New Image 
  Decoders and Encoders</H2></A>The <CODE>sample</CODE> directory contains an 
  example of how to create a new image codec. The example is of a PNM codec, but 
  can be used as a basis for creating any codec. The PNM codec consists of three 
  files:
  <P>
  <TABLE cellPadding=3 border=3>
    <CAPTION><FONT size=-1><B></B></FONT></CAPTION>
    <TBODY>
    <TR vAlign=top>
      <TH><A name=58309>File Name </A>
      <TH><A name=58311>Description </A>
    <TR vAlign=top>
      <TD><A name=58313>SamplePNMCodec.java</A><BR>
      <TD><A name=58315>Defines a subclass of ImageCodec for handling the PNM 
        family of image files.</A><BR>
    <TR vAlign=top>
      <TD><A name=58317>SamplePNMImageDecoder.java</A><BR>
      <TD><A name=58319>Defines an ImageDecoder for the PNM family of image 
        files. Necessary for reading PNM files.</A><BR>
    <TR vAlign=top>
      <TD><A name=58321>SamplePNMImageEncoder.java</A><BR>
      <TD><A name=58323>Defines an ImageEncoder for the PNM family of image 
        files. Necessary for writing PNM files.</A><BR></TR></TBODY></TABLE>
  <P><A name=51534>
  <H3>14.5.1 <IMG src="Extending the API.files/space.gif">Image Codecs</H3></A>
  <HR noShade>
  <B>Note:</B> The codec classes are provided for the developer as a convenience 
  for file IO. These classes are not part of the official Java Advanced Imaging 
  API and are subject to change as a result of the near future File IO extension 
  API. Until the File IO extension API is defined, these classes and functions 
  will be supported for JAI use. 
  <HR noShade>
  The <CODE>ImageCodec</CODE> class allows the creation of image decoders and 
  encoders. Instances of <CODE>ImageCodec</CODE> may be registered by name. The 
  <CODE>registerCodec</CODE> method associates an <CODE>ImageCodec</CODE> with 
  the given name. Any codec previously associated with the name is discarded. 
  Once a codec has been registered, the name associated with it may be used as 
  the <CODE>name</CODE> parameter in the <CODE>createImageEncoder</CODE> and 
  <CODE>createImageDecoder</CODE> methods. 
  <P>The <CODE>ImageCodec</CODE> class maintains a registry of 
  <CODE>FormatRecognizer</CODE> objects that examine an <CODE>InputStream</CODE> 
  and determine whether it adheres to the format handled by a particular 
  <CODE>ImageCodec</CODE>. A <CODE>FormatRecognizer</CODE> is added to the 
  registry with the <CODE>registerFormatRecognizer</CODE> method. The 
  unregisterFormatRecognizer method removes a previously registered 
  <CODE>FormatRecognizer</CODE> from the registry. 
  <P>The <CODE>getCodec</CODE> method returns the <CODE>ImageCodec</CODE> 
  associated with a given name. If no codec is registered with the given name, 
  <CODE>null</CODE> is returned.<CODE></CODE> 
  <P>
  <TABLE border=0>
    <TBODY>
    <TR>
      <TD><IMG src="Extending the API.files/cistine.gif"></TD>
      <TD>
        <HR>
        <B>API:</B> <CODE>com.sun.media.jai.codec.ImageCodec </CODE>
        <HR>
      </TD></TR></TBODY></TABLE><PRE><UL>
<LI>static ImageEncoder createImageEncoder(String name, 
       OutputStream dst, ImageEncodeParam param)
<P></P></LI></UL></PRE>
  <DL><A name=54386>
    <DT>
    <DD>returns an <CODE>ImageEncoder</CODE> object suitable for encoding to the 
    supplied <CODE>OutputStream</CODE>, using the supplied 
    <CODE>ImageEncodeParam</CODE> object.
    <P>
    <TABLE cellPadding=3 border=3>
      <CAPTION><FONT size=-1><B></B></FONT></CAPTION>
      <TBODY>
      <TR vAlign=top>
        <TD rowSpan=3><EM>Parameter</EM>:<EM></EM> 
          <P></P>
        <TD><CODE>name</CODE> 
          <P></P>
        <TD>The name associated with the codec. 
          <P></P>
      <TR vAlign=top>
        <TD><CODE>dst</CODE> 
          <P></P>
        <TD>An <CODE>OutputStream</CODE> to write to. 
          <P></P>
      <TR vAlign=top>
        <TD><CODE>param</CODE> 
          <P></P>
        <TD>An instance of ImageEncodeParam suitable for use with the named 
          codec, or null. 
          <P></P></TR></TBODY></TABLE></A>
    <P></P></DD></DL><PRE><UL>
<LI>static ImageEncoder createImageEncoder(String name, 
       OutputStream dst)
<P></P></LI></UL></PRE>
  <DL><A name=54450>
    <DT>
    <DD>returns an <CODE>ImageEncoder</CODE> object suitable for encoding to the 
    supplied <CODE>OutputStream</CODE> object. A null 
    <CODE>ImageEncodeParam</CODE> is used. </A>
    <P></P></DD></DL><PRE><UL>
<LI>static ImageDecoder createImageDecoder(String name, 
       InputStream  src, ImageDecodeParam param)
<P></P></LI></UL></PRE>
  <DL><A name=54475>
    <DT>
    <DD>returns an <CODE>ImageDecoder</CODE> object suitable for decoding from 
    the supplied <CODE>InputStream</CODE>, using the supplied 
    <CODE>ImageDecodeParam</CODE> object.
    <P>
    <TABLE cellPadding=3 border=3>
      <CAPTION><FONT size=-1><B></B></FONT></CAPTION>
      <TBODY>
      <TR vAlign=top>
        <TD rowSpan=3><EM>Parameter</EM>:<EM></EM> 
          <P></P>
        <TD><CODE>name</CODE> 
          <P></P>
        <TD>The name associated with the codec. 
          <P></P>
      <TR vAlign=top>
        <TD><CODE>src</CODE> 
          <P></P>
        <TD>An <CODE>InputStream</CODE> to read from. 
          <P></P>
      <TR vAlig

⌨️ 快捷键说明

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