将位图旋转90度

时间:2010-05-07 12:20:31  来源:第二电脑网  作者:第二电脑网

  第二电脑网导读://定义缓冲位图并剪切图形区域Graphics::Tbitmap *bufferbitmap=new Graphics::Tbitmap();bufferbitmap->Width=Image1->Height;bufferbitmap->Height=Image1->Width;static Trect sourcepix,destpix,fullbufferimage,fulldestimage;fullbufferimage.Left= 0;fullbufferimage.Top= bufferbitmap->Height;fullbufferimage.Right= b...
  正文:本文将介绍如何将一张位图旋转90度。向工程添加一个Timage控件,取名为Image1。
  工作原理是:创建一个位图缓冲区用于存储中间量,将原位图的每一行的像素转换为每一列然后存放在我们创建的位图缓冲区中。最后,将旋转后的位图从缓冲区存回原位图。

//定义缓冲位图并剪切图形区域
Graphics::Tbitmap *bufferbitmap=new Graphics::Tbitmap();
bufferbitmap->Width=Image1->Height;
bufferbitmap->Height=Image1->Width;

static Trect sourcepix,destpix,fullbufferimage,fulldestimage;

fullbufferimage.Left= 0;
fullbufferimage.Top= bufferbitmap->Height;
fullbufferimage.Right= bufferbitmap->Width;
fullbufferimage.Bottom= 0;

//旋转并逐像素地拷贝原位图到缓冲位图
for (int y=0; y<Image1->Height; y++)
{
 for (int x=0; x<Image1->Width; x++)
 {
  sourcepix.Left= x;
  sourcepix.Top= y+1;
  sourcepix.Right= x+1;
  sourcepix.Bottom= y;
  destpix.Left=y;
  destpix.Top=bufferbitmap->Height-x;
  destpix.Right=y+1;
  destpix.Bottom=bufferbitmap->Height-x-1;
  bufferbitmap->Canvas->CopyRect(destpix,Image1->Canvas,sourcepix);
 }
}

//调整原位图的尺寸并拷贝旋转后的缓冲位图到原位图
Image1->Width=bufferbitmap->Width;
Image1->Height=bufferbitmap->Height;
Image1->Picture->Bitmap->Width=bufferbitmap->Width;
Image1->Picture->Bitmap->Height=bufferbitmap->Height;
Image1->Canvas->CopyRect(fullbufferimage,bufferbitmap->Canvas,fullbufferimage);


"将位图旋转90度"由第二电脑网原创提供,转载请注明:http://www.002pc.com/master/College/Language/VC/2010-05-07/13896.html


关键字:

关于《将位图旋转90度》文章的评论

站内搜索: 高级搜索

热门搜索: Windows style 系统 tr IP QQ CPU 安装 function 注册 if td