Skip to content

Commit e205871

Browse files
authored
Merge pull request MicrosoftDocs#1097 from msebolt/consolidation-graphics
consolidation graphics
2 parents 710480e + 4fcc671 commit e205871

7 files changed

+126
-177
lines changed

.openpublishing.redirection.json

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3890,6 +3890,26 @@
38903890
"redirect_url": "/cpp/dotnet/file-handling-and-i-o-cpp-cli#write_text",
38913891
"redirect_document_id": false
38923892
},
3893+
{
3894+
"source_path": "docs/dotnet/how-to-convert-image-file-formats-with-the-dotnet-framework.md",
3895+
"redirect_url": "/cpp/dotnet/graphics-operations-cpp-cli#convert",
3896+
"redirect_document_id": false
3897+
},
3898+
{
3899+
"source_path": "docs/dotnet/how-to-display-images-with-the-dotnet-framework.md",
3900+
"redirect_url": "/cpp/dotnet/graphics-operations-cpp-cli#display",
3901+
"redirect_document_id": false
3902+
},
3903+
{
3904+
"source_path": "docs/dotnet/how-to-draw-shapes-with-the-dotnet-framework.md",
3905+
"redirect_url": "/cpp/dotnet/graphics-operations-cpp-cli#draw",
3906+
"redirect_document_id": false
3907+
},
3908+
{
3909+
"source_path": "docs/dotnet/how-to-rotate-images-with-the-dotnet-framework.md",
3910+
"redirect_url": "/cpp/dotnet/graphics-operations-cpp-cli#rotate",
3911+
"redirect_document_id": false
3912+
},
38933913
{
38943914
"source_path": "docs/error-messages/compiler-errors-1/index.md",
38953915
"redirect_url": "/cpp/error-messages/compiler-errors-1/compiler-fatal-errors-c999-through-c1999",

docs/dotnet/TOC.md

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -111,10 +111,6 @@
111111
## [Regular Expressions (C++/CLI)](regular-expressions-cpp-cli.md)
112112
## [File Handling and I-O (C++/CLI)](file-handling-and-i-o-cpp-cli.md)
113113
## [Graphics Operations (C++/CLI)](graphics-operations-cpp-cli.md)
114-
### [How to: Convert Image File Formats with the .NET Framework](how-to-convert-image-file-formats-with-the-dotnet-framework.md)
115-
### [How to: Display Images with the .NET Framework](how-to-display-images-with-the-dotnet-framework.md)
116-
### [How to: Draw Shapes with the .NET Framework](how-to-draw-shapes-with-the-dotnet-framework.md)
117-
### [How to: Rotate Images with the .NET Framework](how-to-rotate-images-with-the-dotnet-framework.md)
118114
## [Windows Operations (C++/CLI)](windows-operations-cpp-cli.md)
119115
### [How to: Determine if Shutdown Has Started (C++/CLI)](how-to-determine-if-shutdown-has-started-cpp-cli.md)
120116
### [How to: Determine the User Interactive State (C++/CLI)](how-to-determine-the-user-interactive-state-cpp-cli.md)

docs/dotnet/graphics-operations-cpp-cli.md

Lines changed: 106 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,11 @@ ms.date: "11/04/2016"
55
ms.technology: ["cpp-cli"]
66
ms.topic: "conceptual"
77
dev_langs: ["C++"]
8-
helpviewer_keywords: ["GDI+ [C++]", ".NET Framework [C++], graphics", "images [C++], .NET Framework and", "GDI+ [C++], about graphics operations", "graphics [C++], .NET Framework and"]
8+
helpviewer_keywords: ["GDI+ [C++]", ".NET Framework [C++], graphics", "images [C++], .NET Framework and", "GDI+ [C++], about graphics operations", "graphics [C++], .NET Framework and",
9+
"GDI+ [C++], displaying images", "graphics [C++], displaying images",
10+
"GDI+, drawing shapes", "drawing, shapes", "shapes", "shapes, drawing",
11+
"GDI+ [C++], rotating images", "graphics [C++], rotating images",
12+
"GDI+ [C++], converting image file formats", "graphics [C++], converting image file formats"]
913
ms.assetid: bba27228-b9b3-4c9c-b31c-a04b76702a95
1014
author: "mikeblome"
1115
ms.author: "mblome"
@@ -16,21 +20,113 @@ Demonstrates image manipulation using the [!INCLUDE[winsdklong](../dotnet/includ
1620

1721
The following topics demonstrate the use of the <xref:System.Drawing.Image?displayProperty=fullName> class to perform image manipulation.
1822

19-
## In This Section
20-
[How to: Convert Image File Formats with the .NET Framework](../dotnet/how-to-convert-image-file-formats-with-the-dotnet-framework.md)
23+
## <a name="display"></a> Display Images with the .NET Framework
24+
The following code example modifies the OnPaint event handler to retrieve a pointer to the <xref:System.Drawing.Graphics> object for the main form. The <xref:System.Windows.Forms.Form.OnPaint%2A> function is intended for a Windows Forms application, most likely created with a Visual Studio application wizard.
2125

22-
[How to: Display Images with the .NET Framework](../dotnet/how-to-display-images-with-the-dotnet-framework.md)
26+
The image is represented by the <xref:System.Drawing.Image> class. The image data is loaded from a .jpg file using the <xref:System.Drawing.Image.FromFile%2A?displayProperty=fullName> method. Before the image is drawn to the form, the form is resized to accommodate the image. The drawing of the image is performed with the <xref:System.Drawing.Graphics.DrawImage%2A?displayProperty=fullName> method.
2327

24-
[How to: Draw Shapes with the .NET Framework](../dotnet/how-to-draw-shapes-with-the-dotnet-framework.md)
28+
The <xref:System.Drawing.Graphics> and <xref:System.Drawing.Image> classes are both in the <xref:System.Drawing?displayProperty=fullName> namespace.
2529

26-
[How to: Rotate Images with the .NET Framework](../dotnet/how-to-rotate-images-with-the-dotnet-framework.md)
30+
### Example
31+
32+
```cpp
33+
#using <system.drawing.dll>
34+
35+
using namespace System;
36+
using namespace System::Drawing;
37+
38+
protected:
39+
virtual Void Form1::OnPaint(PaintEventArgs^ pe) override
40+
{
41+
Graphics^ g = pe->Graphics;
42+
Image^ image = Image::FromFile("SampleImage.jpg");
43+
Form::ClientSize = image->Size;
44+
g->DrawImage( image, 0, 0, image->Size.Width, image->Size.Height );
45+
}
46+
```
47+
48+
## <a name="draw"></a> Draw Shapes with the .NET Framework
49+
The following code example uses the <xref:System.Drawing.Graphics> class to modify the <xref:System.Windows.Forms.Form.OnPaint%2A> event handler to retrieve a pointer to the <xref:System.Drawing.Graphics> object for the main form. This pointer is then used to set the background color of the form and draw a line and an arc using the <xref:System.Drawing.Graphics.DrawLine%2A?displayProperty=fullName> and <xref:System.Drawing.Graphics.DrawArc%2A> methods.
50+
51+
### Example
52+
53+
```cpp
54+
#using <system.drawing.dll>
55+
using namespace System;
56+
using namespace System::Drawing;
57+
// ...
58+
protected:
59+
virtual Void Form1::OnPaint(PaintEventArgs^ pe ) override
60+
{
61+
Graphics^ g = pe->Graphics;
62+
g->Clear(Color::AntiqueWhite);
63+
64+
Rectangle rect = Form::ClientRectangle;
65+
Rectangle smallRect;
66+
smallRect.X = rect.X + rect.Width / 4;
67+
smallRect.Y = rect.Y + rect.Height / 4;
68+
smallRect.Width = rect.Width / 2;
69+
smallRect.Height = rect.Height / 2;
70+
71+
Pen^ redPen = gcnew Pen(Color::Red);
72+
redPen->Width = 4;
73+
g->DrawLine(redPen, 0, 0, rect.Width, rect.Height);
74+
75+
Pen^ bluePen = gcnew Pen(Color::Blue);
76+
bluePen->Width = 10;
77+
g->DrawArc( bluePen, smallRect, 90, 270 );
78+
}
79+
```
80+
81+
## <a name="rotate"></a> Rotate Images with the .NET Framework
82+
The following code example demonstrates the use of the <xref:System.Drawing.Image?displayProperty=fullName> class to load an image from disk, rotate it 90 degrees, and save it as a new .jpg file.
83+
84+
### Example
85+
86+
```cpp
87+
#using <system.drawing.dll>
88+
89+
using namespace System;
90+
using namespace System::Drawing;
91+
92+
int main()
93+
{
94+
Image^ image = Image::FromFile("SampleImage.jpg");
95+
image->RotateFlip( RotateFlipType::Rotate90FlipNone );
96+
image->Save("SampleImage_rotated.jpg");
97+
return 0;
98+
}
99+
```
100+
101+
## <a name="convert"></a> Convert Image File Formats with the .NET Framework
102+
The following code example demonstrates the <xref:System.Drawing.Image?displayProperty=fullName> class and the <xref:System.Drawing.Imaging.ImageFormat?displayProperty=fullName> enumeration used to convert and save image files. The following code loads an image from a .jpg file and then saves it in both .gif and .bmp file formats.
103+
104+
### Example
105+
106+
```cpp
107+
#using <system.drawing.dll>
108+
109+
using namespace System;
110+
using namespace System::Drawing;
111+
using namespace System::Drawing::Imaging;
112+
113+
int main()
114+
{
115+
Image^ image = Image::FromFile("SampleImage.jpg");
116+
image->Save("SampleImage.png", ImageFormat::Png);
117+
image->Save("SampleImage.bmp", ImageFormat::Bmp);
118+
119+
return 0;
120+
}
121+
```
27122

28123
## Related Sections
29124
[Getting Started with Graphics Programming](/dotnet/framework/winforms/advanced/getting-started-with-graphics-programming)
30125

31-
[About GDI+ Managed Code](/dotnet/framework/winforms/advanced/about-gdi-managed-code)
32-
33-
<xref:System.Drawing?displayProperty=fullName>
126+
[About GDI+ Managed Code](/dotnet/framework/winforms/advanced/about-gdi-managed-code)
34127

35128
## See Also
36-
[.NET Programming with C++/CLI (Visual C++)](../dotnet/dotnet-programming-with-cpp-cli-visual-cpp.md)
129+
[.NET Programming with C++/CLI (Visual C++)](../dotnet/dotnet-programming-with-cpp-cli-visual-cpp.md)
130+
131+
<xref:System.Drawing>
132+

docs/dotnet/how-to-convert-image-file-formats-with-the-dotnet-framework.md

Lines changed: 0 additions & 38 deletions
This file was deleted.

docs/dotnet/how-to-display-images-with-the-dotnet-framework.md

Lines changed: 0 additions & 41 deletions
This file was deleted.

docs/dotnet/how-to-draw-shapes-with-the-dotnet-framework.md

Lines changed: 0 additions & 49 deletions
This file was deleted.

docs/dotnet/how-to-rotate-images-with-the-dotnet-framework.md

Lines changed: 0 additions & 35 deletions
This file was deleted.

0 commit comments

Comments
 (0)