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

MIDP1.0实现图片翻转

    博客分类:
  • JAVA
阅读更多
最近移植游戏到几个新手机上,总不停的遇见NOKIA UI API,于是自己尝试用MIDP1.0写了个简单的NOKIA图片翻转。

代码里实现了图片的左右翻转,上下翻转,180度翻转。实现方法就是利用setclip()画小图从而实现翻转。对性能要求不是很高的朋友可以用下面的代码,现在偶共享出来:

引用内容 引用内容

/*图片翻转效果*/  
public void drawTransImage(Graphics g1,Image image,int x,int y,int type)  
{  
if(type==0X2000)//左右翻转  
{  
  for(int i=0;i<image.getWidth();i++)  
  drawClipImage(g1,image,x+i,y,1,image.getHeight(),image.getWidth()-i,0);  
}  
else if(type==0x4000)//上下翻转
{  
  for(int i=0;i<image.getHeight();i++)  
  drawClipImage(g1,image,x,y+i,image.getWidth(),1,0,image.getHeight()-i);  
}
else if(type==180)//180度翻转
{
    for(int i=0;i<image.getWidth();i++)
        for(int j=0;j<image.getHeight();j++)
            drawClipImage(g1,image,x+i,y+i,1,1,image.getWidth()-i,image.getHeight()-i);
    }
}  
    
/*画小图*/  
public void drawClipImage(Graphics g,Image a,int clipx,int clipy,int clipw,int cliph,int offx,int offy)  
{  
int x,y,w,h;  
x=g.getClipX();  
y=g.getClipY();  
w=g.getClipWidth();  
h=g.getClipHeight();  
g.setClip(clipx,clipy,clipw,cliph);  
g.drawImage(a,clipx-offx,clipy-offy,0);  
g.setClip(x,y,w,h);  
}
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics