本文整理汇总了C#中System.Drawing.Bitmap.GetPropertyItem方法的典型用法代码示例。如果您正苦于以下问题:C# System.Drawing.Bitmap.GetPropertyItem方法的具体用法?C# System.Drawing.Bitmap.GetPropertyItem怎么用?C# System.Drawing.Bitmap.GetPropertyItem使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Drawing.Bitmap
的用法示例。
在下文中一共展示了System.Drawing.Bitmap.GetPropertyItem方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: AnimationGif
public AnimationGif(string strImagePath)
{
Stream stmImage;
this.decAnimationGif = ImageProcessing.CreateGifBitmapDecoderFromResource(strImagePath, out stmImage);
stmImage.Seek(0, SeekOrigin.Begin);
var tmpImage = new System.Drawing.Bitmap(stmImage);
var piFrameDelay = tmpImage.GetPropertyItem(0x5100);
this.arrDelays = new int[this.decAnimationGif.Frames.Count];
for (int i = 0; i < this.arrDelays.Length; i++) {
this.arrDelays[i] = BitConverter.ToInt32(piFrameDelay.Value, i * 4) * 10;
}
var piLoopCount = tmpImage.GetPropertyItem(0x5101);
this.nLoop = BitConverter.ToInt16(piLoopCount.Value, 0);
this.nLoopRemain = this.nLoop;
BitmapFrame frame = this.decAnimationGif.Frames.First();
this.imgFrame = new Image();
this.imgFrame.Source = frame;
this.imgFrame.Stretch = Stretch.None;
this.imgFrame.Width = frame.PixelWidth;
this.imgFrame.Height = frame.PixelHeight;
this.timerInterval = new DispatcherTimer();
this.timerInterval.Interval = new TimeSpan(0, 0, 0, 0, this.arrDelays[0]);
this.timerInterval.Tick += new EventHandler(AnimationHandler);
this.timerInterval.Start();
}
示例2: AddAnimatedGif
/// <summary>
/// Creates an animated gif shape.
/// Do not add a very large number of these or performance may be degraded.
/// </summary>
/// <param name="imageName">
/// The animated gif file (local or network) to load.
/// </param>
/// <param name="repeat">
/// Continuously repeat the animation "True" or "False".
/// </param>
/// <returns>
/// The animated gif shape name.
/// </returns>
public static Primitive AddAnimatedGif(Primitive imageName, Primitive repeat)
{
if (((string)imageName).StartsWith("http")) imageName = Network.DownloadFile(imageName);
GraphicsWindow.Show();
Type ShapesType = typeof(Shapes);
Canvas _mainCanvas;
string shapeName;
try
{
MethodInfo method = GraphicsWindowType.GetMethod("VerifyAccess", BindingFlags.NonPublic | BindingFlags.Static | BindingFlags.IgnoreCase);
method.Invoke(null, new object[] { });
method = ShapesType.GetMethod("GenerateNewName", BindingFlags.NonPublic | BindingFlags.Static | BindingFlags.IgnoreCase);
shapeName = method.Invoke(null, new object[] { "Image" }).ToString();
_mainCanvas = (Canvas)GraphicsWindowType.GetField("_mainCanvas", BindingFlags.NonPublic | BindingFlags.Static | BindingFlags.IgnoreCase).GetValue(null);
InvokeHelperWithReturn ret = new InvokeHelperWithReturn(delegate
{
try
{
System.Drawing.Bitmap bitmap = new System.Drawing.Bitmap(imageName);
System.Drawing.Imaging.FrameDimension fd = new System.Drawing.Imaging.FrameDimension(bitmap.FrameDimensionsList[0]);
int frameCount = bitmap.GetFrameCount(fd);
if (frameCount > 1)
{
Animated anim = new Animated();
animated.Add(anim);
anim.name = shapeName;
anim.frames = new Frame[frameCount];
anim.repeat = repeat;
//0x5100 is the property id of the GIF frame's durations
//this property does not exist when frameCount <= 1
byte[] times = bitmap.GetPropertyItem(0x5100).Value;
for (int i = 0; i < frameCount; i++)
{
//selects GIF frame based on FrameDimension and frameIndex
bitmap.SelectActiveFrame(fd, i);
//length in milliseconds of display duration
int length = BitConverter.ToInt32(times, 4 * i) * 10;
System.IO.MemoryStream stream = new System.IO.MemoryStream();
new System.Drawing.Bitmap(bitmap).Save(stream, System.Drawing.Imaging.ImageFormat.Png);
BitmapImage bi = new BitmapImage();
bi.BeginInit();
bi.StreamSource = stream;
bi.EndInit();
anim.frames[i] = new Frame(length, bi);
}
Image shape = new Image();
shape.Source = anim.frames[0].bi;
shape.Stretch = Stretch.Fill;
shape.Name = shapeName;
shape.Width = shape.Source.Width;
shape.Height = shape.Source.Height;
anim.shape = shape;
if (null == animationTimer)
{
animationTimer = new System.Windows.Forms.Timer();
animationTimer.Enabled = animationInterval > 0;
if (animationInterval > 0) animationTimer.Interval = animationInterval;
animationTimer.Tick += new System.EventHandler(animation_Tick);
}
_objectsMap[shapeName] = shape;
_mainCanvas.Children.Add(shape);
return shapeName;
}
return "";
}
catch (Exception ex)
{
Utilities.OnError(Utilities.GetCurrentMethod(), ex);
return "";
}
});
return FastThread.InvokeWithReturn(ret).ToString();
}
//.........这里部分代码省略.........
示例3: getDateTaken
DateTime getDateTaken(string filePath)
{
// Load an image however you like.
System.Drawing.Image image = new System.Drawing.Bitmap(filePath);
// Get the Date Created property
System.Drawing.Imaging.PropertyItem propItem = null;
try
{
propItem = image.GetPropertyItem(0x9003);
}
catch
{
}
image.Dispose();
if (propItem != null)
{
// Extract the property value (a string).
var encoding = new System.Text.ASCIIEncoding();
string text = encoding.GetString(propItem.Value, 0, propItem.Len - 1);
// Parse the date and time.
System.Globalization.CultureInfo provider = System.Globalization.CultureInfo.InvariantCulture;
return DateTime.ParseExact(text, "yyyy:MM:d H:m:s", provider);
}
return new DateTime(0);
}
示例4: ReadGifData
private Stream ReadGifData(Stream inkdata)
{
// Read the GIF header ...
System.Drawing.Bitmap img = new System.Drawing.Bitmap(inkdata);
// Read the comment as that is where the ISF is stored...
// for reference the tag is PropertyTagExifUserComment [0x9286] or 37510 (int)
System.Drawing.Imaging.PropertyItem piComment = img.GetPropertyItem(37510);
return new MemoryStream(piComment.Value);
}