Felk

编程的原因是喜欢,不是为了别的。 从摸上电脑的那一刻,我就知道,这才是我的世界。我一心一意地想作个程序员,尽管知道很累。人真的不能轻言放弃,否则,失去的永远无法挽回!生命是一种长期而持续的累积过程。所...

MIDP1.0实现图片的旋转
public static final Image TransformImage (Image srcImage, int transform)
{
 Image result = null;
 int srcW = srcImage.getWidth();
 int srcH = srcImage.getHeight();
 Graphics g = null;
 switch (transform)
 {
  // nothing to do
  case TRANS_NONE:
   return srcImage;
   // X-flip
  case TRANS_MIRROR:
   result = Image.createImage(srcW, srcH);
   g = result.getGraphics();
   for (int i = 0; i < srcW; i++)
   {
    g.setClip(i, 0, 1, srcH);
    g.drawImage(srcImage, i * 2 - srcW + 1, 0, Graphics.TOP
      | Graphics.LEFT);

   }
   break;
  // Y-flip
  case TRANS_MIRROR_ROT180:
   result = Image.createImage(srcW, srcH);
   g = result.getGraphics();
   for (int i = 0; i < srcH; i++)
   {
    g.setClip(0, i, srcW, 1);
    g.drawImage(srcImage, 0, 2 * i - srcH + 1, Graphics.TOP
      | Graphics.LEFT);

   }
   break;
  // rotate 180 degree deasil
  case TRANS_ROT180:
   result = TransformImage(srcImage, TRANS_MIRROR_ROT180);
   result = TransformImage(result, TRANS_MIRROR);
   break;
  // rotate 90 degree deasil
  case TRANS_ROT90:
   result = Image.createImage(srcH, srcW);
   g = result.getGraphics();
   for (int i = 0; i < srcH; i++)
   {
    for (int j = 0; j < srcW; j++)
    {
     g.setClip(i, j, 1, 1);
     g.drawImage(srcImage, i - j, i + j - srcH, Graphics.TOP
       | Graphics.LEFT);
    }

   }
   break;
  // X-flip and then rotate 270 degree deasil
  case TRANS_MIRROR_ROT270:
   result = Image.createImage(srcH, srcW);
   g = result.getGraphics();
   for (int i = 0; i < srcH; i++)
   {
    for (int j = 0; j < srcW; j++)
    {
     g.setClip(i, j, 1, 1);
     g.drawImage(srcImage, i - j, j - i, Graphics.TOP
       | Graphics.LEFT);
    }

   }
   break;
  // X-flip and then rotate 90 degree deasil
  case TRANS_MIRROR_ROT90:
   result = TransformImage(srcImage, TRANS_ROT90);
   result = TransformImage(result, TRANS_MIRROR_ROT180);
   break;
  // Rotate 270 degree deasil
  case TRANS_ROT270:
   result = TransformImage(srcImage, TRANS_MIRROR_ROT270);
   result = TransformImage(result, TRANS_MIRROR_ROT180);
   break;
 }
 return result;
}
阅读更多
文章标签: image null
个人分类: 学习笔记
想对作者说点什么? 我来说一句

MIDP1.0实现图片旋转

2008年03月14日 3KB 下载

没有更多推荐了,返回首页

不良信息举报

MIDP1.0实现图片的旋转

最多只允许输入30个字

加入CSDN,享受更精准的内容推荐,与500万程序员共同成长!
关闭
关闭