问一个比较菜菜的问题“如何把读入的PNG图片分割,用1.0做”

smallrole 2004-12-29 01:43:26
我想把读入的图片分成几个小块分别保存在image对象里吗?
请问用1.0能实现吗?up有分:)
...全文
238 19 打赏 收藏 转发到动态 举报
写回复
用AI写文章
19 条回复
切换为时间正序
请发表友善的回复…
发表回复
皮鲁 2005-01-10
  • 打赏
  • 举报
回复
唉,忍吧~~ 牺牲点速度而已嘛
cuilichen 2005-01-10
  • 打赏
  • 举报
回复
透明色?不好意思,没想到。
我的前一个项目中没有使用到,所以。。。
呵呵,谢谢A_KID(A_KID).
nomenn 2005-01-08
  • 打赏
  • 举报
回复
使用SETCLIP的话 如果一帧中所需要画的图比较多的话 会严重影响运行速度哟
我在nokia4上setClip比不用多了将近60MS,所以有时候还是不使用的好
wizzard 2005-01-06
  • 打赏
  • 举报
回复
楼上说的对,索爱真机还真有问题(t618),那应该怎么办呢,求教!
A_KID 2005-01-05
  • 打赏
  • 举报
回复
楼上的方法会丢掉图片透明色的
cuilichen 2005-01-05
  • 打赏
  • 举报
回复
一、首先声明一个Image,参数是你需要的宽度和高度:
Image target = Image.createImage(width, height);
二、再得到他的Graphics:
Graphics g1 = target.getGraphics();
三、声明源图片:
try {
Image src = Image.createImage(_str);
} catch (IOException e) {
e.printStackTrace();
}
四、将源图片画到目标图片上:
g1.drawImage(src, width/2, height/2, Graphics.HCENTER | Graphics.VCENTER);
注意:目标图片比源图片小,就可以实现分割了。还有就是第四步的时候绘图的位置要把握好。
A_KID 2005-01-05
  • 打赏
  • 举报
回复
做游戏的话不用切出来的。用setclip,再转换一下坐标,直接把一张大图画上去。因为有clip的关系,实际表现出来的就是画你需要的部分。
syngle 2005-01-04
  • 打赏
  • 举报
回复
Image image=Image.createImage(anotherImage)
oceanlee8888 2004-12-31
  • 打赏
  • 举报
回复
public class Draw {
private static final int canvasWidth=240;
private static final int canvasHeight=260;

/**anchor*/
public static final int LEFTANDTOP=0;
public static final int LEFTANDBUTTON=1;
public static final int RIGHTANDTOP=2;
public static final int RIGHTANDBUTTON=3;

private Draw() {
}
/**区域绘图*/
public static void drawRegion(Graphics g, Image src, int srcX, int srcY,int width,
int height, int destX, int destY,int anchor) {
int tarX,tarY;

switch(anchor){
case LEFTANDTOP:
tarX=destX-srcX;
tarY=destY-srcY;
g.setClip(destX, destY, width, height);
break;
case LEFTANDBUTTON:
tarX=destX-srcX;
tarY=destY-srcY-height+1;
g.setClip(destX, destY-height+1, width, height);
break;
case RIGHTANDTOP:
tarX=destX-srcX-width+1;
tarY=destY-srcY;
g.setClip(destX-width+1, destY, width, height);
break;
case RIGHTANDBUTTON:
tarX=destX-srcX-width+1;
tarY=destY-srcY-height+1;
g.setClip(destX-width+1, destY-height+1, width, height);
break;
default:
tarX=destX-srcX;
tarY=destY-srcY;
}

g.drawImage(src, tarX, tarY, g.LEFT|g.TOP);
g.setClip(0, 0, canvasWidth,canvasHeight);
}
}
jinalone 2004-12-30
  • 打赏
  • 举报
回复
还有提醒你一句“割图”这个方法如果图总长度超过128,(高度也一样)的话在索爱真机上显示是有问题的。
jinalone 2004-12-30
  • 打赏
  • 举报
回复
下面是我自己写的程序但不太完善的。你可以加以改进。

//画图
public void PaintCardNum(Image img,int x,int y,int framenum,int num,Graphics bg){
/*
img要画的图
x、y要画图出现在屏幕的相应位置
famenum图片分为的总数
num画的图在大力图中的位置
*/

if(num > framenum) num = framenum;
if(num < 1) num = 1;
int frameWidth = img.getWidth()/framenum;
int framefrist = frameWidth * (num-1);

bg.translate(-framefrist,0);
bg.setClip(x+framefrist,0,frameWidth,y + img.getHeight());
bg.drawImage(img,x,y,Graphics.TOP|Graphics.LEFT);
bg.translate(framefrist,0);
bg.setClip(0,0,getWidth(),getHeight());

}
sy5591 2004-12-30
  • 打赏
  • 举报
回复
setClip();很方便

要求你的代码比较严谨就好了 没有什么麻烦的
smallrole 2004-12-30
  • 打赏
  • 举报
回复
去查api
smallrole 2004-12-30
  • 打赏
  • 举报
回复
楼上的不错,回去试验一下,谢谢你了好心人
CMyMfc 2004-12-29
  • 打赏
  • 举报
回复
去查api
murphy008 2004-12-29
  • 打赏
  • 举报
回复
能实现,但不好做,正如楼上所说的
acreep 2004-12-29
  • 打赏
  • 举报
回复
好想要自己写函数,不过你可以用setClip()只显示图片的一部分呀
smallrole 2004-12-29
  • 打赏
  • 举报
回复
剪切之后可以保存在image对象里吗?
prok 2004-12-29
  • 打赏
  • 举报
回复
setclip。这个函数可以剪切你得图片

13,100

社区成员

发帖
与我相关
我的任务
社区描述
Java J2ME
社区管理员
  • J2ME社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧