GDI+图像的显示、裁剪、缩放、转置…
2017-10-10 16:52
405 查看
在vs2017对话框模式下测试通过
using namespace Gdiplus;
void CXXDlg::OnPaint()
{
//下面两句要加上,不然无法显示图片,不知道为什么
CImage image1;
image1.Load(L"");
// 图像的显示
CDC* pDC = GetDC();
Graphics graph(pDC->GetSafeHdc());
Image image(L"pic.jpg");
graph.DrawImage(&image, 70, 50);
ReleaseDC(pDC);
// 使用负坐标显示图像
CDC* pDC = GetDC();
Graphics graph(pDC->GetSafeHdc());
Image image(L"pic.jpg");
graph.DrawImage(&image, -70, -50);
ReleaseDC(pDC);
// 不同分辨率图片的显示情况
CDC* pDC = GetDC();
Graphics graph(pDC->GetSafeHdc());
Image image(L"pic.jpg");
graph.DrawImage(&image, 0, 0); // 绘制图像
CString
strPrint; //
输出的字符串
double f = graph.GetDpiX() /
image.GetHorizontalResolution(); // 缩放比例
strPrint.Format(L"屏幕分辨率是%.0f, 图像分辨率是%.0f,
缩放比例是%.1f",
graph.GetDpiX(),
image.GetHorizontalResolution(), f);
graph.DrawString(strPrint, -1, &Font(L"黑体",
17, FontStyleBold),
PointF(0, 280),
&SolidBrush(Color::Red));
ReleaseDC(pDC);
// 图像的缩放方法1
CDC* pDC = GetDC();
Graphics graph(pDC->GetSafeHdc());
CRect winRect;
GetClientRect(winRect); //
获得窗口绘制区的大小
Image image(L"pic.jpg");
graph.DrawImage(&image, 0,
0, winRect.Width(), winRect.Height()); //
绘制图像
ReleaseDC(pDC);
// 图像的缩放方法2
CDC* pDC = GetDC();
Graphics graph(pDC->GetSafeHdc());
CRect winRect;
GetClientRect(winRect); //
获得窗口绘制区的大小
Rect rect(0, 0, winRect.Width(),
winRect.Height()); // 创建绘制区域的矩形对象
Image image(L"pic.jpg");
graph.DrawImage(&image, rect); // 绘制图像
ReleaseDC(pDC);
****************************************************************************
6.4.4节代码
****************************************************************************
// 图像的剪裁显示
CDC* pDC = GetDC();
Graphics graph(pDC->GetSafeHdc());
Image image(L"pic.jpg");
// 从原图片的(12, 80)开始,剪裁长为430,宽为180的矩形区域
// 然后将其显示在(80, 90)处
graph.DrawImage(&image, 80, 90, 12, 80, 430,
180, UnitPixel);
ReleaseDC(pDC);
// 剪裁并缩放图像
CDC* pDC = GetDC();
Graphics graph(pDC->GetSafeHdc());
Image image(L"pic.jpg");
int nSrcWidth = 430; // 剪裁区域的宽度
int nSrcHeight = 180; // 剪裁区域的高度
// 构造显示的矩形区域
Rect destRect(15, 40, (int)(nSrcWidth*1.2),
(int)(nSrcHeight*1.2));
graph.DrawImage(&image, destRect, 12, 80,
nSrcWidth, nSrcHeight, UnitPixel);
ReleaseDC(pDC);
// 图像的转置
CDC* pDC = GetDC();
Graphics graph(pDC->GetSafeHdc());
Bitmap image(L"pic.jpg");
// 输出原始图像
graph.DrawImage(&image, 0, 0);
// 输出转置图像的坐标
int nX = 500;
int nY = 0;
// 图像长宽
int nWidth = image.GetWidth();
int nHeight = image.GetHeight();
Point points[] =
{
// 输出位置需要加上转置图像的坐标
Point(nX,
nY),
// 原图像左上角的输出位置
Point(nX, nY +
nWidth), //
原图像右上角的输出位置
Point(nX + nHeight, nY)
}; // 原图像左下角的输出位置
graph.DrawImage(&image, points, 3);
ReleaseDC(pDC);
// 图像的镜像
CDC* pDC = GetDC();
Graphics graph(pDC->GetSafeHdc());
Bitmap image(L"pic.jpg");
// 图像长宽
int nWidth = image.GetWidth();
int nHeight = image.GetHeight();
// 水平镜像的输出位置
int nX = 0;
int nY = 0;
Point HoPoints[] = {
Point(nX + nWidth,
nY),
Point(nX,
nY),
Point(nX + nWidth, nY +
nHeight) };
graph.DrawImage(&image, HoPoints,
3); // 输出水平镜像
// 垂直镜像的输出位置
nX = nWidth + 5;
nY = 0;
Point VePoints[] = {
Point(nX, nY +
nHeight),
Point(nX + nWidth, nY +
nHeight),
Point(nX, nY) };
graph.DrawImage(&image, VePoints,
3); // 输出垂直镜像
ReleaseDC(pDC);
// 图像的简单旋转
CDC* pDC = GetDC();
Graphics graph(pDC->GetSafeHdc());
Bitmap image(L"pic.jpg");
// 图像长宽
int nWidth = image.GetWidth();
int nHeight = image.GetHeight();
// 旋转90度图像的输出位置
int nX = 0;
int nY = 0;
Point points90[] = {
Point(nX + nHeight, nY),
Point(nX + nHeight, nY +
nWidth),
Point(nX, nY) };
graph.DrawImage(&image, points90, 3); //
输出旋转了90度的图像
// 旋转180度图像的输出位置
nX = nHeight + 5;
nY = 0;
Point points180[] = {
Point(nX + nWidth, nY + nHeight),
Point(nX, nY + nHeight),
Point(nX + nWidth, nY) };
graph.DrawImage(&image, points180, 3); //
输出旋转了180度的图像
ReleaseDC(pDC);
// 图像的变形
CDC* pDC = GetDC();
Graphics graph(pDC->GetSafeHdc());
Bitmap image(L"pic.jpg");
// 图像长宽
int nWidth = image.GetWidth();
int nHeight = image.GetHeight();
// 变形图像1的输出位置
int nX = 0;
int nY = 0;
Point points1[] = {
Point(nX, nY),
Point(nX + nWidth, nY +
0),
Point(nX + 60, nY + nHeight)
};
graph.DrawImage(&image, points1, 3); //
输出变形图形1
// 变形图像2的输出位置
nX = 520;
nY = 0;
Point points2[] = {
Point(nX + 52, nY),
Point(nX + 374, nY + 200),
Point(nX, nY + 117) };
graph.DrawImage(&image, points2, 3); //
输出变形图形2
}
using namespace Gdiplus;
void CXXDlg::OnPaint()
{
//下面两句要加上,不然无法显示图片,不知道为什么
CImage image1;
image1.Load(L"");
// 图像的显示
CDC* pDC = GetDC();
Graphics graph(pDC->GetSafeHdc());
Image image(L"pic.jpg");
graph.DrawImage(&image, 70, 50);
ReleaseDC(pDC);
// 使用负坐标显示图像
CDC* pDC = GetDC();
Graphics graph(pDC->GetSafeHdc());
Image image(L"pic.jpg");
graph.DrawImage(&image, -70, -50);
ReleaseDC(pDC);
// 不同分辨率图片的显示情况
CDC* pDC = GetDC();
Graphics graph(pDC->GetSafeHdc());
Image image(L"pic.jpg");
graph.DrawImage(&image, 0, 0); // 绘制图像
CString
strPrint; //
输出的字符串
double f = graph.GetDpiX() /
image.GetHorizontalResolution(); // 缩放比例
strPrint.Format(L"屏幕分辨率是%.0f, 图像分辨率是%.0f,
缩放比例是%.1f",
graph.GetDpiX(),
image.GetHorizontalResolution(), f);
graph.DrawString(strPrint, -1, &Font(L"黑体",
17, FontStyleBold),
PointF(0, 280),
&SolidBrush(Color::Red));
ReleaseDC(pDC);
// 图像的缩放方法1
CDC* pDC = GetDC();
Graphics graph(pDC->GetSafeHdc());
CRect winRect;
GetClientRect(winRect); //
获得窗口绘制区的大小
Image image(L"pic.jpg");
graph.DrawImage(&image, 0,
0, winRect.Width(), winRect.Height()); //
绘制图像
ReleaseDC(pDC);
// 图像的缩放方法2
CDC* pDC = GetDC();
Graphics graph(pDC->GetSafeHdc());
CRect winRect;
GetClientRect(winRect); //
获得窗口绘制区的大小
Rect rect(0, 0, winRect.Width(),
winRect.Height()); // 创建绘制区域的矩形对象
Image image(L"pic.jpg");
graph.DrawImage(&image, rect); // 绘制图像
ReleaseDC(pDC);
****************************************************************************
6.4.4节代码
****************************************************************************
// 图像的剪裁显示
CDC* pDC = GetDC();
Graphics graph(pDC->GetSafeHdc());
Image image(L"pic.jpg");
// 从原图片的(12, 80)开始,剪裁长为430,宽为180的矩形区域
// 然后将其显示在(80, 90)处
graph.DrawImage(&image, 80, 90, 12, 80, 430,
180, UnitPixel);
ReleaseDC(pDC);
// 剪裁并缩放图像
CDC* pDC = GetDC();
Graphics graph(pDC->GetSafeHdc());
Image image(L"pic.jpg");
int nSrcWidth = 430; // 剪裁区域的宽度
int nSrcHeight = 180; // 剪裁区域的高度
// 构造显示的矩形区域
Rect destRect(15, 40, (int)(nSrcWidth*1.2),
(int)(nSrcHeight*1.2));
graph.DrawImage(&image, destRect, 12, 80,
nSrcWidth, nSrcHeight, UnitPixel);
ReleaseDC(pDC);
// 图像的转置
CDC* pDC = GetDC();
Graphics graph(pDC->GetSafeHdc());
Bitmap image(L"pic.jpg");
// 输出原始图像
graph.DrawImage(&image, 0, 0);
// 输出转置图像的坐标
int nX = 500;
int nY = 0;
// 图像长宽
int nWidth = image.GetWidth();
int nHeight = image.GetHeight();
Point points[] =
{
// 输出位置需要加上转置图像的坐标
Point(nX,
nY),
// 原图像左上角的输出位置
Point(nX, nY +
nWidth), //
原图像右上角的输出位置
Point(nX + nHeight, nY)
}; // 原图像左下角的输出位置
graph.DrawImage(&image, points, 3);
ReleaseDC(pDC);
// 图像的镜像
CDC* pDC = GetDC();
Graphics graph(pDC->GetSafeHdc());
Bitmap image(L"pic.jpg");
// 图像长宽
int nWidth = image.GetWidth();
int nHeight = image.GetHeight();
// 水平镜像的输出位置
int nX = 0;
int nY = 0;
Point HoPoints[] = {
Point(nX + nWidth,
nY),
Point(nX,
nY),
Point(nX + nWidth, nY +
nHeight) };
graph.DrawImage(&image, HoPoints,
3); // 输出水平镜像
// 垂直镜像的输出位置
nX = nWidth + 5;
nY = 0;
Point VePoints[] = {
Point(nX, nY +
nHeight),
Point(nX + nWidth, nY +
nHeight),
Point(nX, nY) };
graph.DrawImage(&image, VePoints,
3); // 输出垂直镜像
ReleaseDC(pDC);
// 图像的简单旋转
CDC* pDC = GetDC();
Graphics graph(pDC->GetSafeHdc());
Bitmap image(L"pic.jpg");
// 图像长宽
int nWidth = image.GetWidth();
int nHeight = image.GetHeight();
// 旋转90度图像的输出位置
int nX = 0;
int nY = 0;
Point points90[] = {
Point(nX + nHeight, nY),
Point(nX + nHeight, nY +
nWidth),
Point(nX, nY) };
graph.DrawImage(&image, points90, 3); //
输出旋转了90度的图像
// 旋转180度图像的输出位置
nX = nHeight + 5;
nY = 0;
Point points180[] = {
Point(nX + nWidth, nY + nHeight),
Point(nX, nY + nHeight),
Point(nX + nWidth, nY) };
graph.DrawImage(&image, points180, 3); //
输出旋转了180度的图像
ReleaseDC(pDC);
// 图像的变形
CDC* pDC = GetDC();
Graphics graph(pDC->GetSafeHdc());
Bitmap image(L"pic.jpg");
// 图像长宽
int nWidth = image.GetWidth();
int nHeight = image.GetHeight();
// 变形图像1的输出位置
int nX = 0;
int nY = 0;
Point points1[] = {
Point(nX, nY),
Point(nX + nWidth, nY +
0),
Point(nX + 60, nY + nHeight)
};
graph.DrawImage(&image, points1, 3); //
输出变形图形1
// 变形图像2的输出位置
nX = 520;
nY = 0;
Point points2[] = {
Point(nX + 52, nY),
Point(nX + 374, nY + 200),
Point(nX, nY + 117) };
graph.DrawImage(&image, points2, 3); //
输出变形图形2
}
相关文章推荐
- GDI+图像的显示、裁剪、缩放、转置、镜像、旋转、变形
- GDI+图像的显示、裁剪、缩放、转置…
- 【美工设计 - Adobe Illustrator】基本设置 (图像显示 | 图像缩放 | 置入导出 | 标尺 | 网格 | 参考线 | 画板)
- 第6周作业-图像缩放显示2
- Java图片缩略图裁剪水印缩放旋转压缩转格式-Thumbnailator图像处理
- Qt绘图,显示图片图像,平移,缩放,旋转和扭曲图片的方法
- VC++2008中基于对话框GDI+的图像显示
- 使用GDI+可以方便的把OpenCV的图像矩阵类型数据显示在MFC的窗口中
- GDI+ 显示DICOM 图像测试
- 图片异步下载+本地缓存+listview显示+服务器缩放图像代码
- 第6周作业-图像缩放显示
- 第6周作业-图像缩放显示
- 【美工设计 - Adobe Illustrator】基本设置 (图像显示 | 图像缩放 | 置入导出 | 标尺 | 网格 | 参考线 | 画板)
- 第6周作业-图像缩放显示
- PHP图像操作:3D图、缩放、旋转、裁剪、添加水印(一)
- GDI+初探之图像透明显示和保存
- 基于mschart控件,绘制工控采集类曲线,可对图像进行缩放,拖动滚动条显示放大后的图像
- 第6周作业-图像缩放显示1
- GDI+ 中Image::FromStream ,用流的方式显示图像
- Java图片缩略图裁剪水印缩放旋转压缩转格式-Thumbnailator图像处理