本文整理汇总了C#中System.Drawing.Bitmap.SetPropertyItem方法的典型用法代码示例。如果您正苦于以下问题:C# System.Drawing.Bitmap.SetPropertyItem方法的具体用法?C# System.Drawing.Bitmap.SetPropertyItem怎么用?C# System.Drawing.Bitmap.SetPropertyItem使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Drawing.Bitmap
的用法示例。
在下文中一共展示了System.Drawing.Bitmap.SetPropertyItem方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: AddMetaValuesBackToRotatedImage
/// <summary>
/// Add the <paramref name="metaValues" /> back to the <paramref name="filePath" />.
/// </summary>
/// <param name="filePath">The full path to the file.</param>
/// <param name="metaValues">The property items. If null, no action is taken.</param>
private void AddMetaValuesBackToRotatedImage(string filePath, System.Drawing.Imaging.PropertyItem[] metaValues)
{
if (metaValues == null)
return;
// Create a copy of the file and add the metadata to it.
string tmpImagePath;
using (var targetImage = new System.Drawing.Bitmap(filePath))
{
foreach (var propertyItem in metaValues)
{
// Don't copy width, height or orientation meta items.
var metasToNotCopy = new[]
{
RawMetadataItemName.ImageWidth,
RawMetadataItemName.ImageHeight,
RawMetadataItemName.ExifPixXDim,
RawMetadataItemName.ExifPixYDim,
RawMetadataItemName.Orientation
};
if (Array.IndexOf(metasToNotCopy, (RawMetadataItemName)propertyItem.Id) >= 0)
continue;
targetImage.SetPropertyItem(propertyItem);
}
// Save image to temporary location. We can't overwrite the original path because the Bitmap has a lock on it.
tmpImagePath = Path.Combine(AppSetting.Instance.TempUploadDirectory, String.Concat(Guid.NewGuid().ToString(), ".jpg"));
ImageHelper.SaveImageToDisk(targetImage, tmpImagePath, System.Drawing.Imaging.ImageFormat.Jpeg, GallerySettings.OriginalImageJpegQuality);
}
// Now that the original file is freed up, delete it and move the temp file into its place.
if (File.Exists(filePath))
File.Delete(filePath);
File.Move(tmpImagePath, filePath);
}