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


C# Image.SetPropertyItem方法代码示例

本文整理汇总了C#中System.Drawing.Image.SetPropertyItem方法的典型用法代码示例。如果您正苦于以下问题:C# Image.SetPropertyItem方法的具体用法?C# Image.SetPropertyItem怎么用?C# Image.SetPropertyItem使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在System.Drawing.Image的用法示例。


在下文中一共展示了Image.SetPropertyItem方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: AddMetadata

        public static bool AddMetadata(Image img, int id, string text)
        {
            PropertyItem pi;

            try
            {
                pi = (PropertyItem)typeof(PropertyItem).GetConstructor(BindingFlags.Instance | BindingFlags.NonPublic, null, new Type[] { }, null).Invoke(null);
                pi.Id = id;
                pi.Len = text.Length + 1;
                pi.Type = 2;
                byte[] bytesText = Encoding.ASCII.GetBytes(text + " ");
                bytesText[bytesText.Length - 1] = 0;
                pi.Value = bytesText;

                if (pi != null)
                {
                    img.SetPropertyItem(pi);
                    return true;
                }
            }
            catch (Exception e)
            {
                DebugHelper.WriteException(e, "Reflection fail");
            }

            return false;
        }
开发者ID:sides,项目名称:sharexl,代码行数:27,代码来源:ImageHelpers.cs

示例2: Copy

 public static void Copy(Image source, Image target)
 {
     foreach (var propertyItem in source.PropertyItems)
     {
         target.SetPropertyItem(propertyItem);
     }
 }
开发者ID:GorelH,项目名称:FluentImageResizing,代码行数:7,代码来源:ImagePropertyItems.cs

示例3: CopyEXIF

 public static void CopyEXIF(Image from, Image to)
 {
     // This should work most the time.  Could on Vista and below get
     // some improved results with WIC
     foreach (PropertyItem pi in from.PropertyItems)
     {
         to.SetPropertyItem(pi);
     }
 }
开发者ID:gmilazzoitag,项目名称:OpenLiveWriter,代码行数:9,代码来源:ImageUtils.cs

示例4: SetPropertyItemString

 private static void SetPropertyItemString(Image srcImg, ImageMetadataPropertyId id, string value)
 {
     var buffer = Encoding.Unicode.GetBytes(value);
     var propItem = srcImg.GetPropertyItem(srcImg.PropertyItems[0].Id);
     propItem.Id = (int)id;
     propItem.Type = 1;
     propItem.Len = buffer.Length;
     propItem.Value = buffer;
     srcImg.SetPropertyItem(propItem);
 }
开发者ID:BlythMeister,项目名称:BingImageDowload,代码行数:10,代码来源:ImagePropertyHandling.cs

示例5: SaveThumbnail

		public static void SaveThumbnail(Image thumb, ushort rating, string filePath)
		{
			string thumbPath = GetThumbPath(filePath);
			if (ratingProperty == null)
			{
				System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(ThumbUtility));
				ratingProperty = ((System.Drawing.Image)(resources.GetObject("rating"))).GetPropertyItem(18246);
			}
			ratingProperty.Value = BitConverter.GetBytes(rating);
			thumb.SetPropertyItem(ratingProperty);
			thumb.Save(thumbPath, ImageFormat.Jpeg);
		}
开发者ID:ericpony,项目名称:comic-gallery,代码行数:12,代码来源:ThumbUtility.cs

示例6: AddDescriptionToImage

        private static void AddDescriptionToImage(Image image, string description)
        {
            //create a new property item
            var newItem = (PropertyItem)FormatterServices.GetUninitializedObject(typeof(PropertyItem));
            // Change the ID of the PropertyItem. to description
            newItem.Id = 0x010E;
            newItem.Value = Encoding.UTF8.GetBytes(description);
            newItem.Len = newItem.Value.Length;
            newItem.Type = 1;//byte array

            // Set the PropertyItem for the image.
            image.SetPropertyItem(newItem);
        }
开发者ID:drasockalypse,项目名称:BingBackground,代码行数:13,代码来源:BingBackground.cs

示例7: WriteExifString

        private static void WriteExifString(Image image, int id, string value)
        {
            var data = new byte[value.Length + 1];
            Encoding.ASCII.GetBytes(value, 0, value.Length, data, 0);

            PropertyItem property = image.PropertyItems[0];
            property.Id = id;
            property.Type = PropertyTagTypeAscii;
            property.Len = data.Length;
            property.Value = data;

            image.SetPropertyItem(property);
        }
开发者ID:jcmcbeth,项目名称:pialpr,代码行数:13,代码来源:AlrpFileLogger.cs

示例8: SetPropertyItems

        public static void SetPropertyItems(Image image, PropertyItem[] items)
        {
            PropertyItem[] pis = image.PropertyItems;

            foreach (PropertyItem pi in pis)
            {
                image.RemovePropertyItem(pi.Id);
            }

            foreach (PropertyItem pi in items)
            {
                image.SetPropertyItem(pi);
            }
        }
开发者ID:metadeta96,项目名称:openpdn,代码行数:14,代码来源:PdnGraphics.cs

示例9: CopyExif

        /// <summary>
        /// Copies the EXIF data into the new image and adjusts the Width and Height 
        /// accordingly.
        /// </summary>
        /// <param name="oldImage"></param>
        /// <param name="newImage"></param>
        private static void CopyExif(Image oldImage, Image newImage)
        {
            foreach (PropertyItem property in oldImage.PropertyItems) {
                if (property.Id == EXIF_HEIGHT_ID) {
                    byte[] newHeight = BitConverter.GetBytes(newImage.Height);
                    property.Value = newHeight;
                } else if (property.Id == EXIF_WIDTH_ID) {
                    byte[] newWidth = BitConverter.GetBytes(newImage.Width);
                    property.Value = newWidth;
                }

                newImage.SetPropertyItem(property);
            }
        }
开发者ID:ivanz,项目名称:PicasaUploader,代码行数:20,代码来源:ImageScaler.cs

示例10: SaveToImage

        /// <summary>
        /// Embed the data into given image in memory.
        /// NOTE: You will still need to save the image to disk yourself
        /// </summary>
        /// <param name="image">Image in memory in which to write the embedded data</param>
        /// <exception cref="System.Exception">Not all image data was given correctly.</exception>
        public void SaveToImage(Image image)
        {
            if (image.PropertyItems.Length == 0)
                throw new Exception("No property items detected on the given Image object.");

            PropertyItem tempPropItem = image.PropertyItems[0];
            byte[] b_Time = new byte[24];
            byte[] justOne = BitConverter.GetBytes(1);
            byte[] temp = BitConverter.GetBytes(GPSHours);
            Array.Copy(temp, 0, b_Time, 0, 4);
            Array.Copy(justOne, 0, b_Time, 4, 4);
            temp = BitConverter.GetBytes(GPSMinutes);
            Array.Copy(temp, 0, b_Time, 8, 4);
            Array.Copy(justOne, 0, b_Time, 12, 4);
            int[] frac = ConvertToFraction(GPSSeconds);
            Array.Copy(BitConverter.GetBytes(frac[0]), 0, b_Time, 16, 4);
            Array.Copy(BitConverter.GetBytes(frac[1]), 0, b_Time, 20, 4);
            tempPropItem.Id = (int)ProportyItemId.gpsTime;
            tempPropItem.Type = 5;
            tempPropItem.Len = b_Time.Length;
            tempPropItem.Value = b_Time;
            image.SetPropertyItem(tempPropItem);

            if (!String.IsNullOrEmpty(CameraModel))
            {
                byte[] byteoriginal = asciiEncoder.GetBytes(CameraModel);
                byte[] bytes = new byte[(byteoriginal.Length + 1)];
                Array.Copy(byteoriginal, 0, bytes, 0, byteoriginal.Length);
                bytes[(bytes.Length - 1)] = 0;
                tempPropItem.Id = (int)ProportyItemId.cameraModel;
                tempPropItem.Type = 2;
                tempPropItem.Len = bytes.Length;
                tempPropItem.Value = bytes;
                image.SetPropertyItem(tempPropItem);
            }

            byte[] latBytes = GetBytesGPSLatitude();
            tempPropItem.Id = (int)ProportyItemId.gpsLat;
            tempPropItem.Type = 5;
            tempPropItem.Len = latBytes.Length;
            tempPropItem.Value = latBytes;
            image.SetPropertyItem(tempPropItem);

            byte[] longBytes = GetBytesGPSLongitude();
            tempPropItem.Id = (int)ProportyItemId.gpsLong;
            tempPropItem.Type = 5;
            tempPropItem.Len = longBytes.Length;
            tempPropItem.Value = longBytes;
            image.SetPropertyItem(tempPropItem);

            byte[] b_AltRef = new byte[] { 0x0 };
            tempPropItem.Id = (int)ProportyItemId.gpsAltRef;
            tempPropItem.Type = 1;
            tempPropItem.Len = 1;
            tempPropItem.Value = b_AltRef;
            image.SetPropertyItem(tempPropItem);

            byte[] latRefBytes = new byte[2];
            latRefBytes[0] = asciiEncoder.GetBytes(GPSLatitudeRef)[0];
            tempPropItem.Id = (int)ProportyItemId.gpsLatRef;
            tempPropItem.Type = 2;
            tempPropItem.Len = latRefBytes.Length;
            tempPropItem.Value = latRefBytes;
            image.SetPropertyItem(tempPropItem);

            byte[] longRefBytes = new byte[2];
            longRefBytes[0] = asciiEncoder.GetBytes(GPSLongitudeRef)[0];
            tempPropItem.Id = (int)ProportyItemId.gpsLongRef;
            tempPropItem.Type = 2;
            tempPropItem.Len = longRefBytes.Length;
            tempPropItem.Value = longRefBytes;
            image.SetPropertyItem(tempPropItem);

            byte[] b_Heading = GetYAWBytes();
            tempPropItem.Id = (int)ProportyItemId.yaw;
            tempPropItem.Type = 5;
            tempPropItem.Len = b_Heading.Length;
            tempPropItem.Value = b_Heading;
            image.SetPropertyItem(tempPropItem);

            //tempPropItem = image.
            byte[] b_Alt = GetGPSAltBytes();
            tempPropItem.Id = (int)ProportyItemId.gpsAlt;
            tempPropItem.Type = 5;
            tempPropItem.Len = b_Alt.Length;
            tempPropItem.Value = b_Alt;
            image.SetPropertyItem(tempPropItem);
        }
开发者ID:RichardHabeeb,项目名称:UAS-ImageDataConnector,代码行数:94,代码来源:ImageData.cs

示例11: SetImageProperty

 private static void SetImageProperty(Image image, int propertyId, byte[] value)
 {
     var prop = (PropertyItem) FormatterServices.GetUninitializedObject(typeof(PropertyItem));
     prop.Id = propertyId;
     prop.Value = value;
     prop.Len = prop.Value.Length;
     prop.Type = 1;
     image.SetPropertyItem(prop);
 }
开发者ID:W1R3D-Code,项目名称:RedditRip,代码行数:9,代码来源:RedditRip.cs

示例12: ShiftPropItemDateTime

        /// <summary>
        /// Adjusts the Date/Time of PropertyItem propDecId in Image photo with period timeShift
        /// </summary>
        /// <param name="photo"></param>
        /// <param name="propDecId"></param>
        /// <param name="timeShift"></param>
        private void ShiftPropItemDateTime(Image photo, int propDecId, TimeSpan timeShift, bool updateLog)
        {
            PropertyItem dateTimeItem = photo.GetPropertyItem(propDecId);

            System.Text.ASCIIEncoding encoding = new System.Text.ASCIIEncoding();

            string dateAsString = encoding.GetString(dateTimeItem.Value);
            dateAsString = dateAsString.Remove(19);
            DateTime tempDateTime = DateTime.ParseExact(dateAsString, "yyyy:MM:dd HH:mm:ss", null);
            tempDateTime += timeShift;
            dateAsString = tempDateTime.ToString("yyyy:MM:dd HH:mm:ss");
            if (updateLog) AddStatus(dateAsString);
            dateAsString += "\0";
            dateTimeItem.Value = encoding.GetBytes(dateAsString);
            photo.SetPropertyItem(dateTimeItem);
        }
开发者ID:grokkingly,项目名称:adjust-exif-time,代码行数:22,代码来源:Form1.cs

示例13: CopyProperties

 private static void CopyProperties(Image from, Image to)
 {
     foreach (var propertyItem in from.PropertyItems)
         to.SetPropertyItem(propertyItem);
 }
开发者ID:RyuaNerin,项目名称:QIT,代码行数:5,代码来源:ResizeImage.cs

示例14: AddTag

 /// <summary>
 /// Add the greenshot property!
 /// </summary>
 /// <param name="imageToSave"></param>
 private static void AddTag(Image imageToSave)
 {
     // Create meta-data
     PropertyItem softwareUsedPropertyItem = CreatePropertyItem(PROPERTY_TAG_SOFTWARE_USED, "Greenshot");
     if (softwareUsedPropertyItem != null)
     {
         try
         {
             imageToSave.SetPropertyItem(softwareUsedPropertyItem);
         }
         catch (Exception)
         {
             LOG.WarnFormat("Couldn't set property {0}", softwareUsedPropertyItem.Id);
         }
     }
 }
开发者ID:yoykiee,项目名称:ShareX,代码行数:20,代码来源:ImageOutput.cs

示例15: Save

        /// <summary>
        /// Saves image to specific path with specified quality
        /// </summary>
        public static void Save(Image img, string fullPath, int quality)
        {
            // check whether path exists - if not create it
            DirectoryInfo di = new DirectoryInfo(fullPath.Substring(0, fullPath.LastIndexOf(Path.DirectorySeparatorChar)));
            if (!di.Exists)
            {
                Directory.CreateDirectory(di.FullName);
            }

            ImageFormat imfo = null;
            string extension = fullPath.Substring(fullPath.LastIndexOf(".") + 1);
            if (extension.Equals("jpg")) extension = "jpeg"; // we need jpeg string with e for reflection
            extension = extension.Substring(0, 1).ToUpper() + extension.Substring(1).ToLower();
            try
            {
                Type t = typeof(ImageFormat);
                PropertyInfo pi = t.GetProperty(extension, typeof(ImageFormat));
                imfo = (ImageFormat)pi.GetValue(null, null);
            }
            catch (Exception e)
            {
                MessageBox.Show(e.ToString());
                MessageBox.Show("Could not use " + extension + " as image format. Using Jpeg.");
                imfo = ImageFormat.Jpeg;
                extension = imfo.ToString();
            }
            PropertyItem pit = PropertyItemProvider.GetPropertyItem(0x0131, "Greenshot");
            img.SetPropertyItem(pit);
            if (extension.Equals("Jpeg"))
            {
                EncoderParameters parameters = new EncoderParameters(1);
                parameters.Param[0] = new System.Drawing.Imaging.EncoderParameter(Encoder.Quality, quality);
                ImageCodecInfo[] ies = ImageCodecInfo.GetImageEncoders();
                img.Save(fullPath, ies[1], parameters);
            }
            else
            {
                img.Save(fullPath, imfo);
            }
            if ((bool)AppConfig.GetInstance().Output_File_CopyPathToClipboard)
            {
                ido.SetData(DataFormats.Text, true, fullPath);
                Clipboard.SetDataObject(ido, true);
            }
        }
开发者ID:modulexcite,项目名称:ZScreen_Google_Code,代码行数:48,代码来源:ImageOutput.cs


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