小图终于可以居中了

以前以为把图像居中是一件很难的事情,今天试了一下才晓得原来很简单。

  mem_bmp=new Bitmap(mainframe->viewX,mainframe->viewY,PixelFormat32bppARGB); //设置画布 

  mem_g=Graphics::FromImage(mem_bmp);

  Matrix ccmatrix;//图像进行缩放和移动
  ccmatrix.Scale(doc_scalefactor,doc_scalefactor);
  ccmatrix.Translate(doc_Xmove,doc_Ymove);
  mem_g->SetTransform(&ccmatrix);
  m_DrawRectStartX=(mainframe->viewX-nViewsizeX)/2;//计算图像中心移动到视图中心所需要移动的距离,Mainframe->viewX是视图的宽度,

                                                                                  //nViewsizeX是图像的宽度。
  m_DrawRectStartY=(mainframe->viewY-nViewsizeY)/2;
  Rect draw_rect(m_DrawRectStartX,m_DrawRectStartY,nViewsizeX,nViewsizeY);  //图像显示所在的矩形
       
  mem_g->DrawImage(&bitmap,draw_rect);    //在画布上画栅格图像

 

当然,如果牵涉到矢量图的叠加的时候,自然是要把矢量图上各个点的坐标转换为画布的坐标之后在加上相应的量,即m_DrawRectStartX,m_DrawRectStartY。

 

 for(int array_point=0;array_point<ipoints;array_point++)  //依次取出线上各点的坐标
 {
  double temx;
  temx=Arrayx[array_point];//poLine->getX(line_point_id);
  double temy;
  temy=Arrayy[array_point];//poLine->getY(line_point_id);

  double lower_left_y=Y0+YResolution*nBufferSizeY;
  (*(lpoint+array_point)).X=(temx-X0)/XResolution*(nViewsizeX/nBufferSizeX)+m_DrawRectStartX;                   //遥感影像垂直分辨率为负值
  (*(lpoint+array_point)).Y=-1.0*(temy-lower_left_y)/YResolution*(nViewsizeY/nBufferSizeY)+m_DrawRectStartY;

 }
 linepath.AddLines(lpoint,ipoints);
 delete [] lpoint;
 delete [] Arrayx;
 delete [] Arrayy;
 Pen mypen(Color(255,0,255,0),2/doc_scalefactor);//定义画笔
 mem_g->DrawPath(&mypen,&linepath);

posted @ 2009-03-12 17:10  gisbingxin  阅读(471)  评论(0编辑  收藏  举报