本文整理汇总了C#中System.Drawing.Bitmap.GetFrameCount方法的典型用法代码示例。如果您正苦于以下问题:C# System.Drawing.Bitmap.GetFrameCount方法的具体用法?C# System.Drawing.Bitmap.GetFrameCount怎么用?C# System.Drawing.Bitmap.GetFrameCount使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Drawing.Bitmap
的用法示例。
在下文中一共展示了System.Drawing.Bitmap.GetFrameCount方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ConvertToPdf
public static string ConvertToPdf(string strFilePath)
{
Document document = new Document(PageSize.A4, 50, 50, 50, 50);
string newPdfFile = string.Empty;
try
{
System.Drawing.Image objImage = System.Drawing.Image.FromFile(strFilePath);
Guid objGuid = objImage.FrameDimensionsList[0];
System.Drawing.Imaging.FrameDimension objDimension = new System.Drawing.Imaging.FrameDimension(objGuid);
newPdfFile = System.IO.Path.GetTempPath() + @"\" + objGuid + ".pdf";
PdfWriter writer = PdfWriter.GetInstance(document, new FileStream(newPdfFile, FileMode.Create));
System.Drawing.Bitmap bm = new System.Drawing.Bitmap(strFilePath);
int total = bm.GetFrameCount(System.Drawing.Imaging.FrameDimension.Page);
document.Open();
PdfContentByte cb = writer.DirectContent;
for (int i = 0; i < total; i++)
{
string pageName = System.IO.Path.GetTempPath() + @"\" + objGuid + "_" + i.ToString();
objImage.SelectActiveFrame(objDimension, i);
objImage.Save(pageName, System.Drawing.Imaging.ImageFormat.Tiff);
iTextSharp.text.Image img = iTextSharp.text.Image.GetInstance(pageName);
img.ScalePercent(62208f / img.Width, 83737.5f / img.Height);
img.SetAbsolutePosition(0, 0);
cb.AddImage(img);
document.NewPage();
File.Delete(pageName);
}
}
catch (DocumentException de)
{
Console.Error.WriteLine(de.Message);
}
catch (IOException ioe)
{
Console.Error.WriteLine(ioe.Message);
}
document.Close();
return newPdfFile;
}
示例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: tiffToPDF
// public List<Card> Cards { get; set; }
public void tiffToPDF(string resultPDF)
{
// creation of the document with a certain size and certain margins
using (iTextSharp.text.Document document = new iTextSharp.text.Document(iTextSharp.text.PageSize.A4, 0, 0, 0, 0))
{
using (FileStream fs = new System.IO.FileStream(resultPDF, System.IO.FileMode.Create))
{
// creation of the different writers
using (iTextSharp.text.pdf.PdfWriter writer = iTextSharp.text.pdf.PdfWriter.GetInstance(document, fs))
{
document.Open();
foreach (Page page in Pages)
{
if (page.Card.ImageLocationLR != null)
{
// load the tiff image and count the total pages
int total = 0;
using (System.Drawing.Bitmap bm2 = new System.Drawing.Bitmap(page.Card.ImageLocationLR))
{
total = bm2.GetFrameCount(System.Drawing.Imaging.FrameDimension.Page);
// bm2 = null;
bm2.Dispose();
}
for (int k = 0; k < total; ++k)
{
System.Drawing.Bitmap bm = new System.Drawing.Bitmap(page.Card.ImageLocationLR);
iTextSharp.text.pdf.PdfContentByte cb = writer.DirectContent;
bm.SelectActiveFrame(System.Drawing.Imaging.FrameDimension.Page, k);
iTextSharp.text.Image img = iTextSharp.text.Image.GetInstance(bm, System.Drawing.Imaging.ImageFormat.Bmp);
img.ScaleToFitHeight = false;
img.ScalePercent(70f / img.DpiX * 100);
// scale the image to fit in the page
//Lukas old value img.SetAbsolutePosition(-22, 25);
img.SetAbsolutePosition(0, 0);
cb.AddImage(img);
document.NewPage();
img = null;
cb.ClosePath();
bm.Dispose();
}
}
}
document.Close();
document.Dispose();
writer.Dispose();
fs.Close();
fs.Dispose();
}
}
}
}