本文整理汇总了C#中System.Drawing.Image.GetPropertyItem方法的典型用法代码示例。如果您正苦于以下问题:C# Image.GetPropertyItem方法的具体用法?C# Image.GetPropertyItem怎么用?C# Image.GetPropertyItem使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Drawing.Image
的用法示例。
在下文中一共展示了Image.GetPropertyItem方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ImageAnimation
//-------------------------------------------------------------------------------
//
public ImageAnimation(Image img)
{
_image = img;
FrameDimension = new FrameDimension(img.FrameDimensionsList[0]);
MaxFrameCount = img.GetFrameCount(FrameDimension);
PropertyItem pItemFrameDelay = img.GetPropertyItem(FRAME_DELAY);
PropertyItem pItemFrameNum = img.GetPropertyItem(FRAME_NUM);
FrameDelays = new int[MaxFrameCount];
for (int i = 0; i < MaxFrameCount; i++) {
FrameDelays[i] = BitConverter.ToInt32(pItemFrameDelay.Value, 4 * i);
}
MaxLoopCount = BitConverter.ToInt16(pItemFrameNum.Value, 0);
LoopInfinity = (MaxLoopCount == 0);
_timer = new Timer(Timer_Elapsed, null, Timeout.Infinite, Timeout.Infinite);
try {
_image.SelectActiveFrame(FrameDimension, 0);
}
catch (InvalidOperationException/* ex*/) {
//Log.DebugLog(ex);
//Debug.Assert(false, "Image.SelectActiveFrame失敗");
}
}
示例2: GifDecoder
/// <summary>
/// Initializes a new instance of the <see cref="GifDecoder"/> class.
/// </summary>
/// <param name="image">
/// The <see cref="Image"/> to decode.
/// </param>
public GifDecoder(Image image)
{
this.Height = image.Height;
this.Width = image.Width;
if (FormatUtilities.IsAnimated(image))
{
this.IsAnimated = true;
if (this.IsAnimated)
{
int frameCount = image.GetFrameCount(FrameDimension.Time);
int last = frameCount - 1;
double length = 0;
List<GifFrame> gifFrames = new List<GifFrame>();
// Get the times stored in the gif.
byte[] times = image.GetPropertyItem((int)ExifPropertyTag.FrameDelay).Value;
for (int i = 0; i < frameCount; i++)
{
// Convert each 4-byte chunk into an integer.
// GDI returns a single array with all delays, while Mono returns a different array for each frame.
TimeSpan delay = TimeSpan.FromMilliseconds(BitConverter.ToInt32(times, (4 * i) % times.Length) * 10);
// Find the frame
image.SelectActiveFrame(FrameDimension.Time, i);
Bitmap frame = new Bitmap(image);
frame.SetResolution(image.HorizontalResolution, image.VerticalResolution);
// TODO: Get positions.
gifFrames.Add(new GifFrame { Delay = delay, Image = frame });
// Reset the position.
if (i == last)
{
image.SelectActiveFrame(FrameDimension.Time, 0);
}
length += delay.TotalMilliseconds;
}
this.GifFrames = gifFrames;
this.AnimationLength = length;
// Loop info is stored at byte 20737.
this.LoopCount = BitConverter.ToInt16(image.GetPropertyItem((int)ExifPropertyTag.LoopCount).Value, 0);
this.IsLooped = this.LoopCount != 1;
}
}
}
示例3: GetLatitude
public static float? GetLatitude(Image targetImg)
{
try
{
//Property Item 0x0001 - PropertyTagGpsLatitudeRef
PropertyItem propItemRef = targetImg.GetPropertyItem(1);
//Property Item 0x0002 - PropertyTagGpsLatitude
PropertyItem propItemLat = targetImg.GetPropertyItem(2);
return ExifGpsToFloat(propItemRef, propItemLat);
}
catch (ArgumentException)
{
return null;
}
}
示例4: GetLongitude
public static float? GetLongitude(Image targetImg)
{
try
{
///Property Item 0x0003 - PropertyTagGpsLongitudeRef
PropertyItem propItemRef = targetImg.GetPropertyItem(3);
//Property Item 0x0004 - PropertyTagGpsLongitude
PropertyItem propItemLong = targetImg.GetPropertyItem(4);
return ExifGpsToFloat(propItemRef, propItemLong);
}
catch (ArgumentException)
{
return null;
}
}
示例5: Animate
public static void Animate (Image image, EventHandler onFrameChangedHandler)
{
// must be non-null and contain animation time frames
if (!CanAnimate (image))
return;
// is animation already in progress ?
if (ht.ContainsKey (image))
return;
PropertyItem item = image.GetPropertyItem (0x5100); // FrameDelay in libgdiplus
byte[] value = item.Value;
int[] delay = new int [(value.Length >> 2)];
for (int i=0, n=0; i < value.Length; i += 4, n++) {
int d = BitConverter.ToInt32 (value, i) * 10;
// follow worse case (Opera) see http://news.deviantart.com/article/27613/
delay [n] = d < 100 ? 100 : d;
}
AnimateEventArgs aea = new AnimateEventArgs (image);
WorkerThread wt = new WorkerThread (onFrameChangedHandler, aea, delay);
Thread thread = new Thread (new ThreadStart (wt.LoopHandler));
thread.IsBackground = true;
aea.RunThread = thread;
ht.Add (image, aea);
thread.Start ();
}
示例6: ImageInfo
/// <devdoc>
/// </devdoc>
public ImageInfo(Image image) {
this.image = image;
animated = ImageAnimator.CanAnimate(image);
if (animated) {
frameCount = image.GetFrameCount(FrameDimension.Time);
PropertyItem frameDelayItem = image.GetPropertyItem(PropertyTagFrameDelay);
// If the image does not have a frame delay, we just return 0.
//
if (frameDelayItem != null) {
// Convert the frame delay from byte[] to int
//
byte[] values = frameDelayItem.Value;
Debug.Assert(values.Length == 4 * FrameCount, "PropertyItem has invalid value byte array");
frameDelay = new int[FrameCount];
for (int i=0; i < FrameCount; ++i) {
frameDelay[i] = values[i * 4] + 256 * values[i * 4 + 1] + 256 * 256 * values[i * 4 + 2] + 256 * 256 * 256 * values[i * 4 + 3];
}
}
}
else {
frameCount = 1;
}
if (frameDelay == null) {
frameDelay = new int[FrameCount];
}
}
示例7: GetDateTakenPropertyItem
private static PropertyItem GetDateTakenPropertyItem(Image image)
{
PropertyItem dateTakenItem = null;
try
{
dateTakenItem = image.GetPropertyItem(DATE_TAKEN);
}
catch (ArgumentException) { }
return dateTakenItem;
}
示例8: ImageAnimation
//-------------------------------------------------------------------------------
//
public ImageAnimation(Image img)
{
_image = img;
FrameDimension = new FrameDimension(img.FrameDimensionsList[0]);
MaxFrameCount = img.GetFrameCount(FrameDimension);
PropertyItem pItemFrameDelay = img.GetPropertyItem(FRAME_DELAY);
PropertyItem pItemFrameNum = img.GetPropertyItem(FRAME_NUM);
FrameDelays = new int[MaxFrameCount];
for (int i = 0; i < MaxFrameCount; i++) {
FrameDelays[i] = BitConverter.ToInt32(pItemFrameDelay.Value, 4 * i);
}
MaxLoopCount = BitConverter.ToInt16(pItemFrameNum.Value, 0);
LoopInfinity = (MaxLoopCount == 0);
_timer = new Timer(Timer_Elapsed, null, Timeout.Infinite, Timeout.Infinite);
_image.SelectActiveFrame(FrameDimension, 0);
}
示例9: GifHandler
public GifHandler( Image Image ) {
mImage = Image.Clone() as Image;
mFrameDimension = new FrameDimension( mImage.FrameDimensionsList[ 0 ] );
mFrameCount = mImage.GetFrameCount( mFrameDimension );
mFrameTimes = new int[ mFrameCount ];
byte[] times = mImage.GetPropertyItem( 0x5100 ).Value;
for( int i = 0; i < mFrameCount; i++ )
mFrameTimes[ i ] = BitConverter.ToInt32( times, 4 * i ) * 10;
}
示例10: 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);
}
示例11: Orientate
/// <summary>
/// Make sure the image is orientated correctly
/// </summary>
/// <param name="image"></param>
public static void Orientate(Image image)
{
/*if (!conf.ProcessEXIFOrientation)
{
return;
}*/
try
{
// Get the index of the orientation property.
int orientationIndex = Array.IndexOf(image.PropertyIdList, EXIF_ORIENTATION_ID);
// If there is no such property, return Unknown.
if (orientationIndex < 0)
{
return;
}
PropertyItem item = image.GetPropertyItem(EXIF_ORIENTATION_ID);
ExifOrientations orientation = (ExifOrientations)item.Value[0];
// Orient the image.
switch (orientation)
{
case ExifOrientations.Unknown:
case ExifOrientations.TopLeft:
break;
case ExifOrientations.TopRight:
image.RotateFlip(RotateFlipType.RotateNoneFlipX);
break;
case ExifOrientations.BottomRight:
image.RotateFlip(RotateFlipType.Rotate180FlipNone);
break;
case ExifOrientations.BottomLeft:
image.RotateFlip(RotateFlipType.RotateNoneFlipY);
break;
case ExifOrientations.LeftTop:
image.RotateFlip(RotateFlipType.Rotate90FlipX);
break;
case ExifOrientations.RightTop:
image.RotateFlip(RotateFlipType.Rotate90FlipNone);
break;
case ExifOrientations.RightBottom:
image.RotateFlip(RotateFlipType.Rotate90FlipY);
break;
case ExifOrientations.LeftBottom:
image.RotateFlip(RotateFlipType.Rotate270FlipNone);
break;
}
// Set the orientation to be normal, as we rotated the image.
item.Value[0] = (byte)ExifOrientations.TopLeft;
image.SetPropertyItem(item);
}
catch (Exception orientEx)
{
LOG.Warn("Problem orientating the image: ", orientEx);
}
}
示例12: GifImage
public GifImage(string path)
{
_lastRequest = DateTime.Now;
_gifImage = Image.FromFile(path); //initialize
_dimension = new FrameDimension(_gifImage.FrameDimensionsList[0]); //gets the GUID
FrameCount = _gifImage.GetFrameCount(_dimension); //total frames in the animation
Source = path;
var item = _gifImage.GetPropertyItem(0x5100); // FrameDelay in libgdiplus
_delay = (item.Value[0] + item.Value[1]*256)*10; // Time is in 1/100th of a second
}
示例13: ImageOrientation
/// <summary>
/// Return the image's orientation.
/// </summary>
/// <param name="img"></param>
/// <returns></returns>
public static ExifOrientations ImageOrientation(Image img)
{
// Get the index of the orientation property.
int orientation_index = Array.IndexOf(img.PropertyIdList, OrientationID);
// If there is no such property, return Unknown.
if ((orientation_index < 0))
return ExifOrientations.Unknown;
// Return the orientation value.
return (ExifOrientations)img.GetPropertyItem(OrientationID).Value[0];
}
示例14: MakeSureAllPropertyItemsArePresent
protected void MakeSureAllPropertyItemsArePresent(Image source, Image target)
{
foreach (var propertyItem in source.PropertyItems)
{
try
{
target.GetPropertyItem(propertyItem.Id);
}
catch (ArgumentException)
{
Assert.Fail("The property item with ID {0} was not present.", propertyItem.Id);
}
}
}
示例15: GifDecoder
/// <summary>
/// Initializes a new instance of the <see cref="GifDecoder"/> class.
/// </summary>
/// <param name="image">
/// The <see cref="Image"/> to decode.
/// </param>
/// <param name="animationProcessMode">
/// The <see cref="AnimationProcessMode" /> to use.
/// </param>
public GifDecoder(Image image, AnimationProcessMode animationProcessMode)
{
this.Height = image.Height;
this.Width = image.Width;
if (FormatUtilities.IsAnimated(image) && animationProcessMode == AnimationProcessMode.All)
{
this.IsAnimated = true;
this.FrameCount = image.GetFrameCount(FrameDimension.Time);
// Loop info is stored at byte 20737.
this.LoopCount = BitConverter.ToInt16(image.GetPropertyItem((int)ExifPropertyTag.LoopCount).Value, 0);
}
else
{
this.FrameCount = 1;
}
}