From 8068d80b5bd212601921faa300ac09a960a4b415 Mon Sep 17 00:00:00 2001 From: Dirk Lemstra Date: Thu, 9 Nov 2023 20:11:51 +0100 Subject: [PATCH] Added example about reading a thumbnail from a raw image. --- Magick.NET.sln | 1 + docs/ReadRawThumbnail.md | 29 +++++++++++++++ docs/Readme.md | 2 + .../Magick.NET.Samples/ReadRawThumbnail.cs | 37 +++++++++++++++++++ 4 files changed, 69 insertions(+) create mode 100644 docs/ReadRawThumbnail.md create mode 100644 samples/Magick.NET.Samples/ReadRawThumbnail.cs diff --git a/Magick.NET.sln b/Magick.NET.sln index ec43509fa6..69f5a04c69 100644 --- a/Magick.NET.sln +++ b/Magick.NET.sln @@ -36,6 +36,7 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "docs", "docs", "{6D1DE15B-E docs\LosslessCompression.md = docs\LosslessCompression.md docs\ReadingImages.md = docs\ReadingImages.md docs\Readme.md = docs\Readme.md + docs\ReadRawThumbnail.md = docs\ReadRawThumbnail.md docs\ResizeImage.md = docs\ResizeImage.md docs\UsingColors.md = docs\UsingColors.md docs\Watermark.md = docs\Watermark.md diff --git a/docs/ReadRawThumbnail.md b/docs/ReadRawThumbnail.md new file mode 100644 index 0000000000..e921f74e55 --- /dev/null +++ b/docs/ReadRawThumbnail.md @@ -0,0 +1,29 @@ +# Read raw thumbnail + +## Read thumbnail from raw image + +```C# +// Setup DNG read defines +var defines = new DngReadDefines +{ + ReadThumbnail = true +}; + +// Create empty image +using var image = new MagickImage(); + +// Copy the defines to the settings +image.Settings.SetDefines(defines); + +// Read only meta data of the image +image.Ping(SampleFiles.StillLifeCR2); + +// Get thumbnail data +var thumbnailData = image.GetProfile("dng:thumbnail")?.GetData(); + +if (thumbnailData != null) +{ + // Read the thumbnail image + using var thumbnail = new MagickImage(thumbnailData); +} +``` diff --git a/docs/Readme.md b/docs/Readme.md index 1c0c3787ab..7104c543f6 100644 --- a/docs/Readme.md +++ b/docs/Readme.md @@ -108,6 +108,8 @@ provide you with some help on how to use Magick.NET. - [Exif data](ExifData.md) - Read exif data - Create thumbnail from exif data +- [Read raw thumbnail](ReadRawThumbnail.md) + - Read thumbnail from raw image - [Lossless compression](LosslessCompression.md) - Lossless compress JPEG logo - [Detailed debug information](DetailedDebugInformation.md) diff --git a/samples/Magick.NET.Samples/ReadRawThumbnail.cs b/samples/Magick.NET.Samples/ReadRawThumbnail.cs new file mode 100644 index 0000000000..ed0b2f0969 --- /dev/null +++ b/samples/Magick.NET.Samples/ReadRawThumbnail.cs @@ -0,0 +1,37 @@ +// Copyright Dirk Lemstra https://github.com/dlemstra/Magick.NET. +// Licensed under the Apache License, Version 2.0. + +using ImageMagick; +using ImageMagick.Formats; + +namespace Magick.NET.Samples; + +public static class ReadRawThumbnailSamples +{ + public static void ReadRawThumbnail() + { + // Setup DNG read defines + var defines = new DngReadDefines + { + ReadThumbnail = true + }; + + // Create empty image + using var image = new MagickImage(); + + // Copy the defines to the settings + image.Settings.SetDefines(defines); + + // Read only meta data of the image + image.Ping(SampleFiles.StillLifeCR2); + + // Get thumbnail data + var thumbnailData = image.GetProfile("dng:thumbnail")?.GetData(); + + if (thumbnailData != null) + { + // Read the thumbnail image + using var thumbnail = new MagickImage(thumbnailData); + } + } +}