我正在尝试从源jpegs中提取缩略图,并使用C# ImageSharp库将它们保存到文件系统中。我看到在组件的intellisense中提到了它: SixLabors.ImageSharp.Image.Metadata.ExifProfile.CreateThumbnail()
...but我似乎找不到它的任何文档或例子来正确地调用它。
我确实找到了这个:
using SixLabors.ImageSharp;
using SixLabors.ImageSharp.PixelFormats;
using SixLabors.ImageSharp.Processing;
//method code:
Image<TPixel> thumbnail = image.Metadata.ExifProfile.CreateThumbnail<TPixel>();...but --我需要找到TPixel类型的位置才能让它工作。VisualStudio不认识它,我似乎无法找到名称空间或正确地使用它:
“无法找到类型或命名空间名称'TPixel‘(您是缺少使用指令还是程序集引用?)
传统的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);
}...however,image.Metadata.ExifProfile是null,这是意外的,因为我知道这些源图像有EXIF数据。
编辑:实际上,它现在起作用了。成功!谢谢!
发布于 2022-02-12 20:53:09
TPixel将是SixLabors.ImageSharp.PixelFormats命名空间中的任何像素格式。但是,除非您计划与其他需要以特定方式放置在内存中的像素数据的系统进行互操作,否则您可能只想使用Rgba32。
Image<Rgba32> thumbnail = image.Metadata.ExifProfile.CreateThumbnail<Rgba32>();https://stackoverflow.com/questions/71095559
复制相似问题