---
title: "Remove EXIF metadata from an image in C#"
url: https://recursiveai.org/oneimage/cookbook/remove-exif-metadata/
description: "Remove EXIF data, including the GPS location, from photos in C# before you publish them, keeping the photo upright and its colors right. Runnable code with OneImage."
version: "1.10.4"
---

# Remove EXIF metadata from an image in C#

Load the photo, call `StripMetadata()`, and save. The new file has no EXIF, XMP or IPTC block, so no GPS position, camera serial or capture time. `Load` has already turned the photo upright, so removing the orientation tag doesn’t turn it sideways. The program below cleans a Nikon photo with GPS from the public [exif-samples](https://github.com/ianare/exif-samples) collection.

```shell
dotnet new console -o StripExif && cd StripExif
dotnet add package RecursiveAI.OneImage --version 1.10.4
repo=https://raw.githubusercontent.com/ianare/exif-samples/master
curl -L -o gps.jpg $repo/jpg/gps/DSCN0010.jpg
```

OneImage needs the .NET 10 SDK. Put this in `Program.cs` and run `dotnet run`:

```csharp
using OneImage;

static void Show(string file)
{
    ExifData? exif = Image.Identify(file).Metadata.ReadExif();
    string gps = exif?.Gps is GpsPosition p
        ? $"{p.Latitude:F4}, {p.Longitude:F4}" : "none";
    string block = exif is null ? "none" : "present";
    Console.WriteLine($"{file}: EXIF {block}, GPS {gps}");
}

Show("gps.jpg");

// Everything but the pixels goes; keepIcc: true keeps the color profile.
Image.Load("gps.jpg").StripMetadata(keepIcc: true).Save("public.jpg");
Show("public.jpg");
```

```text
gps.jpg: EXIF present, GPS 43.4674, 11.8851
public.jpg: EXIF none, GPS none
```

`StripMetadata()` without arguments also drops the ICC color profile, which can shift the colors of photos in wide-gamut spaces such as Adobe RGB; `keepIcc: true` keeps it.

## Strip and resize in one call

For web copies, `Image.Thumbnail` resizes, turns the photo upright, converts it to sRGB (so the colors stay right without the original profile) and removes EXIF, XMP and IPTC:

```csharp
using OneImage;

Image.Thumbnail("gps.jpg", 400).Save("thumb.jpg");
bool hasExif = Image.Identify("thumb.jpg").Metadata.ReadExif() is not null;
Console.WriteLine($"thumb.jpg: {(hasExif ? "EXIF present" : "no EXIF")}");
```

```text
thumb.jpg: no EXIF
```

## Limits

- **The file is re-encoded.** Removing metadata this way decodes and encodes the JPEG again, at quality 75 unless you set `JpegEncoderOptions.Quality`. OneImage doesn’t rewrite a JPEG’s metadata in place.
- **It’s all or nothing.** You can keep the ICC profile, but not, say, the copyright field alone. To keep everything except a few tags, use a dedicated EXIF editor.
- **Plain `Load` and `Save` keep metadata**, GPS included, so stripping has to be explicit, unless you use `Thumbnail`.

To read the fields before removing them, see [Read EXIF data](https://recursiveai.org/oneimage/cookbook/read-exif-data/). Metadata handling is in the [guide](https://recursiveai.org/oneimage/docs/guide/#metadata).
