Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

For a Windows-targeted .NET application using System.Drawing, load the image and call Image.Save with a new destination path and an explicit format, such as ImageFormat.Png. For in-memory output, save to a new MemoryStream. If your application must run on Linux or macOS, do not build on System.Drawing.Common: Microsoft classifies it as Windows-specific in modern .NET.

Save an image to a file with System.Drawing

The basic pattern is to load an image, choose its output path, specify its output format, and dispose of the image when finished:

using System.Drawing;
using System.Drawing.Imaging;

using var image = Image.FromFile("input.jpg");
image.Save("output.png", ImageFormat.Png);

Image.Save has overloads for a filename or a stream. Passing an ImageFormat makes the encoding choice explicit: the example reads a JPEG and writes PNG. Microsoft documents this overload as saving an image to the specified file in the specified format. The code shown here is for Windows-targeted .NET applications; the platform limitation is important and is covered below.

Choose a destination that is not the source

Save to a new destination rather than saving back to the file used to create the image. Microsoft warns that loading and saving to the same file can corrupt data or cause an exception. The same caution applies to streams: do not save an image to the stream used to construct it. When saving to a destination stream, make sure it starts at offset zero.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
#1 Best Overall
Sale
Seagate 2TB Portable Hard Drive | USB 3.0 (STGX2000400)
  • Easily store and access 2TB to content on the go with the Seagate Portable Drive, a USB external hard drive
  • Designed to work with Windows or Mac computers, this external hard drive makes backup a snap just drag and drop
  • To get set up, connect the portable hard drive to a computer for automatic recognition no software required
  • This USB drive provides plug and play simplicity with the included 18 inch USB 3.0 cable
  • The available storage capacity may vary.

In a real application, make the paths explicit and ensure the destination directory exists and is writable. A relative path such as output.png is resolved from the process’s current working directory, which may differ between a command prompt, IDE, desktop app, and service. If a file seems to disappear, inspect the resolved path rather than assuming it was written beside the source image.

Choose PNG, JPEG, BMP, or GIF

The format parameter controls how the image is encoded. Pick a format based on what the output needs to preserve, not just the input extension.

Format Good fit Trade-off
PNG Lossless output or transparency Often not the preferred compact format for photographic images.
JPEG Photographic content when lossy compression is acceptable Compression is lossy; use encoder settings when you need to control quality.
BMP Cases that specifically require an uncompressed Windows bitmap Uncompressed output is not a sensible default for most web or storage use.
GIF When GIF output is specifically required The supplied Microsoft material documents the format option but does not establish its suitability for a particular image or animation workflow.

For a basic conversion, use the matching format constant:

image.Save("output.png", ImageFormat.Png);
image.Save("output.jpg", ImageFormat.Jpeg);
image.Save("output.bmp", ImageFormat.Bmp);
image.Save("output.gif", ImageFormat.Gif);

Use an extension that reflects the format you explicitly selected. Do not rely on the extension alone to express your intent: in code, specify the desired ImageFormat so the encoder choice is unambiguous.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Control JPEG quality with an encoder

The simple ImageFormat.Jpeg overload is convenient when the default encoder settings are acceptable. If you need to request a JPEG quality value, find the JPEG codec and pass an EncoderParameters object to the codec overload:

Rank #2
Seagate Portable 5TB External Hard Drive HDD – USB 3.0 for PC, Mac, PS4, & Xbox - 1-Year Rescue Service (STGX5000400), Black
  • Easily store and access 5TB of content on the go with the Seagate portable drive, a USB external hard Drive
  • Designed to work with Windows or Mac computers, this external hard drive makes backup a snap just drag and drop
  • To get set up, connect the portable hard drive to a computer for automatic recognition software required
  • This USB drive provides plug and play simplicity with the included 18 inch USB 3.0 cable
  • The available storage capacity may vary.
using System.Drawing;
using System.Drawing.Imaging;
using System.Linq;

using var image = Image.FromFile("photo.png");
var jpegCodec = ImageCodecInfo.GetImageEncoders()
    .First(codec => codec.FormatID == ImageFormat.Jpeg.Guid);

using var parameters = new EncoderParameters(1);
parameters.Param[0] = new EncoderParameter(Encoder.Quality, 85L);
image.Save("photo.jpg", jpegCodec, parameters);

The example requests quality value 85 through the JPEG encoder. It is a setting passed to the encoder, not a promise of a particular file size or visual result; those depend on the image and encoder. Use a representative set of images to decide what value is acceptable for your application. The codec overload is the option to use for JPEG quality or other encoder-specific parameters documented by Microsoft.

Save to a MemoryStream or byte array

When the next step needs bytes rather than a file—for example, handing encoded data to another part of the application—save to a new stream and then obtain its bytes:

using System.Drawing;
using System.Drawing.Imaging;
using System.IO;

using var image = Image.FromFile("input.jpg");
using var output = new MemoryStream();
image.Save(output, ImageFormat.Png);
byte[] bytes = output.ToArray();

The stream is created separately from the input image, so it avoids the same-stream hazard. It is new and positioned at offset zero when the save begins. ToArray gives you the encoded PNG data; it does not turn the output into a file by itself. Keep or pass the byte array to the component that needs it, or write it to a file if persistent storage is the goal.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

When an API specifically accepts a stream, you can pass the stream itself after saving rather than creating a byte array. Be mindful of stream position: if another consumer expects to read from the beginning, reset the position before handing it over. Dispose of the stream after all consumers have finished with it.

Use WPF encoders in a WPF application

WPF has a different encoding model. Use a BitmapEncoder such as PngBitmapEncoder or JpegBitmapEncoder, add a BitmapFrame, and write the encoder output to a file stream. For a PNG:

Rank #3
Seagate Portable 1TB External Hard Drive HDD – USB 3.0 for PC, Mac, PlayStation, & Xbox, 1-Year Rescue Service (STGX1000400) , Black
  • Easily store and access 1TB to content on the go with the Seagate Portable Drive, a USB external hard drive.Specific uses: Personal
  • Designed to work with Windows or Mac computers, this external hard drive makes backup a snap just drag and drop. Reformatting may be required for Mac
  • To get set up, connect the portable hard drive to a computer for automatic recognition no software required
  • This USB drive provides plug and play simplicity with the included 18 inch USB 3.0 cable
  • The available storage capacity may vary.
using System.IO;
using System.Windows.Media.Imaging;

var encoder = new PngBitmapEncoder();
encoder.Frames.Add(BitmapFrame.Create(bitmapSource));
using var file = File.Create("output.png");
encoder.Save(file);

Here bitmapSource is the WPF bitmap source you already have. To save JPEG instead, use JpegBitmapEncoder. This is the WPF route for WPF bitmap objects; it is not a drop-in replacement for a System.Drawing.Image. Keep the two API models distinct when choosing an implementation.

Check the platform before choosing System.Drawing

Modern .NET’s System.Drawing.Common is Windows-specific. Microsoft’s .NET 6 breaking-change guidance states that the package is now attributed as a Windows-specific library. In .NET 7, the compatibility switch that had enabled Unix support was removed. Consequently, a solution that appears to work on Windows should not be treated as a supported Linux or macOS image-processing strategy.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

For cross-platform applications, Microsoft lists ImageSharp, SkiaSharp, Aspose.Drawing, and Microsoft.Maui.Graphics as alternatives. The right choice depends on the platforms you deploy to, required formats and operations, performance needs, licensing, and support requirements. No official comparative benchmark is established here, so there is no basis to claim that one of these libraries is universally fastest or smallest. Check each library’s current documentation and licensing for your target environment before adopting it.

Match the API to the app

  • Windows-only utility or desktop app: System.Drawing is the straightforward choice for the file and stream examples above.
  • WPF app using WPF bitmap objects: use WPF’s BitmapEncoder model rather than trying to treat a WPF bitmap as a System.Drawing.Image.
  • Service or web app deployed across operating systems: choose a library intended for the actual deployment platforms. Validate the formats and operations you need, and verify licensing and runtime dependencies.
  • Unknown or changing deployment environment: confirm the host OS and .NET version before selecting the image library. A successful Windows development run does not establish Linux compatibility.

Common failures and how to diagnose them

The app throws when saving over the input

Cause: the source image was loaded from the same file being used as the destination. Fix: save to a different path. If replacing the original is a requirement, first encode to a separate file or stream and handle replacement as a separate operation after the source is no longer needed.

A stream save fails or produces unusable output

Cause: the destination is the same stream used to construct the image, or the destination stream is not positioned at its beginning. Fix: create a distinct output stream and start it at offset zero. If a later reader consumes a stream you have written, reset its position when that reader expects to start at the beginning.

Rank #4
Seagate Portable 4TB External Hard Drive HDD – USB 3.0, 1-Year Rescue
  • Easily store and access 4TB of content on the go with the Seagate Portable Drive, a USB external hard drive.Specific uses: Personal
  • Designed to work with Windows or Mac computers, this external hard drive makes backup a snap just drag and drop
  • To get set up, connect the portable hard drive to a computer for automatic recognition no software required
  • This USB drive provides plug and play simplicity with the included 18 inch USB 3.0 cable
  • The available storage capacity may vary.

The output is not the format you expected

Cause: the code did not explicitly choose the encoder, or the filename and selected format do not agree. Fix: pass the intended ImageFormat (or the relevant codec and parameters) and use a matching extension. For JPEG quality control, use the JPEG codec overload rather than assuming a filename changes encoder settings.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

System.Drawing works locally but fails on Linux or macOS

Cause: the application relies on System.Drawing.Common outside its supported Windows platform boundary. Fix: use a cross-platform alternative such as ImageSharp, SkiaSharp, Aspose.Drawing, or Microsoft.Maui.Graphics, selected for your platform and requirements. The removed .NET 7 Unix compatibility switch is not a durable workaround.

The file cannot be created at the chosen path

Cause: the process may be running from a different working directory than expected, or the destination location may not be writable. Fix: inspect the full resolved output path, create the parent directory when appropriate, and confirm the application identity has permission to write there. These are file-system conditions, separate from image encoding.

Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Performance, reliability, and cost considerations

Saving does encoding work and may consume memory for the decoded image plus the output representation. A stream or byte-array workflow can avoid an intermediate file but does not make image encoding free; use the form that fits the next consumer. Avoid holding more image and output data in memory than your workload requires, and dispose of disposable image, stream, codec-parameter, and file objects when they are no longer needed.

For a server workload, account for the operating system and deployment model before release. Choosing a Windows-specific API for a service that may move to Linux creates an operational failure mode, not merely a code-style concern. On a cross-platform library, validate the real input types, output formats, quality settings, and concurrency requirements in the target environment. There is no benchmark in the cited Microsoft material to support a generic throughput comparison among the alternatives.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Best Value
Sale
UnionSine 500GB Ultra Slim Portable External Hard Drive HDD-USB 3.0
  • [Upgraded Version] - This external hard drive features a mirrored logo stripe combined with a striped anti-slip design, and the rounded corners of the casing make it easier to grip. The stripes also have a heat dissipation function, ensuring stable and fast data transfer.
  • 【Ultra-thin and quiet】 - The motherboard adopts JMicron 578 noise-free solution, giving you a quiet working environment. Lightweight and portable size designed to fit in your pocket for easy portability.
  • 【Ultra-Fast Data Transfers】 - Pairing this external hard drive with JMicron 578 solution USB 3.0 and USB 2.0 interfaces enables blazing-fast data transfer. It boasts theoretical read speeds of up to 125MB/s and write speeds of up to 103MB/s.
  • 【Plug and Play】 - With no software to install, just plug it in and the drive is ready to use.The hard disk chip is wrapped with an aluminum anti-interference layer to increase heat dissipation and protect data.
  • 【What You Get】 - 1 x Portable Hard Drive, 1 x USB 3.0 Cable, 1 x User Manual, Gift-type shell packaging ,Three-year manufacturer's warranty and free technical support services.

Or skip the browser setup

If the image you need is a capture of a web page rather than an image already in your C# application, ScreenshotNeo is a website screenshot API and MCP server. One GET request can return PNG, JPEG, WebP, or PDF. For a direct command-line capture, use the documented endpoint and parameter pattern:

curl -G "https://api.screenshotneo.com/v1/shot" -d access_key=YOUR_API_KEY --data-urlencode url=https://stripe.com -o shot.webp

See the ScreenshotNeo API documentation for request options. ScreenshotNeo accepts cookie and consent banners before capture and removes 60+ known consent platforms, newsletter popups, and chat widgets; each step can be turned off. Bot checks, blank pages, timeouts, failed loads, and cache hits cost nothing, and response headers indicate the page verdict and billing status. Its MCP server provides take_screenshot, get_page_info, and capture_pdf tools for AI agents. The free plan includes 1,000 screenshots a month with no card; paid plans start at $5 for 3,000 shots. Learn about ScreenshotNeo or sign up for 1,000 free screenshots a month with no card.

Frequently Asked Questions

Does renaming a saved image change its encoding?

No. A filename extension does not transcode image data. Choose the intended format in the save call, then give the output a matching extension.

Can I use the System.Drawing examples in a cross-platform .NET project?

Not as a supported modern .NET solution on Linux or macOS. Microsoft identifies System.Drawing.Common as Windows-specific; choose a library intended for your deployment platforms.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Is there a universally fastest cross-platform image library?

No universal winner is established by the available Microsoft material. Compare the libraries against your platform, format, licensing, support, and workload requirements.

Quick Recap

SaleBestseller No. 1
Seagate 2TB Portable Hard Drive | USB 3.0 (STGX2000400)
Seagate 2TB Portable Hard Drive | USB 3.0 (STGX2000400)
This USB drive provides plug and play simplicity with the included 18 inch USB 3.0 cable; The available storage capacity may vary.
$129.99
Bestseller No. 2
Seagate Portable 5TB External Hard Drive HDD – USB 3.0 for PC, Mac, PS4, & Xbox - 1-Year Rescue Service (STGX5000400), Black
Seagate Portable 5TB External Hard Drive HDD – USB 3.0 for PC, Mac, PS4, & Xbox - 1-Year Rescue Service (STGX5000400), Black
This USB drive provides plug and play simplicity with the included 18 inch USB 3.0 cable; The available storage capacity may vary.
$229.99
Bestseller No. 3
Seagate Portable 1TB External Hard Drive HDD – USB 3.0 for PC, Mac, PlayStation, & Xbox, 1-Year Rescue Service (STGX1000400) , Black
Seagate Portable 1TB External Hard Drive HDD – USB 3.0 for PC, Mac, PlayStation, & Xbox, 1-Year Rescue Service (STGX1000400) , Black
This USB drive provides plug and play simplicity with the included 18 inch USB 3.0 cable; The available storage capacity may vary.
$119.80
Bestseller No. 4
Seagate Portable 4TB External Hard Drive HDD – USB 3.0, 1-Year Rescue
Seagate Portable 4TB External Hard Drive HDD – USB 3.0, 1-Year Rescue
This USB drive provides plug and play simplicity with the included 18 inch USB 3.0 cable; The available storage capacity may vary.
$189.98

Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.