📄 image.html
字号:
<A NAME="createImage(javax.microedition.lcdui.Image)"><!-- --></A><H3>
createImage</H3>
<PRE>
public static <A HREF="../../../javax/microedition/lcdui/Image.html">Image</A> <B>createImage</B>(<A HREF="../../../javax/microedition/lcdui/Image.html">Image</A> source)</PRE>
<DL>
<DD>Creates an immutable image from a source image. If the source image is mutable, an immutable copy is created and returned. If the source image is immutable, the implementation may simply return it without creating a new image. If an immutable source image contains transparency information, this information is copied to the new image unchanged. <p> This method is useful for placing the contents of mutable images into <code>Choice</code> objects. The application can create an off-screen image using the <A HREF="../../../javax/microedition/lcdui/Image.html#createImage(int, int)"><CODE>createImage(w, h)</CODE></A> method, draw into it using a <code>Graphics</code> object obtained with the <A HREF="../../../javax/microedition/lcdui/Image.html#getGraphics()"><CODE>getGraphics()</CODE></A> method, and then create an immutable copy of it with this method. The immutable copy may then be placed into <code>Choice</code> objects. </p><DD><DL>
<DT><B>Parameters:</B><DD><CODE>source</CODE> - the source image to be copied<DT><B>Returns:</B><DD>the new, immutable image<DT><B>Throws:</B><DD><CODE><A HREF="../../../java/lang/NullPointerException.html">NullPointerException</A></CODE> - if <code>source</code> is <code>null</code></DL>
</DD>
</DL>
<HR>
<A NAME="createImage(java.lang.String)"><!-- --></A><H3>
createImage</H3>
<PRE>
public static <A HREF="../../../javax/microedition/lcdui/Image.html">Image</A> <B>createImage</B>(<A HREF="../../../java/lang/String.html">String</A> name) throws <A HREF="../../../java/io/IOException.html">IOException</A></PRE>
<DL>
<DD>Creates an immutable image from decoded image data obtained from the named resource. The name parameter is a resource name as defined by <A HREF="../../../java/lang/Class.html#getResourceAsStream(java.lang.String)"><CODE>Class.getResourceAsStream(name)</CODE></A>. The rules for resolving resource names are defined in the <a href="../../../java/lang/package-summary.html"> Application Resource Files</a> section of the <code>java.lang</code> package documentation.<DD><DL>
<DT><B>Parameters:</B><DD><CODE>name</CODE> - the name of the resource containing the image data in one of the supported image formats<DT><B>Returns:</B><DD>the created image<DT><B>Throws:</B><DD><CODE><A HREF="../../../java/lang/NullPointerException.html">NullPointerException</A></CODE> - if <code>name</code> is <code>null</code><DD><CODE><A HREF="../../../java/io/IOException.html">IOException</A></CODE> - if the resource does not exist, the data cannot be loaded, or the image data cannot be decoded</DL>
</DD>
</DL>
<HR>
<A NAME="createImage(byte[], int, int)"><!-- --></A><H3>
createImage</H3>
<PRE>
public static <A HREF="../../../javax/microedition/lcdui/Image.html">Image</A> <B>createImage</B>(byte[] imageData, int imageOffset, int imageLength)</PRE>
<DL>
<DD>Creates an immutable image which is decoded from the data stored in the specified byte array at the specified offset and length. The data must be in a self-identifying image file format supported by the implementation, such as <a href="#PNG">PNG</A>. <p>The <code>imageoffset</code> and <code>imagelength</code> parameters specify a range of data within the <code>imageData</code> byte array. The <code>imageOffset</code> parameter specifies the offset into the array of the first data byte to be used. It must therefore lie within the range <code>[0..(imageData.length-1)]</code>. The <code>imageLength</code> parameter specifies the number of data bytes to be used. It must be a positive integer and it must not cause the range to extend beyond the end of the array. That is, it must be true that <code>imageOffset + imageLength < imageData.length</code>. </p> <p> This method is intended for use when loading an image from a variety of sources, such as from persistent storage or from the network.</p><DD><DL>
<DT><B>Parameters:</B><DD><CODE>imageData</CODE> - the array of image data in a supported image format<DD><CODE>imageOffset</CODE> - the offset of the start of the data in the array<DD><CODE>imageLength</CODE> - the length of the data in the array<DT><B>Returns:</B><DD>the created image<DT><B>Throws:</B><DD><CODE><A HREF="../../../java/lang/ArrayIndexOutOfBoundsException.html">ArrayIndexOutOfBoundsException</A></CODE> - if <code>imageOffset</code> and <code>imageLength</code> specify an invalid range<DD><CODE><A HREF="../../../java/lang/NullPointerException.html">NullPointerException</A></CODE> - if <code>imageData</code> is <code>null</code><DD><CODE><A HREF="../../../java/lang/IllegalArgumentException.html">IllegalArgumentException</A></CODE> - if <code>imageData</code> is incorrectly formatted or otherwise cannot be decoded</DL>
</DD>
</DL>
<HR>
<A NAME="createImage(javax.microedition.lcdui.Image, int, int, int, int, int)"><!-- --></A><H3>
createImage</H3>
<PRE>
public static <A HREF="../../../javax/microedition/lcdui/Image.html">Image</A> <B>createImage</B>(<A HREF="../../../javax/microedition/lcdui/Image.html">Image</A> image, int x, int y, int width, int height, int transform)</PRE>
<DL>
<DD>Creates an immutable image using pixel data from the specified region of a source image, transformed as specified. <p>The source image may be mutable or immutable. For immutable source images, transparency information, if any, is copied to the new image unchanged.</p> <p>On some devices, pre-transformed images may render more quickly than images that are transformed on the fly using <code>drawRegion</code>. However, creating such images does consume additional heap space, so this technique should be applied only to images whose rendering speed is critical.</p> <p>The transform function used must be one of the following, as defined in the <A HREF="../../../javax/microedition/lcdui/game/Sprite.html"><CODE>Sprite</CODE></A> class:<br> <code>Sprite.TRANS_NONE</code> - causes the specified image region to be copied unchanged<br> <code>Sprite.TRANS_ROT90</code> - causes the specified image region to be rotated clockwise by 90 degrees.<br> <code>Sprite.TRANS_ROT180</code> - causes the specified image region to be rotated clockwise by 180 degrees.<br> <code>Sprite.TRANS_ROT270</code> - causes the specified image region to be rotated clockwise by 270 degrees.<br> <code>Sprite.TRANS_MIRROR</code> - causes the specified image region to be reflected about its vertical center.<br> <code>Sprite.TRANS_MIRROR_ROT90</code> - causes the specified image region to be reflected about its vertical center and then rotated clockwise by 90 degrees.<br> <code>Sprite.TRANS_MIRROR_ROT180</code> - causes the specified image region to be reflected about its vertical center and then rotated clockwise by 180 degrees.<br> <code>Sprite.TRANS_MIRROR_ROT270</code> - causes the specified image region to be reflected about its vertical center and then rotated clockwise by 270 degrees.<br></p> <p> The size of the returned image will be the size of the specified region with the transform applied. For example, if the region is <code>100 x 50</code> pixels and the transform is <code>TRANS_ROT90</code>, the returned image will be <code>50 x 100</code> pixels.</p> <p><strong>Note:</strong> If all of the following conditions are met, this method may simply return the source <code>Image</code> without creating a new one:</p> <ul> <li>the source image is immutable;</li> <li>the region represents the entire source image; and</li> <li>the transform is <code>TRANS_NONE</code>.</li> </ul><DD><DL>
<DT><B>Parameters:</B><DD><CODE>image</CODE> - the source image to be copied from<DD><CODE>x</CODE> - the horizontal location of the region to be copied<DD><CODE>y</CODE> - the vertical location of the region to be copied<DD><CODE>width</CODE> - the width of the region to be copied<DD><CODE>height</CODE> - the height of the region to be copied<DD><CODE>transform</CODE> - the transform to be applied to the region<DT><B>Returns:</B><DD>the new, immutable image<DT><B>Throws:</B><DD><CODE><A HREF="../../../java/lang/NullPointerException.html">NullPointerException</A></CODE> - if <code>image</code> is <code>null</code><DD><CODE><A HREF="../../../java/lang/IllegalArgumentException.html">IllegalArgumentException</A></CODE> - if the region to be copied exceeds the bounds of the source image<DD><CODE><A HREF="../../../java/lang/IllegalArgumentException.html">IllegalArgumentException</A></CODE> - if either <code>width</code> or <code>height</code> is zero or less<DD><CODE><A HREF="../../../java/lang/IllegalArgumentException.html">IllegalArgumentException</A></CODE> - if the <code>transform</code> is not valid<DT><B>Since: </B><DD>MIDP 2.0</DD>
</DL>
</DD>
</DL>
<HR>
<A NAME="getGraphics()"><!-- --></A><H3>
getGraphics</H3>
<PRE>
public <A HREF="../../../javax/microedition/lcdui/Graphics.html">Graphics</A> <B>getGraphics</B>()</PRE>
<DL>
<DD>Creates a new <code>Graphics</code> object that renders to this image. This image must be mutable; it is illegal to call this method on an immutable image. The mutability of an image may be tested with the <code>isMutable()</code> method. <P>The newly created <code>Graphics</code> object has the following properties: </P> <UL> <LI>the destination is this <code>Image</code> object;</LI> <LI>the clip region encompasses the entire <code>Image</code>;</LI> <LI>the current color is black;</LI> <LI>the font is the same as the font returned by <A HREF="../../../javax/microedition/lcdui/Font.html#getDefaultFont()"><CODE>Font.getDefaultFont()</CODE></A>;</LI> <LI>the stroke style is <A HREF="../../../javax/microedition/lcdui/Graphics.html#SOLID"><CODE>SOLID</CODE></A>; and </LI> <LI>the origin of the coordinate system is located at the upper-left corner of the Image.</LI> </UL> <P>The lifetime of <code>Graphics</code> objects created using this method is indefinite. They may be used at any time, by any thread.</P><DD><DL>
<DT><B>Returns:</B><DD>a <code>Graphics</code> object with this image as its destination<DT><B>Throws:</B><DD><CODE><A HREF="../../../java/lang/IllegalStateException.html">IllegalStateException</A></CODE> - if the image is immutable</DL>
</DD>
</DL>
<HR>
<A NAME="getWidth()"><!-- --></A><H3>
getWidth</H3>
<PRE>
public int <B>getWidth</B>()</PRE>
<DL>
<DD>Gets the width of the image in pixels. The value returned must reflect the actual width of the image when rendered.<DD><DL>
<DT><B>Returns:</B><DD>width of the image</DL>
</DD>
</DL>
<HR>
<A NAME="getHeight()"><!-- --></A><H3>
getHeight</H3>
<PRE>
public int <B>getHeight</B>()</PRE>
<DL>
<DD>Gets the height of the image in pixels. The value returned must reflect the actual height of the image when rendered.<DD><DL>
<DT><B>Returns:</B><DD>height of the image</DL>
</DD>
</DL>
<HR>
<A NAME="isMutable()"><!-- --></A><H3>
isMutable</H3>
<PRE>
public boolean <B>isMutable</B>()</PRE>
<DL>
<DD>Check if this image is mutable. Mutable images can be modified by rendering to them through a <code>Graphics</code> object obtained from the <code>getGraphics()</code> method of this object.<DD><DL>
<DT><B>Returns:</B><DD><code>true</code> if the image is mutable, <code>false</code> otherwise</DL>
</DD>
</DL>
<HR>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -