In vs2017 dialog mode test by
a using namespace Gdiplus;
void CXXDlg :: the OnPaint ()
{
// the following two to add, or not display the picture, do not know why
CImage image1;
image1.Load (L "");
/ / display image
the CDC the pDC * = the GetDC ();
Graphics Graph (pDC-> GetSafeHdc ());
image image (L "pic.jpg");
graph.DrawImage (& image, 70, 50);
the ReleaseDC (the pDC);
// display image using a negative coordinate
the CDC the pDC * = the GetDC ();
Graphics Graph (pDC-> GetSafeHdc ());
image image (L "pic.jpg");
graph.DrawImage (& image, -70, -50);
ReleaseDC (pDC);
display resolution different picture of the situation //
CDC * pDC = GetDC ();
Graphics Graph (pDC-> GetSafeHdc ());
Image Image (L "pic.jpg");
graph.DrawImage (Image &, 0, 0); // draw the image
CString strPrint; // output string
double f = graph.GetDpiX () / image.GetHorizontalResolution (); // scaling
strPrint.Format (L "screen resolution% .0f, the image resolution is% .0f, scaling is .1f%",
graph.GetDpiX (), image.GetHorizontalResolution (), F);
Graph .DrawString (strPrint, -1, & Font (L " bold",. 17, FontStyleBold),
of PointF (0, 280), & SolidBrush with (Color :: Red));
the ReleaseDC (the pDC);
zooming method // image. 1
the CDC * = the GetDC the pDC ();
Graphics Graph (pDC-> GetSafeHdc ());
CRect winRect;
the GetClientRect (winRect); // get the window drawing area size
Image image (L "pic.jpg") ;
graph.DrawImage (& image, 0, 0 , winRect.Width (), winRect.Height ()); // draw the image
the ReleaseDC (the pDC);
// image scaling method 2
the CDC the pDC * = the GetDC ();
Graphics Graph ( pDC-> GetSafeHdc ());
CRect winRect;
the GetClientRect (winRect); // get the size of the window drawing area
Rect rect (0, 0, winRect.Width (), winRect.Height ()); // Create a drawing area rectangular Object
image image (L "pic.jpg");
graph.DrawImage (& image, RECT); // draw the image
the ReleaseDC (the pDC);
******************* ************************************************** *******
6.4.4 Code
************************************** **************************************
// trimming image display
CDC * pDC = GetDC ( );
Graph Graphics (pDC-> GetSafeHdc ());
Image Image (L "pic.jpg");
// start from an original image (12, 80), the trimming length 430, a width of the rectangular region 180
// then displays it (80, 90) at
graph.DrawImage (& image, 80, 90, 12 is, 80, 430., 180 [, UnitPixel);
the ReleaseDC (the pDC);
// scaling and cropping an image
the CDC the pDC * = the GetDC ();
Graphics Graph (pDC-> GetSafeHdc ());
Image Image (L "pic.jpg");
int = 430. nSrcWidth; // clip area width
int nSrcHeight = 180; // clip area height
// display a rectangular area configured
destRect RECT (15, 40, (int) (* nSrcWidth 1.2), (int) (* nSrcHeight 1.2));
graph.DrawImage (& Image, destRect, 12 is, 80, nSrcWidth, nSrcHeight, UnitPixel);
the ReleaseDC (the pDC);
// transpose images
* = The GetDC the pDC the CDC ();
Graphics Graph (pDC-> GetSafeHdc ());
Bitmap Image (L "pic.jpg");
// outputs the original image
graph.DrawImage (Image &, 0, 0);
// switch output image coordinate counter
int nX = 500;
int nY = 0;
// image aspect
int nWidth image.GetWidth = ();
int = nHeight image.GetHeight ();
Point Points [] = {// need to add the output position transposed image coordinate
Point (nX, nY), // original position of the upper left corner of the image output
Point (nX, nY + nWidth) , // output position upper right corner of the original image
Point (nX + nHeight, nY) }; / / lower left corner of the original image output position
graph.DrawImage (& image, Points,. 3);
the ReleaseDC (the pDC);
// mirror image of
the CDC the pDC * = the GetDC ();
Graphics Graph (pDC-> GetSafeHdc ());
Image Bitmap (L "pic.jpg");
// image aspect
int nWidth image.GetWidth = ();
int = nHeight image.GetHeight ();
// horizontal position of the output image
int nX = 0;
int nY = 0 ;
Point HoPoints [] = {
Point (nWidth + nX, nY),
Point (nX, nY),
Point (nWidth + nX, nY + nHeight)};
graph.DrawImage (& Image, HoPoints,. 3); // output level mirror
// output position of the vertical mirror
nX + = nWidth. 5;
nY = 0;
Point VePoints [] = {
Point (nX, nY + nHeight),
Point (nWidth + nX, nY + nHeight),
Point (nX, nY) };
graph.DrawImage (& Image, VePoints,. 3); // output vertical mirroring
ReleaseDC (pDC);
simple rotation of the image //
the CDC the pDC * = the GetDC ();
Graphics Graph (pDC-> GetSafeHdc ());
Bitmap Image (L "pic.jpg");
// image aspect
int nWidth = image .GetWidth ();
int = nHeight image.GetHeight ();
// 90-degree rotation position of the output image
int nX = 0;
int nY = 0;
Point points90 [] = {
Point (nHeight + nX, nY),
Point ( nHeight + nX, nY + nWidth),
Point (nX, nY)};
graph.DrawImage (& image, points90,. 3); // output image rotated by 90 degrees
@ 180 degrees rotation of the image output position
nX = nHeight + . 5;
nY = 0;
Point points180 [] = {
Point (nWidth + nX, nY + nHeight),
Point (nX, nY + nHeight),
Point (nWidth + nX, nY)};
graph.DrawImage (& Image, points180,. 3); // output image rotated by 180 degrees in
the ReleaseDC (the pDC);
// image distortion
CDC the GetDC the pDC = * ();
Graphics Graph (pDC-> GetSafeHdc ());
Bitmap image (L "pic.jpg");
// image aspect
int nWidth image.GetWidth = ();
int = nHeight image.GetHeight ( );
// 1 warped image output position
int nX = 0;
int nY = 0;
Point points1 [] = {
Point (nX, nY),
Point (nWidth + nX, nY + 0),
Point (nX + 60, nHeight + nY)};
graph.DrawImage (& image, points1,. 3); // output deformed figure 1
// 2 position of the output image modification
nX = 520;
a = 0;
Point points2 [] = {
Point (nX + 52),
Point (nX + 374 + 200),
Point (nX + 117)};
graph.DrawImage (& image, points2, 3); //输出变形图形2
}
a using namespace Gdiplus;
void CXXDlg :: the OnPaint ()
{
// the following two to add, or not display the picture, do not know why
CImage image1;
image1.Load (L "");
/ / display image
the CDC the pDC * = the GetDC ();
Graphics Graph (pDC-> GetSafeHdc ());
image image (L "pic.jpg");
graph.DrawImage (& image, 70, 50);
the ReleaseDC (the pDC);
// display image using a negative coordinate
the CDC the pDC * = the GetDC ();
Graphics Graph (pDC-> GetSafeHdc ());
image image (L "pic.jpg");
graph.DrawImage (& image, -70, -50);
ReleaseDC (pDC);
display resolution different picture of the situation //
CDC * pDC = GetDC ();
Graphics Graph (pDC-> GetSafeHdc ());
Image Image (L "pic.jpg");
graph.DrawImage (Image &, 0, 0); // draw the image
CString strPrint; // output string
double f = graph.GetDpiX () / image.GetHorizontalResolution (); // scaling
strPrint.Format (L "screen resolution% .0f, the image resolution is% .0f, scaling is .1f%",
graph.GetDpiX (), image.GetHorizontalResolution (), F);
Graph .DrawString (strPrint, -1, & Font (L " bold",. 17, FontStyleBold),
of PointF (0, 280), & SolidBrush with (Color :: Red));
the ReleaseDC (the pDC);
zooming method // image. 1
the CDC * = the GetDC the pDC ();
Graphics Graph (pDC-> GetSafeHdc ());
CRect winRect;
the GetClientRect (winRect); // get the window drawing area size
Image image (L "pic.jpg") ;
graph.DrawImage (& image, 0, 0 , winRect.Width (), winRect.Height ()); // draw the image
the ReleaseDC (the pDC);
// image scaling method 2
the CDC the pDC * = the GetDC ();
Graphics Graph ( pDC-> GetSafeHdc ());
CRect winRect;
the GetClientRect (winRect); // get the size of the window drawing area
Rect rect (0, 0, winRect.Width (), winRect.Height ()); // Create a drawing area rectangular Object
image image (L "pic.jpg");
graph.DrawImage (& image, RECT); // draw the image
the ReleaseDC (the pDC);
******************* ************************************************** *******
6.4.4 Code
************************************** **************************************
// trimming image display
CDC * pDC = GetDC ( );
Graph Graphics (pDC-> GetSafeHdc ());
Image Image (L "pic.jpg");
// start from an original image (12, 80), the trimming length 430, a width of the rectangular region 180
// then displays it (80, 90) at
graph.DrawImage (& image, 80, 90, 12 is, 80, 430., 180 [, UnitPixel);
the ReleaseDC (the pDC);
// scaling and cropping an image
the CDC the pDC * = the GetDC ();
Graphics Graph (pDC-> GetSafeHdc ());
Image Image (L "pic.jpg");
int = 430. nSrcWidth; // clip area width
int nSrcHeight = 180; // clip area height
// display a rectangular area configured
destRect RECT (15, 40, (int) (* nSrcWidth 1.2), (int) (* nSrcHeight 1.2));
graph.DrawImage (& Image, destRect, 12 is, 80, nSrcWidth, nSrcHeight, UnitPixel);
the ReleaseDC (the pDC);
// transpose images
* = The GetDC the pDC the CDC ();
Graphics Graph (pDC-> GetSafeHdc ());
Bitmap Image (L "pic.jpg");
// outputs the original image
graph.DrawImage (Image &, 0, 0);
// switch output image coordinate counter
int nX = 500;
int nY = 0;
// image aspect
int nWidth image.GetWidth = ();
int = nHeight image.GetHeight ();
Point Points [] = {// need to add the output position transposed image coordinate
Point (nX, nY), // original position of the upper left corner of the image output
Point (nX, nY + nWidth) , // output position upper right corner of the original image
Point (nX + nHeight, nY) }; / / lower left corner of the original image output position
graph.DrawImage (& image, Points,. 3);
the ReleaseDC (the pDC);
// mirror image of
the CDC the pDC * = the GetDC ();
Graphics Graph (pDC-> GetSafeHdc ());
Image Bitmap (L "pic.jpg");
// image aspect
int nWidth image.GetWidth = ();
int = nHeight image.GetHeight ();
// horizontal position of the output image
int nX = 0;
int nY = 0 ;
Point HoPoints [] = {
Point (nWidth + nX, nY),
Point (nX, nY),
Point (nWidth + nX, nY + nHeight)};
graph.DrawImage (& Image, HoPoints,. 3); // output level mirror
// output position of the vertical mirror
nX + = nWidth. 5;
nY = 0;
Point VePoints [] = {
Point (nX, nY + nHeight),
Point (nWidth + nX, nY + nHeight),
Point (nX, nY) };
graph.DrawImage (& Image, VePoints,. 3); // output vertical mirroring
ReleaseDC (pDC);
simple rotation of the image //
the CDC the pDC * = the GetDC ();
Graphics Graph (pDC-> GetSafeHdc ());
Bitmap Image (L "pic.jpg");
// image aspect
int nWidth = image .GetWidth ();
int = nHeight image.GetHeight ();
// 90-degree rotation position of the output image
int nX = 0;
int nY = 0;
Point points90 [] = {
Point (nHeight + nX, nY),
Point ( nHeight + nX, nY + nWidth),
Point (nX, nY)};
graph.DrawImage (& image, points90,. 3); // output image rotated by 90 degrees
@ 180 degrees rotation of the image output position
nX = nHeight + . 5;
nY = 0;
Point points180 [] = {
Point (nWidth + nX, nY + nHeight),
Point (nX, nY + nHeight),
Point (nWidth + nX, nY)};
graph.DrawImage (& Image, points180,. 3); // output image rotated by 180 degrees in
the ReleaseDC (the pDC);
// image distortion
CDC the GetDC the pDC = * ();
Graphics Graph (pDC-> GetSafeHdc ());
Bitmap image (L "pic.jpg");
// image aspect
int nWidth image.GetWidth = ();
int = nHeight image.GetHeight ( );
// 1 warped image output position
int nX = 0;
int nY = 0;
Point points1 [] = {
Point (nX, nY),
Point (nWidth + nX, nY + 0),
Point (nX + 60, nHeight + nY)};
graph.DrawImage (& image, points1,. 3); // output deformed figure 1
// 2 position of the output image modification
nX = 520;
a = 0;
Point points2 [] = {
Point (nX + 52),
Point (nX + 374 + 200),
Point (nX + 117)};
graph.DrawImage (& image, points2, 3); //输出变形图形2
}