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

📄 directgraphicsimpl.java

📁 J2me唆哈的代码
💻 JAVA
字号:
/*
 * Created on 2005-8-8 by pcy
 *
 * TODO To change the template for this generated file go to
 * Window - Preferences - Java - Code Style - Code Templates
 */
package com.nokia.mid.ui;


import java.awt.image.BufferedImage;
import javax.microedition.lcdui.*;
import javax.microedition.lcdui.game.*;

import a.a.a.midp.lcdui.*;

/**
 * @author pcy
 *
 * TODO To change the template for this generated type comment go to
 * Window - Preferences - Java - Code Style - Code Templates
 */
class DirectGraphicsImpl implements DirectGraphics {


    public Graphics instance=null;
    

    public DirectGraphicsImpl(Graphics g) {
        super();
        instance = g;
    }
    

    public void setARGBColor(int argbColor) {
        instance.setColor(argbColor);
    }

    public void drawImage(javax.microedition.lcdui.Image img, int x, int y,
            int anchor, int manipulation) {
       
    	int trans=0;
        if (manipulation == 0) {
        	trans=Sprite.TRANS_NONE;
            
        }else{
        	if (manipulation == ROTATE_90) {
                trans=Sprite.TRANS_ROT270;
            } else if (manipulation == ROTATE_180) {
            	trans=Sprite.TRANS_ROT180;
            } else if (manipulation == ROTATE_270) {
            	trans=Sprite.TRANS_ROT90;
            } else if (manipulation == FLIP_HORIZONTAL) {
            	trans=Sprite.TRANS_MIRROR;
            } else if (manipulation == FLIP_VERTICAL) {
            	trans=Sprite.TRANS_MIRROR_ROT180;
            }else if (manipulation == (FLIP_HORIZONTAL|FLIP_VERTICAL)){
            	trans=Sprite.TRANS_ROT180;
            }else if(manipulation == (FLIP_HORIZONTAL|ROTATE_90)){
            	trans=Sprite.TRANS_MIRROR_ROT270;
            }else if(manipulation == (FLIP_HORIZONTAL|ROTATE_180)){
            	trans=Sprite.TRANS_MIRROR_ROT180;
            }else if(manipulation == (FLIP_HORIZONTAL|ROTATE_270)){
            	trans=Sprite.TRANS_MIRROR_ROT90;
            }else if(manipulation == (FLIP_VERTICAL|ROTATE_90)){
            	trans=Sprite.TRANS_MIRROR_ROT90;
            }else if(manipulation == (FLIP_VERTICAL|ROTATE_180)){
            	trans=Sprite.TRANS_MIRROR;
            }else if(manipulation == (FLIP_VERTICAL|ROTATE_270)){
            	trans=Sprite.TRANS_MIRROR_ROT270;
            }else{
            	throw new java.lang.IllegalArgumentException();
            }
        }
        instance.drawRegion(img,0,0,img.getWidth(),img.getHeight(),trans,x,y,anchor);
            
    }

    public void drawTriangle(int x1, int y1, int x2, int y2, int x3, int y3,
            int argbColor) {
        
        int orColor = instance.getColor();
        instance.setColor(argbColor);
        instance.drawLine(x1, y1, x2, y2);
        instance.drawLine(x1, y1, x3, y3);
        instance.drawLine(x2, y2, x3, y3);
        instance.setColor(orColor);
    }

    public void fillTriangle(int x1, int y1, int x2, int y2, int x3, int y3,
            int argbColor) {
        instance.getBQGraphics().fillTriangle(x1,y1,x2,y2,x3,y3,argbColor);
    }

    public void drawPolygon(int[] xPoints, int xOffset, int[] yPoints,
            int yOffset, int nPoints, int argbColor) {
        instance.getBQGraphics().drawPolygon(xPoints,xOffset,yPoints,yOffset,nPoints,argbColor);
    }

    public void fillPolygon(int[] xPoints, int xOffset, int[] yPoints,
            int yOffset, int nPoints, int argbColor) {

        instance.getBQGraphics().fillPolygon(xPoints,xOffset,yPoints,yOffset,nPoints,argbColor);
    }

    public void drawPixels(int[] pixels, boolean transparency, int offset,
            int scanlength, int x, int y, int width, int height,
            int manipulation, int format) {

        BufferedImage buf=null;
        if(transparency){
            buf=new BufferedImage(width,height,BufferedImage.TYPE_INT_ARGB);
        }else{
            buf=new BufferedImage(width,height,BufferedImage.TYPE_INT_RGB);
        }
        buf.setRGB(0,0,width,height,pixels,offset,scanlength);
        drawImage(new Image(new BQImage(buf)),x,y,Graphics.LEFT|Graphics.TOP,manipulation);
    }

    public void drawPixels(byte[] pixels, byte[] transparencyMask, int offset,
            int scanlength, int x, int y, int width, int height,
            int manipulation, int format) {
    	/*BufferedImage buf=null;
        if(transparency){
            buf=new BufferedImage(width,height,BufferedImage.TYPE_INT_ARGB);
        }else{
            buf=new BufferedImage(width,height,BufferedImage.TYPE_INT_RGB);
        }
        buf.setRGB(0,0,width,height,pixels,offset,scanlength);
        drawImage(new Image(new BQImage(buf)),x,y,Graphics.LEFT|Graphics.TOP,manipulation);
        */
    	System.out.println("temp");
    }

    public void drawPixels(short[] pixels, boolean transparency, int offset,
            int scanlength, int x, int y, int width, int height,
            int manipulation, int format) {

        BufferedImage buf=new BufferedImage(width,height,BufferedImage.TYPE_INT_ARGB);
        int temp=0;
        int temp2=0;
        for(int i=0;i<height;i++){
            for(int j=0;j<width;j++){
                temp=0;
                for(int k=0;k<4;k++){
                    temp2=(pixels[offset+i*scanlength+j]>>(k<<2))&15;
                    temp2=temp2<<4;
                    temp|=(temp2<<(k<<3));
                }
                buf.setRGB(j,i,temp);
            }
        }

        drawImage(new Image(new BQImage(buf)),x,y,Graphics.LEFT|Graphics.TOP,manipulation);
    }

    public void getPixels(int[] pixels, int offset, int scanlength, int x,
            int y, int width, int height, int format) {
        
        BufferedImage buf=new BufferedImage(width,height,BufferedImage.TYPE_INT_ARGB);
        BQImage img=new BQImage(buf);
        BQGraphics g=img.getGraphics();
        g.drawImage(instance.getSource(),-x,-y,Graphics.LEFT|Graphics.TOP);
        buf.getRGB(0,0,width,height,pixels,offset,scanlength);
        buf=null;
    }

    public void getPixels(byte[] pixels, byte[] transparencyMask, int offset,
            int scanlength, int x, int y, int width, int height, int format) {
    	System.out.println("temp2");
    }

    public void getPixels(short[] pixels, int offset, int scanlength, int x,
            int y, int width, int height, int format) {
        BufferedImage buf=new BufferedImage(width,height,BufferedImage.TYPE_INT_ARGB);
        BQImage tp=new BQImage(buf);
        tp.setMutable(true);
        BQGraphics g=tp.getGraphics();
        g.drawImage(instance.getSource(),-x,-y,Graphics.LEFT|Graphics.TOP);
        int temp=0;
        int temp2=0;
        for(int i=0;i<height;i++){
            for(int j=0;j<width;j++){
                temp=buf.getRGB(j,i);
                temp2=0;
                for(int k=0;k<4;k++){
                    temp2=(temp>>(k<<3))&255;
                    temp2=temp2>>4;
                    pixels[offset+i*scanlength+j]|=(short)(temp2<<(k<<2));
                }
            }
        }
    }

    public int getNativePixelFormat() {
     
        return TYPE_INT_8888_ARGB;
    }

    public int getAlphaComponent() {
        
        return 0;
    }
}

⌨️ 快捷键说明

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