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

📄 bqimage.java

📁 J2me唆哈的代码
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
            BufferedImage bufImg2 = new BufferedImage(height, width, bufImg
                    .getType());
            for (int j = 0; j < height; j++)
                for (int i = 0; i < width; i++)
                    bufImg2.setRGB(j, width - 1 - i, bufImg.getRGB(i, j));
            bufImg = null;
            return new BQImage(bufImg2);
        } else if (transform == Sprite.TRANS_MIRROR_ROT90)// ���Ҿ���Ȼ��˳ʱ��ѡ��90��
        {
            BufferedImage bufImg2 = new BufferedImage(height, width, bufImg
                    .getType());
            for (int j = 0; j < height; j++)
                for (int i = 0; i < width; i++)
                    bufImg2.setRGB(height - 1 - j, width - 1 - i, bufImg
                            .getRGB(i, j));
            bufImg = null;
            return new BQImage(bufImg2);
        } else if (transform == Sprite.TRANS_MIRROR_ROT270)// ���Ҿ���Ȼ��˳ʱ��ѡ��270��
        {
            BufferedImage bufImg2 = new BufferedImage(height, width, bufImg
                    .getType());
            for (int j = 0; j < height; j++)
                for (int i = 0; i < width; i++)
                    bufImg2.setRGB(j, i, bufImg.getRGB(i, j));
            bufImg = null;
            return new BQImage(bufImg2);
        }
        return null;
    }

    /**
     * ��istream���д���һ��ɸı��image
     * 
     * @param istream
     *            ��ij�ֿ��Ա�����ĸ�ʽ����ݵ���
     * @return ���istream�е����?������4�IJ��ɱ��Image����
     * @throws IOException
     *             �������?�׳�
     * @since MIDP1.0
     */
    public static BQImage createImage(InputStream istream) throws IOException {
        try {
            if (istream == null) {
                throw new java.io.IOException();
            } else {
                /*
                 * ���blocksize��֪����4��ʲô��,2.0��Դ����������4��, Ӧ�ÿ���ɾ��
                 */
                int blocksize = 4096;
                int l = istream.available();
                byte[] buffer = new byte[l + 1];
                int length = 0;

                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;
                    }
                }
                istream.close();
                return createImage(buffer, 0, length);
            }
        } catch (IOException e) {
            throw e;
        }catch(Exception e){
            throw new IOException();
        }
    }

    /**
     * ����һ��ɸı��image����
     * 
     * @param width
     *            ������iamge�Ŀ��?     * @param height
     *            ������iamge�ĸ߶�
     * @return ������4�Ŀɱ��Image����
     * @since MIDP1.0
     */
    public static BQImage createImage(int width, int height) {
        if (width <= 0 || height <= 0) {
            throw new IllegalArgumentException();
        }
        java.awt.Image img = new BufferedImage(width, height,
                BufferedImage.TYPE_INT_ARGB);

        BQImage ret = new BQImage(img);
        ret.setMutable(true);

        return ret;
    }

    /**
     * ��nameָ�����ļ��д���һ��image
     * 
     * @param name
     *            ���
     * @return ���ļ��д�����4�IJ��ɱ��Image����
     * @throws java.io.IOException
     *             �������?�׳�
     * @since MIDP1.0
     */
    public static BQImage createImage(String name) throws java.io.IOException {

    	BQImage image=EmulatorFrame.instance.createImage(name);
    	if(image==null){
    		String path=System.getProperty("java.class.path");
            
            int idx1=0;
            int idx2=path.indexOf(';',idx1);
            String pre=null;
            while(idx2>0){
                pre=path.substring(idx1,idx2);
                if(pre.endsWith(".jar")){
                    image=createImageFromJar(pre,name);
                }else{
                    image=createImageWidthFullPath(pre+name);
                }
                if(image!=null){
                    return image;
                }
                idx1=idx2+1;
                idx2=path.indexOf(';',idx1);
            }
            pre=path.substring(idx1);
            if(pre.endsWith(".jar")){
                image=createImageFromJar(pre,name);
            }else{
                image=createImageWidthFullPath(pre+name);
            }
    	}
        if(image!=null){
            return image;
        }else{
            throw new IOException();
        }
    	
    }
    
    
    private static BQImage createImageFromJar(String jarFile,String name){
        BQImage image=null;
        try{
            JarFile jar=new JarFile(jarFile);
            String eName=name;
            eName.trim();
            while(eName.startsWith("/")){
                eName=eName.substring(1);
            }
            ZipEntry zp=jar.getEntry(eName);
            if(zp!=null){
                image=createImage(jar.getInputStream(zp));
            }
            jar.close();
        }catch(IOException e){
            
        }
        return image;
    }
    
    private static BQImage createImageWidthFullPath(String path){
    	BQImage img=null;
    	try{
    		FileInputStream fis=new FileInputStream(new File(path));
    		img=createImage(fis);
    	}catch(IOException e){
    		
    	}
    	return img;
    		
    }

    public static BQImage createRGBImage(int[] rgb,
            int width,
            int height,
            boolean processAlpha){
    	BufferedImage img;
    	if(processAlpha){
    		img=new BufferedImage(width,height,BufferedImage.TYPE_INT_ARGB);
    	}else{
    		img=new BufferedImage(width,height,BufferedImage.TYPE_INT_RGB);
    	}
    	img.setRGB(0,0,width,height,rgb,0,width);
    	return new BQImage(img);
    }    
    
    /**
     * ����image�ǿɸı��?�õ����������image�ϻ�ͼ��Graphics �����׳��쳣
     * 
     * @since MIDP1.0
     */
    public BQGraphics getGraphics() {
    	BQGraphics g = new BQGraphics(instance.getGraphics());
        g.setSource(this);
        g.setLimit(width, height);
        g.setIsDisplayContents(false);
        
        if (this.isMutable()) {
        	return g;    
        } else{
            //throw new IllegalStateException();
        	System.out.println("getGraphics called at a immutable Image");
        	return g;
        }
    }

    /**
     * �õ���Image����ĸ�?     * 
     * @return ��Image����ĸ�?     * @since MIDP1.0
     */
    public int getHeight() {
        return height;
    }

    /**
     * �õ���Image����Ŀ�?     * 
     * @return ��Image����Ŀ�?     * @since MIDP1.0
     */
    public int getWidth() {
        return width;
    }

    public void getRGB(int[] rgbData, int offset, int scanlength, 
    		int x, int y, int w, int h){
    	if(x+w>this.width||y+h>this.height){
    		throw new IllegalArgumentException("region error");
    	}else if(scanlength<w){
    		throw new IllegalArgumentException("scanlength must not less than width");
    	}
    	BufferedImage img=new BufferedImage(w,h,BufferedImage.TYPE_INT_ARGB);
    	img.getGraphics().drawImage(instance,-x,-y,null);
    	img.getRGB(0,0,w,h,rgbData,offset,scanlength);
    	img=null;
    }
    
    /**
     * �жϸ�image�Ƿ��ǿ��������滭ͼ�� ���Ƿ�ɸı��
     */
    public boolean isMutable() {
        return isMutable;
    }

    /**
     * ���µIJ���Image����ɼ�ĺ���
     * ֮������public,����Ϊcom.nokia.mid.ui.DirectUtils��createImage��Ҫ�õ�
     */
    public void setMutable(boolean mutable) {
        isMutable = mutable;
    }

    /**
     * �õ����������õ�java.awt.Image���� �����⿪�ŵĽӿ�
     * 
     * @return ���������õ�java.awt.Image����
     */
    public java.awt.Image getTrueImage() {
        return instance;
    }
    
    public void setShell(Image img){
    	shell=img;
    }
    
    public Image getShell(){
    	return shell;
    }

}

⌨️ 快捷键说明

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