次の方法で共有


How to: Convert Image File Formats with the .NET Framework

 

The new home for Visual Studio documentation is Visual Studio 2017 Documentation on docs.microsoft.com.

For the latest documentation on Visual Studio 2017, see How to: Convert Image File Formats with the .NET Framework on docs.microsoft.com.

The following code example demonstrates the System.Drawing.Image class and the System.Drawing.Imaging.ImageFormat 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.

Note

GDI+ is included with Windows XP, Windows Server 2003, and Windows Vista and is available as a redistributable for Windows 2000. To download the latest redistributable, see https://go.microsoft.com/fwlink/?linkid=11232.

Example

#using <system.drawing.dll>  
  
using namespace System;  
using namespace System::Drawing;  
using namespace System::Drawing::Imaging;  
  
int main()  
{  
   Image^ image = Image::FromFile("SampleImage.jpg");  
   image->Save("SampleImage.png", ImageFormat::Png);  
   image->Save("SampleImage.bmp", ImageFormat::Bmp);  
  
   return 0;  
}  

See Also

System.Drawing
.NET Programming with C++/CLI (Visual C++)