`
7090
  • 浏览: 274055 次
  • 性别: Icon_minigender_1
  • 来自: 北京
社区版块
存档分类
最新评论

Graphics 的translate(int x, int y) 函数

    博客分类:
  • J2me
UI 
阅读更多

以前没有使用过translate(int x, int y)函数,新项目使用后,明白了使用原理

translate(int x, int y)
          Translates the origin of the graphics context to the point (x, y) in the current coordinate system.

就是把绘制区的x,y点坐标定义为坐标系的原点

比如之前绘制  

g.drawImage(img,x,y,0);

等价于

g.translate(x,y);

g.drawImage(img,0,0,0);

转变之后其他对Graphics的操作,也依赖于新的坐标系

比如

g.setClip(x,y,w,h);

等价于

g.translate(x,y);

g.setClip(0,0,w,h);

因此

g.setClip(x,y,w,h);

g.drawImage(img,x,y,0);

等价于

g.translate(x,y);

g.setClip(0,0,w,h);

g.drawImage(img,0,0,0);

 

基于translate函数的作用,就可以把Grphics绘制的一些功能,交给别人去做,提供一些方法或者接口,快速开发UI,

比如可以建立一个setX,setY之类的函数,对translate函数的参数进行操作,从而影响到Graphis的绘制位置及绘制区域,不过记得在使用完毕后,translate回来,使坐标系回归正常

 

 

分享到:
评论
2 楼 zhang_shuai870717 2016-01-06  
求指教。没懂
1 楼 刘亮love小雪 2015-04-23  
楼主我还是没有懂啊

相关推荐

    画图_j2se项目源码及介绍

    函数原型 getSubimage(int x, int y, int w, int h) 函数说明 根据指定的坐标和大小,获取图标。 函数原型 hasNextImage() 函数说明 是否还能取得下一个图标。 函数原型 setStartPosition(int x, int y) 函数...

    计算机图形学代码PixelWindow

    public int code(float x,float y){ int c=0; if(x) c=c|1;// 在左边,第四位为一 else if(x>xR) c=c|2;//在右边,第二位为一 if(y)c=c|4;//在下边,第三位为一 else if(y>yT) c=c|8;//在上边,第四位为...

    计算机图形学画圆代码

    void CirclePoints(int x,int y,int x0,int y0,int color) { putpixel(x+x0,y+ y0,color); putpixel(y+x0,x+y0,color); putpixel(-x+x0,y+y0,color); putpixel(y+x0,-x+y0,color); putpixel(x+x0,-y+y0,color);...

    openGL graphics with x window system

    openGL graphics with x window system

    C语言图形函数库总结graphics.h[参照].pdf

    C语言图形函数库总结graphics.h[参照].pdf

    贪吃蛇程序 c语言 可以运行正确

    此程序为一个c语言贪吃蛇 源代码 #define N 200 ... int x; int y; int yes; }food; struct Snake { int x[N]; int y[N]; int node; int direction; int life; ......下载 可查看完整的程序

    五子棋tc2.0算法

    一、黑白棋 /*3.3.4 源程序,黑白棋*/ ...int QpChange(int x,int y,int z);/*判断棋盘的变化*/ void DoScore(void);/*处理分数*/ void PrintScore(int n);/*输出成绩*/ void playWin(void);/*输出胜利者信息*/

    C语言编写的推箱子游戏源码

    { int x; int y; }PLAYER; PLAYER p; typedef struct ADD { int x; int y; }ADD; typedef struct STAR { int x; int y; int c; } STAR; STAR s[300]; DRAWSTAR1() {int i,j,m,n,dotx,doty,color...

    java 纸牌游戏 面向对象开发

    draw(Graphics, int, int) width : int height : int red : int black : int heart : int spade : int diamond : int club : int faceup : boolean r : int s : int link : Card 它主要定义了一个纸牌的...

    C语言函数及相关知识

    用 法: void far arc(int x, int y, int stangle, int endangle, int radius); 程序例: #include <graphics.h> #include #include #include int main(void) { /* request auto detection */ int gdriver = ...

    C#实现扫雷

    Mines[x, y].Font = new Font("宋体", 10.5F, FontStyle.Bold, GraphicsUnit.Point, ((byte)(134))); //定义字体 Mines[x, y].BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch;//自定义图片...

    扫雷.cpp(部分代码)

    int couty_xyk_byMsg(int *x, int *y); void cout_xy_by_k(int k,int *x,int *y); int dig_mine(); int scan_mine(int k); void scan_mine1(int k); void show_all_mines(int n); void test_data(); void show_...

    java用填充多边形的方法填充一个三角形Demo

    public void paintIcon(Component c, Graphics g, int x, int y) { Graphics2D g2d = (Graphics2D) g; Polygon plygon = new Polygon(); plygon.addPoint(0, 30); plygon.addPoint(30, 30); ...

    DDA画直线源代码 C语言代码

    putpixel(x,(int)(y+0.5),color); y+=m; } } main() { int a,b,c,d,e; int graphdriver=DETECT; int graphmode=0; initgraph(&graphdriver,&graphmode," "); cleardevice(); a=0; b=0; c=...

    C语言图形函数介绍

    Turbo C提供了非常丰富的图形函数, 所有图形函数的原型均在graphics. h中, 本节主要介绍图形模式的初始化、独立图形程序的建立、基本图形功能、图形窗口以及图形模式下的文本输出等函数。另外, 使用图形函数时要确保...

    java helloworld java

    int x,y; public void init() { x=8; y=7; } public void paint(Graphics g) {g.drawString("类中定义两个变量:x=8 y=7",50,60); g.drawString("他们的和是: "+(x+y),50,80); g.drawString("他们的差是: "+(x-...

    水印 java Graphics2D实现文字图片水印

    水印 java Graphics2D实现文字图片水印 实现水印四个角水印

    Java 小项目 飞机大战源码(已测试无BUG)

    public FlyingObject(int width,int height,int x,int y){ this.width = width; this.height = height; this.x = x; this.y = y; } /** 读取图片 */ public static BufferedImage loadImage(String ...

    C语言函数大全.CHM

    C语言函数大全,CHM,中文版。 C语言各种函数具体描述,有例证. 函数名: bar 功 能: 画一个二维条形图 用 法: void far bar(int left, int top, int right, int bottom); 程序例: #include #include #include...

    java五子棋源码

    int locX, locY /* 囱竚 */, count /* 硈囱计 */, x, y /* 既竚 */, displace_x=0, displace_y=0 /* 簿秖 */, direction; ArrayList steps = new ArrayList(); /* 癘魁囱˙ */ JPopupMenu control_...

Global site tag (gtag.js) - Google Analytics