当前位置: 首页>>代码示例>>C#>>正文


C# System.Drawing.Bitmap.SetPropertyItem方法代码示例

本文整理汇总了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);
        }
开发者ID:Jiyuu,项目名称:galleryserverpro,代码行数:43,代码来源:DisplayObjectCreator.cs


注:本文中的System.Drawing.Bitmap.SetPropertyItem方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。