ImageEx.cpp 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  1. // ImageEx.cpp : 实现文件
  2. //
  3. #include "stdafx.h"
  4. #include "ImageEx.h"
  5. // CImageEx
  6. CImageEx::CImageEx(IN const WCHAR* filename,IN BOOL useEmbeddedColorManagement/* = FALSE*/)
  7. :Image(filename,useEmbeddedColorManagement)
  8. {
  9. }
  10. CImageEx::CImageEx(IN IStream* stream,IN BOOL useEmbeddedColorManagement/* = FALSE*/)
  11. :Image(stream,useEmbeddedColorManagement)
  12. {
  13. }
  14. CImageEx::~CImageEx()
  15. {
  16. }
  17. //绘画图像
  18. bool CImageEx::DrawImage(CDC * pDC, INT nXPos, INT nYPos)
  19. {
  20. if(IsNull())
  21. return false;
  22. //创建屏幕
  23. ASSERT(pDC!=NULL);
  24. Graphics graphics(pDC->GetSafeHdc());
  25. //获取属性
  26. INT nImageWidth=this->GetWidth();
  27. INT nImageHeight=this->GetHeight();
  28. //构造位置
  29. RectF rcDrawRect;
  30. rcDrawRect.X=(REAL)nXPos;
  31. rcDrawRect.Y=(REAL)nYPos;
  32. rcDrawRect.Width=(REAL)nImageWidth;
  33. rcDrawRect.Height=(REAL)nImageHeight;
  34. //绘画图像
  35. graphics.DrawImage(this,rcDrawRect,0,0,(REAL)nImageWidth,(REAL)nImageHeight,UnitPixel);
  36. return true;
  37. }
  38. //绘画图像
  39. bool CImageEx::DrawImage( CDC * pDC, INT nXPos, INT nYPos, INT nDestWidth, INT nDestHeight )
  40. {
  41. if(IsNull())
  42. return false;
  43. //创建屏幕
  44. ASSERT(pDC!=NULL);
  45. Graphics graphics(pDC->GetSafeHdc());
  46. //构造位置
  47. RectF rcDrawRect;
  48. rcDrawRect.X=(REAL)nXPos;
  49. rcDrawRect.Y=(REAL)nYPos;
  50. rcDrawRect.Width=(REAL)nDestWidth;
  51. rcDrawRect.Height=(REAL)nDestHeight;
  52. //绘画图像
  53. graphics.DrawImage(this,rcDrawRect,0,0,(REAL)GetWidth(),(REAL)GetHeight(),UnitPixel);
  54. return true;
  55. }
  56. //绘画图像
  57. bool CImageEx::DrawImage( CDC * pDC, RECT &rc )
  58. {
  59. if(IsNull())
  60. return false;
  61. //创建屏幕
  62. ASSERT(pDC!=NULL);
  63. Graphics graphics(pDC->GetSafeHdc());
  64. //构造位置
  65. RectF rcDrawRect;
  66. rcDrawRect.X=(REAL)rc.left;
  67. rcDrawRect.Y=(REAL)rc.top;
  68. rcDrawRect.Width=(REAL)(rc.right-rc.left);
  69. rcDrawRect.Height=(REAL)(rc.bottom-rc.top);
  70. //绘画图像
  71. graphics.DrawImage(this,rcDrawRect,0,0,(REAL)GetWidth(),(REAL)GetHeight(),UnitPixel);
  72. return true;
  73. }
  74. //绘画图像
  75. bool CImageEx::DrawImage(CDC * pDC, INT nXDest, INT nYDest, INT nDestWidth, INT nDestHeight, INT nXScr, INT nYSrc)
  76. {
  77. if(IsNull())
  78. return false;
  79. //创建屏幕
  80. ASSERT(pDC!=NULL);
  81. Graphics graphics(pDC->GetSafeHdc());
  82. //构造位置
  83. RectF rcDrawRect;
  84. rcDrawRect.X=(REAL)nXDest;
  85. rcDrawRect.Y=(REAL)nYDest;
  86. rcDrawRect.Width=(REAL)nDestWidth;
  87. rcDrawRect.Height=(REAL)nDestHeight;
  88. //绘画图像
  89. graphics.DrawImage(this,rcDrawRect,(REAL)nXScr,(REAL)nYSrc,(REAL)nDestWidth,(REAL)nDestHeight,UnitPixel);
  90. return true;
  91. }
  92. //绘画图像
  93. bool CImageEx::DrawImage(CDC * pDC, INT nXDest, INT nYDest, INT nDestWidth, INT nDestHeight, INT nXScr, INT nYSrc, INT nSrcWidth, INT nSrcHeight)
  94. {
  95. if(IsNull())
  96. return false;
  97. //创建屏幕
  98. ASSERT(pDC!=NULL);
  99. Graphics graphics(pDC->GetSafeHdc());
  100. //构造位置
  101. RectF rcDrawRect;
  102. rcDrawRect.X=(REAL)nXDest;
  103. rcDrawRect.Y=(REAL)nYDest;
  104. rcDrawRect.Width=(REAL)nDestWidth;
  105. rcDrawRect.Height=(REAL)nDestHeight;
  106. //绘画图像
  107. graphics.DrawImage(this,rcDrawRect,(REAL)nXScr,(REAL)nYSrc,(REAL)nSrcWidth,(REAL)nSrcHeight,UnitPixel);
  108. return true;
  109. }
  110. // 是否为空图借
  111. BOOL CImageEx::IsNull()
  112. {
  113. return this->lastResult != Ok;
  114. }