如何使用ImageSharp提取jpeg的EXIF缩略图? [英] How do I extract a jpeg's EXIF thumbnail using ImageSharp?

查看:0
本文介绍了如何使用ImageSharp提取jpeg的EXIF缩略图?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试从源jpeg中提取缩略图,并使用C#ImageSharp库将它们保存到文件系统。我看到在组件的智能感知中有一些提到它: SixLabors.ImageSharp.Image.Metadata.ExifProfile.CreateThumbnail()

...但我似乎找不到正确调用它的任何文档或示例。

我确实找到了这个:

using SixLabors.ImageSharp;
using SixLabors.ImageSharp.PixelFormats;
using SixLabors.ImageSharp.Processing;  

//method code:
Image<TPixel> thumbnail = image.Metadata.ExifProfile.CreateThumbnail<TPixel>();

https://docs.sixlabors.com/api/ImageSharp/SixLabors.ImageSharp.Metadata.Profiles.Exif.ExifProfile.html

...但我需要找到TPixel类型的位置才能使其工作。VisualStudio无法识别它,我似乎无法找到命名空间或正确使用它:

找不到类型或命名空间名称‘TPixel’(是否缺少Using指令或程序集引用?)

旧版Windows.NET框架可以为System.Drawing.Image.Image.GetThumbnailImage()执行此操作,并且运行良好。

编辑:使用tocsoft的答案,我将代码更改为:

if (image.Metadata.ExifProfile != null)
{
    Image<Rgba32> thumbnail = image.Metadata.ExifProfile.CreateThumbnail<Rgba32>();

    thumbnail.Save(thumbnailPath, encoder);
}

...但是,image.Metadata.ExifProfile为空,这是意外的,因为我知道这些源图像具有EXIF数据。

编辑:实际上,它现在正在工作。成功了!谢谢!

推荐答案

TPixel将是SixLabors.ImageSharp.PixelFormats命名空间中的任何像素格式。但是,除非您计划与其他需要以特定方式在内存中放置像素数据的系统进行互操作,否则您可能只想使用Rgba32

Image<Rgba32> thumbnail = image.Metadata.ExifProfile.CreateThumbnail<Rgba32>();

这篇关于如何使用ImageSharp提取jpeg的EXIF缩略图?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆