本文整理汇总了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;
}
示例2: Copy
public static void Copy(Image source, Image target)
{
foreach (var propertyItem in source.PropertyItems)
{
target.SetPropertyItem(propertyItem);
}
}
示例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);
}
}
示例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);
}
示例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);
}
示例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);
}
示例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);
}
示例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);
}
}
示例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);
}
}
示例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);
}
示例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);
}
示例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);
}
示例13: CopyProperties
private static void CopyProperties(Image from, Image to)
{
foreach (var propertyItem in from.PropertyItems)
to.SetPropertyItem(propertyItem);
}
示例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);
}
}
}
示例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);
}
}