Convert image formats with PowerShell and System.Drawing
Turn any PNG into JPEG, BMP into PNG, and more using .NET's built-in imaging library — scriptable, batchable, zero third-party tools.
01Command
$ Add-Type -AssemblyName System.Drawing; $img=[System.Drawing.Image]::FromFile("C:\pics\photo.png"); $img.Save("C:\pics\photo.jpg",[System.Drawing.Imaging.ImageFormat]::Jpeg); $img.Dispose()02What it does
System.Drawing's Image class decodes the source file and Bitmap.Save re-encodes it into the ImageFormat you name, all inside PowerShell without installing anything. Batch it by wrapping in a loop: `Get-ChildItem *.png | ForEach-Object { $i=[System.Drawing.Image]::FromFile($_.FullName); $i.Save($_.FullName -replace '\.png$','.jpg'), [System.Drawing.Imaging.ImageFormat]::Jpeg; $i.Dispose() }` — always Dispose to release the file handle. Note the quality trade-offs: converting PNG to JPEG flattens transparency to black or a chosen background, and JPEG is lossy; set JPEG quality via an EncoderParameters object if file size matters. This must run in Windows PowerShell 5.1, since System.Drawing.Common is unsupported in .NET Core on non-Windows and restricted in newer .NET versions.
03Risk
04Undo
✓No undo needed — this command does not change persistent state.
05Sources
- System.Drawing.Bitmap class | Microsoft LearnEvidence: Microsoft documents the System.Drawing Bitmap class and its Save method for writing images in formats such as JPEG, PNG and BMP.
Last verified: 2026-09-17 · Category: Media
06Related solutions
One pipeline that renames every matching file in a folder using regular expressions — safer and far more flexible than third-party renamers.
The built-in file compare tool reports whether two text or binary files differ and shows every mismatching byte with its hex offset.
A script-driven screenshot: grab the entire virtual desktop (all monitors) and write it to a timestamped PNG — useful for monitoring, unattended tasks, and scheduled captures.