BCB PNG图片任意角度旋转总结

因为是在原有项目中加入新功能,导致走了许多弯路,也问了很多问题。废话不多说,进入正题。
1.在数据库中取图片流

   TStream *pStream;
   TStreamAdapter *Adapter;
   Image *plmg;
   pStream = pQuery->CreateBlobStream(pQuery->FieldByName("ImgData"), bmRead);//数据库中取TSream流数据保存在pStream
   Adapter = new TStreamAdapter(pStream, soReference);
   Adapter->_AddRef();
   pImg=new Gdiplus::Image((IStream*)*Adapter,0);//通过TStreamAdapter对象转ISream后保存在plmg
    Adapter->_Release();
    delete pStream;

2.图片旋转

     Gdiplus::Graphics *g=new Gdiplus::Graphics(Image1->Canvas->Handle);
     POINT imgRotateCenterPos={0,0}; //旋转中心在图片坐标(相对于图片本身)
     PointF centerPos(imgRotateCenterPos.x+pImg->left,imgRotateCenterPos.y+pImg->top);
     g->Save();
     g->TranslateTransform(centerPos.X,centerPos.Y ); //源点移动到旋转中心
     g->RotateTransform(pDevice->pDevNode->Angle); //旋转
     g->TranslateTransform(-centerPos.X, -centerPos.Y);//还原源点
     g->DrawImage(pImg,pImg->left,pImg->top);
     g=NULL;
     delete g;

图片旋转通过GDI+实现,几个注意点:
1.如果你发现图片没有显示:初始化GDI+程序结束时释放GDI+;

头文件声明:

  ULONG_PTR   GdiplusToken;
 Gdiplus::GdiplusStartupInput   GdiplusStartupInput;

构造函数初始化GDI+

GdiplusStartup(&GdiplusToken,&GdiplusStartupInput, NULL);   //   初始化GDI+

析构函数释放GDI+

GdiplusShutdown(GdiplusToken);
  • 2
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值