强化JAVA图形操作类

                  不想再继续为汉语编程的问题浪费时间,印度的SKTN下场怎么样大家一目了然。
 
  而在我Blog发表评论的,只要是用人类语言,我都可以接受。就算有个别不用人类语言的,有空时我也会尽量帮那些生物往人类语言方向矫正。

  ——————————————————————————————

  我们都知道,微软对其原有GDI(Graphics Device Interface)改进后形成了现在的GDI+。作为图形设备接口GDI的继任者,其对GDI的很多功能都进行了优化,而且还提供了许多方便实用的附加功能。

  以此为基础,在.Net环境下可以很轻松的完成一系列复杂的图形操作。而与之相较,Java的图像接口在图像处理功能上则略显单薄,而部分操作较之C#等还有些复杂。

  所以最近我打算在本人的loonframework项目中将一些java图像接口二次封装,及添加部分新的功能进入。下面我公布的,是一些在Loonframework框架中将新添加的图像处理类。当然,这些还在测试阶段,最后的确定版估计会与此有较大出入,有改进意见的欢迎邮寄到我的Email:ceponline@yahoo.com.cn。(最近挺懒的……一写代码就犯困……下班只看漫画度日……)

BaseImage.java:
  
package  org.loon.framework.game.test.image;

import  java.awt.Image;

/** */ /**
 * <p>
 * Title: LoonFramework
 * </p>
 * <p>
 * Description:基础Bitmap接口
 * </p>
 * <p>
 * Copyright: Copyright (c) 2007
 * </p>
 * <p>
 * Company: LoonFramework
 * </p>
 * 
 * @author chenpeng
 * @email:ceponline@yahoo.com.cn
 * @version 0.1
 */

public   interface  BaseImage  ... {

    final static int BITMAPFILEHEADER_SIZE = 14;

    final static int BITMAPINFOHEADER_SIZE = 40;

    abstract int getWidth();

    abstract int getHeight();

    abstract LColor getPixel(int x, int y);

    /** *//**
     * 设定像素点
     * 
     * @param x
     * @param y
     * @param rgb
     * @return
     */

    abstract boolean setPixel(int x, int y, int rgb);

    abstract boolean setPixel(int x, int y, int r, int g, int b);

    abstract boolean setPixel(int x, int y, LColor color);

    /** *//**
     * 移动像素
     * 
     * @param dx
     * @param dy
     */

    abstract void movePixels(int dx, int dy);

    /** *//**
     * 清除像素
     * 
     * @param rgb
     */

    abstract void clear(int rgb);

    /** *//**
     * 获得LGraphics
     * 
     * @return
     */

    abstract LGraphics getLGraphics();

    abstract Image getImage();

    /** *//**
     * 设定指定x,y交集
     * 
     * @param x
     * @param y
     * @return
     */

    abstract boolean setTransparent(int x, int y);

    /** *//**
     * 设定指定color出现处
     * 
     * @param val
     */

    abstract void setTransparent(LColor color);

    /** *//**
     * 替换指定颜色
     * 
     * @param color1
     * @param color2
     */

    abstract void setDisplace(LColor color1, LColor color2);

    /** *//**
     * 保存自身到指定路径
     * 
     * @param path
     */

    abstract void save(String path);

    /** *//**
     * 保存图像到指定路径
     * 
     * @param image
     * @param path
     */

    abstract void save(Image image, String path);

    /** *//**
     * 保存图像到指定路径为指定大小
     * 
     * @param image
     * @param path
     * @param width
     * @param height
     */

    abstract void save(Image image, String path, int width, int height);

}


LColor.java:
package  org.loon.framework.game.test.image;
/** */ /**
 * <p>Title: LoonFramework</p>
 * <p>Description:loonframework用color</p>
 * <p>Copyright: Copyright (c) 2007</p>
 * <p>Company: LoonFramework</p>
 * @author chenpeng  
 * @email:ceponline@yahoo.com.cn 
 * @version 0.1
 */

public   class  LColor  ... {
    
    
    int R=0;
    int G=0;
    int B=0;
    
    public LColor()...{}
    
    /** *//**
     * 注入r,g,b数值
     * @param r
     * @param g
     * @param b
     */

    public LColor(int r,int g,int b)...{
        this.R=r;
        this.G=g;
        this.B=b;
    }

}

LGraphics:

package  org.loon.framework.game.test.image;

import  java.awt.Color;
import  java.awt.Font;
import  java.awt.FontMetrics;
import  java.awt.Graphics;
import  java.awt.Polygon;
import  java.awt.font.LineMetrics;

import  org.loon.framework.game.test.image.BaseImage;

/** */ /**
 * <p>Title: LoonFramework</p>
 * <p>Description:loonframework用graphics,开发中……</p>
 * <p>Copyright: Copyright (c) 2007</p>
 * <p>Company: LoonFramework</p>
 * @author chenpeng  
 * @email:ceponline@yahoo.com.cn 
 * @version 0.1
 */

public   class  LGraphics  ... {

    Graphics _g = null;

    Font _font;

    public LGraphics() ...{
        _font = new Font(null, Font.PLAIN, 12);
    }


    public LGraphics(Graphics g) ...{

        _font = new Font(null, Font.PLAIN, 12);

        setGraphics(g);

    }


    public void setGraphics(Graphics g) ...{

        _g = g;

        _g.setFont(_font);

    }


    public void setRGB(int rgb) ...{

        _g.setColor(new Color(rgb));

    }


    public void setRGB(int r, int g, int b) ...{

        int rgb = (r << 16) | (g << 8) | b;

        _g.setColor(new Color(rgb));

    }


    public void drawLine(int x1, int y1, int x2, int y2, int rgb) ...{

        setRGB(rgb);

        _g.drawLine(x1, y1, x2, y2);

    }


    public void drawRect(int x, int y, int width, int height) ...{
        _g.drawRect(x, y, width, height);
    }


    public void drawRect(int x, int y, int width, int height, int rgb) ...{

        setRGB(rgb);

        _g.drawRect(x, y, width, height);

    }


    public void fillRect(int x, int y, int width, int height) ...{
        _g.fillRect(x, y, width, height);
    }


    public void fillRect(int x, int y, int width, int height, int rgb) ...{

        setRGB(rgb);

        _g.fillRect(x, y, width, height);

    }


    public void fillTriangle(int x1, int y1, int x2, int y2, int x3, int y3) ...{

        if (_g == null) ...{
            return;
        }


        Polygon p = new Polygon();

        p.addPoint(x1, y1);
        p.addPoint(x2, y2);
        p.addPoint(x3, y3);

        _g.fillPolygon(p);

    }


    public void drawImage(BaseImage img, int x, int y) ...{
        _g.drawImage(img.getImage(), x, y, null);
    }


    public int getStringWidth(String str) ...{

        if (str == null || str.length() < 1) ...{
            return 0;
        }


        FontMetrics fm = _g.getFontMetrics();

        int w = 0;

        w = fm.stringWidth(str);

        return w;

    }


    public int getStringHeight(String str) ...{

        if (str == null ||
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值