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


C# System.Drawing.Bitmap.SelectActiveFrame方法代码示例

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


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

示例1: 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();
            }
//.........这里部分代码省略.........
开发者ID:litdev1,项目名称:LitDev,代码行数:101,代码来源:Shapes.cs

示例2: 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();

                    }
                }
            }
        }
开发者ID:smoo7h,项目名称:PDFScanAndSort,代码行数:79,代码来源:Application.cs


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