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

📄 image.java

📁 用于移动设备上的java虚拟机源代码
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
     * @param x the x-coordinate of the upper left corner of the region     * @param y the y-coordinate of the upper left corner of the region     * @param width the width of the region     * @param height the height of the region     *     * @throws ArrayIndexOutOfBoundsException if the requested operation would     * attempt to access an element in the <code>rgbData</code> array     * whose index is either     * negative or beyond its length (the contents of the array are unchanged)     *     * @throws IllegalArgumentException if the area being retrieved     * exceeds the bounds of the source image     *     * @throws IllegalArgumentException if the absolute value of     * <code>scanlength</code> is less than <code>width</code>     *     * @throws NullPointerException if <code>rgbData</code> is <code>null</code>     *     * @since MIDP 2.0     */    public native void getRGB(int[] rgbData, int offset, int scanlength,                       int x, int y, int width, int height);    /**     * The width, height of this Image     */    int width, height;    /**     * Native image data     */    int imgData;        /**     * Valid transforms possible are 0 - 7     */    private static final int INVALID_TRANSFORM_BITS = 0xFFFFFFF8;}/** * A special mutable Image subclass */class MutableImage extends Image {    /**     * Create a new mutable Image     *     * @param width The width of the mutable Image     * @param height The height of the mutable Image     */    MutableImage(int width, int height) {        this.width = width;        this.height = height;        createMutableImage(width, height);    }    /**     * 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.     * @return <code>true</code> if the image is mutable,     * <code>false</code> otherwise     */    public boolean isMutable() {        // SYNC NOTE: return of atomic value, no locking necessary        return true;    }    /**     * 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     * {@link Font#getDefaultFont() Font.getDefaultFont()};</LI>     * <LI>the stroke style is {@link Graphics#SOLID SOLID}; 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>     *     * @return a <code>Graphics</code> object with this image as its destination     * @throws IllegalStateException if the image is immutable     */    public Graphics getGraphics() {        // SYNC NOTE: no locking necessary as getGraphics() only allocates        // a new object        return Graphics.getGraphics(this);    }    /**     * Create a mutable image     *     * @param width The width of the new mutable image     * @param height The height of the new mutable image     */    private native void createMutableImage(int width, int height);    /**     * Cleanup any native resources used by a MutableImage     */    private native void finalize();}/** * A special immutable Image subclass */class ImmutableImage extends Image {    /**     * Construct an empty immutable image.     */    private ImmutableImage() {    }    /**     * Create a new immutable Image with the given Image     *     * @param img The Image to use to create an immutable copy     */    ImmutableImage(Image img) {        this.width   = img.width;        this.height  = img.height;        createImmutableCopy(width, height, img);    }    /**     * Create a new immutable Image with the region of the given Image     * applying the given transform     *     * @param img The Image to use to create an immutable copy     * @param x   The x-offset of the top-left of the region     * @param y   The y-offset of the top-left of the region     * @param width The width of the region     * @param height The height of the region     * @param transform The transform to apply to the region     */    ImmutableImage(Image img,		   int x, int y, 		   int width, int height,		   int transform) {	if ((transform & INVERTED_AXES) != 0x0) {	    this.width = height;	    this.height = width;	} else {	    this.width = width;	    this.height = height;	}	createImmutableImageRegion(img, x, y, width, height, transform);    }    /**     * Create an immutable Image with the given byte data     *     * @param imageData The byte[] image data     * @param imageOffset The offset in the array marking the start     *                    of the image data     * @param imageLength The length of the image data in the array     */    ImmutableImage(byte[] imageData, int imageOffset, int imageLength) {        decodeImage(imageData, imageOffset, imageLength);    }    /**     * Create an immutable Image with the given rgb data     *     * @param rgbImageData an array of ARGB values that composes      *                     the image.     * @param width the width of the image     * @param height the height of the image     * @param parseAlpha true if rgb has an alpha channel,     *                   false if all pixels are fully opaque     */    ImmutableImage(int[] rgbImageData, int width, int height, 		   boolean parseAlpha) {        decodeRGBImage(rgbImageData, width, height, parseAlpha);    }    /**     * Create an immutable Image from the given file name     *     * @param str   A String holding a file name to load the image data from     * @throws IOException if there is an error with the stream     */    ImmutableImage(String str) throws java.io.IOException {        /*	 * allocate an array and read in the bits using	 * Class.getResourceAsStream(name);	 */        InputStream is = null;        is = getClass().getResourceAsStream(str);		getImageFromStream(is);    }        /**     * Create an immutable Image from the given IO stream     *     * @param stream the name of the resource containing the image data     *               in one of the supported image formats     * @throws IOException if there is an error with the stream     */    ImmutableImage(InputStream stream) throws java.io.IOException {	getImageFromStream(stream);    }    /**     * helper function called by the constructors above      *      * @param istream the name of the input stream containing image     *                data in a supported format     * @throws IOException if there is an error with the stream     */    private void getImageFromStream(InputStream istream) 	throws java.io.IOException {        int blocksize = 4096; // the size of blocks to read and allocate	        if (istream == null) {            throw new java.io.IOException();        } else {	    /*	     * Allocate an array assuming available is correct.	     * Only reading an EOF is the real end of file	     * so allocate an extra byte to read the EOF into.	     * If available is incorrect, increase the buffer	     * size and keep reading.	     */            int l = istream.available();            byte[] buffer = new byte[l+1];            int length = 0;            // TBD: Guard against an implementation with incorrect available            while ((l = istream.read(buffer, length, 				     buffer.length-length)) != -1) {                length += l;                if (length == buffer.length) {                    byte[] b = new byte[buffer.length + blocksize];                    System.arraycopy(buffer, 0, b, 0, length);                    buffer = b;                }            }            decodeImage(buffer, 0, length);	                istream.close();        }    }    /**     * Create an ImmutableImage from the named system icon resource.     * The icons are stored in the $MIDP_HOME/lib directory.     * If the named resource can not be found a placeholder     * image is used instead.     * @param imageName name of the image     * @return a new ImmutableImage     * @throws IllegalArgumentException if imageName contains a "/" or "\\"     */    static Image createIcon(String imageName) {	if ((imageName.indexOf('/') >= 0) ||	    (imageName.indexOf('\\') >= 0)) {	    throw new IllegalArgumentException("illegal character");	}	ImmutableImage image = new ImmutableImage();	byte[] asciiName = com.sun.midp.io.Util.toCString(imageName);	image.loadIcon(asciiName);	return image;    }    /**     * Native function to create an immutable copy of an image     *     * @param width The width of the new Image     * @param height The height of the new Image     * @param img The Image to make a copy of     */    private native void createImmutableCopy(int width, int height, Image img);    /**     * Native function that creates an immutable image from      * a region of another image, applying the given transform     *     * @param img The Image to make a copy of     * @param x The horizontal offset of the top left of the region to copy     * @param y The vertical offset of the top left of the region to copy     * @param width The width of the new Image     * @param height The height of the new Image     * @param transform The transformation to apply     *     * @since MIDP 2.0     */    private native void createImmutableImageRegion(Image img,                                                    int width, int height,                                                    int x, int y,                                                   int transform);					         /**     * Native function to decode an Image from a byte array     *     * @param inputData The byte array image data     * @param offset The start of the image data within the byte array     * @param length The length of the image data in the byte array     */    private native void decodeImage(byte[] inputData, int offset, int length);    /**     * Native function to load an Image from a system resource.     * If the resource cannot be found a place holder image is     * returned instead of the requested image.     *     * @param asciiName name of the image as an ascii byte array     */    private native void loadIcon(byte[] asciiName);    /**     * Cleanup any native resources used by an ImmutableImage     */    private native void finalize();    /**     * Native function to decode an Image from an array of RGB data     *     * @param inputData an array of ARGB values that composes      *                  the image.     * @param width the width of the image     * @param height the height of the image     * @param processAlpha true if rgb has an alpha channel,     *                     false if all pixels are fully opaque     */    private native void decodeRGBImage(int[] inputData, int width, 				       int height, boolean processAlpha);    /**     * A constant to denote that axes are inverted in a transform     */    private static final int INVERTED_AXES = 0x4;}

⌨️ 快捷键说明

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