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


C# Bitmap.GetFrameCount方法代码示例

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


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

示例1: Load

        public static LCDBitmapAnimation Load(Bitmap img)
        {
            LCDBitmapAnimation anim = new LCDBitmapAnimation();
            anim.FrameHeight = img.Height;
            anim.FrameWidth = img.Width;

            int fcount = img.GetFrameCount(FrameDimension.Time);
            if (fcount == 1)
            {
                anim.Frames.Add(LCDBitmap.Load(img));
                anim.FrameTimes.Add(1);
            }
            else
            {
                byte[] times = img.GetPropertyItem(0x5100).Value;
                for (int i = 0; i < fcount; i++)
                {
                    img.SelectActiveFrame(FrameDimension.Time, i);
                    int dur = BitConverter.ToInt32(times, (i * 4) % times.Length) * 10;
                    anim.FrameTimes.Add(dur);
                    anim.Frames.Add(LCDBitmap.Load(img));
                }
            }

            anim.Length = anim.FrameTimes.Sum();

            return anim;
        }
开发者ID:Bzaraticus,项目名称:WiringPi,代码行数:28,代码来源:LCDBitmapAnimation.cs

示例2: CreatePdf

        private void CreatePdf(string[] tiffImages, string outputFile)
        {
            Document    document    = new Document();
            PdfWriter   writer      = PdfWriter.GetInstance(document, new System.IO.FileStream(outputFile, System.IO.FileMode.Create));

            document.Open();

            for (int count = 0; count < tiffImages.Length; count++)
            {
                Bitmap  bitmap  = new Bitmap(tiffImages[count]);
                int     total   = bitmap.GetFrameCount(System.Drawing.Imaging.FrameDimension.Page);

                PdfContentByte cb = writer.DirectContent;

                for (int k = 0; k < total; ++k)
                {
                    bitmap.SelectActiveFrame(System.Drawing.Imaging.FrameDimension.Page, k);
                    Image image = Image.GetInstance(bitmap, System.Drawing.Imaging.ImageFormat.Bmp);

                    image.ScalePercent(72f / image.DpiX * 100);
                    image.SetAbsolutePosition(0, 0);
                    cb.AddImage(image);
                    document.NewPage();
                }
            }
            UpdateProperties(document);
            document.Close();
        }
开发者ID:ebruning,项目名称:Enhanced-PDF-Export,代码行数:28,代码来源:PdfGenerator.cs

示例3: Import

 public IEnumerable<ScannedImage> Import(string filePath, Func<int, int, bool> progressCallback)
 {
     if (!progressCallback(0, 1))
     {
         yield break;
     }
     Bitmap toImport;
     try
     {
         toImport = new Bitmap(filePath);
     }
     catch (Exception e)
     {
         Log.ErrorException("Error importing image: " + filePath, e);
         // Handle and notify the user outside the method so that errors importing multiple files can be aggregated
         throw;
     }
     using (toImport)
     {
         int frameCount = toImport.GetFrameCount(FrameDimension.Page);
         for (int i = 0; i < frameCount; ++i)
         {
             if (!progressCallback(i, frameCount))
             {
                 yield break;
             }
             toImport.SelectActiveFrame(FrameDimension.Page, i);
             var image = new ScannedImage(toImport, ScanBitDepth.C24Bit, IsLossless(toImport.RawFormat), -1);
             image.SetThumbnail(thumbnailRenderer.RenderThumbnail(toImport));
             yield return image;
         }
         progressCallback(frameCount, frameCount);
     }
 }
开发者ID:cyanfish,项目名称:naps2,代码行数:34,代码来源:ImageImporter.cs

示例4: Precache

 public override BitmapImage Precache(int width, int height)
 {
     using (var fs = new FileStream(FileList.CurrentPath, FileMode.Open, FileAccess.Read))
     {
         var bmp = new Bitmap(fs);
         _pagesCount = bmp.GetFrameCount(FrameDimension.Page);
         bmp.SelectActiveFrame(FrameDimension.Page, CurrentPage);
         _bmp = new Bitmap(bmp);
     }
     return _bmp.ToBitmapImage(width, height);
 }
开发者ID:birdy90,项目名称:LightImageViewer,代码行数:11,代码来源:Tif.cs

示例5: LoadGif

        public static IEnumerable<Frame> LoadGif(string filename)
        {
            using (Bitmap bitmap = new Bitmap(filename))
            {
                FrameDimension dim = new FrameDimension(bitmap.FrameDimensionsList[0]);
                for (int i = 0; i < bitmap.GetFrameCount(dim); i++)
                {
                    bitmap.SelectActiveFrame(dim, i);

                    var frame = new MutableFrame();
                    frame.LoadBitmap(bitmap);
                    yield return frame;
                }
            }
        }
开发者ID:foobert,项目名称:Colorduino,代码行数:15,代码来源:Frame.cs

示例6: GetImageParameters

 public override void GetImageParameters()
 {
     CurrentPage = GetLastPagePosition(CurrentPage);
     using (var fs = new FileStream(FileList.CurrentPath, FileMode.Open, FileAccess.Read))
     {
         var bmp = new Bitmap(fs);
         _pagesCount = bmp.GetFrameCount(FrameDimension.Page);
         bmp.SelectActiveFrame(FrameDimension.Page, CurrentPage);
         _bmp = new Bitmap(bmp);
     }
     ImageParameters.CalculateParameters(
         (int)Math.Min(_bmp.Width, _canvas.ActualWidth),
         (int)Math.Min(_bmp.Height, _canvas.ActualHeight),
         _canvas);
 }
开发者ID:birdy90,项目名称:LightImageViewer,代码行数:15,代码来源:Tif.cs

示例7: GetDelays

        int[] GetDelays(Bitmap image)
        {
            List<int> results = new List<int>();

            var frameDimension = image.FrameDimensionsList.Single();
            var frameCount = image.GetFrameCount(new FrameDimension(frameDimension));

            for (var i = 0; i < frameCount; i++)
            {
                image.SelectActiveFrame(new FrameDimension(frameDimension), i);

                results.Add(image.DelayMS());
            }

            return results.ToArray();
        }
开发者ID:fschwiet,项目名称:Gifenstein,代码行数:16,代码来源:AnimationVisitorExtension.cs

示例8: TestBrokenTransformOfAnimiatedGif

        public void TestBrokenTransformOfAnimiatedGif()
        {
            using (var imageStream = new MemoryStream(ReadBytes("ImageResizerGDIBug.poison.gif")))
            using (var bmp = new Bitmap(imageStream))
            using (var outputStream = new MemoryStream())
            {

                /*
                 * The exception occurs in GDI+ via System.Drawing.
                 * The error occurs for this "poison" gif on frame 2 (time dimension).
                 * The AnimatedGifs ImageResizer package fails on this exact same line
                 * I've commented out the ImageResizer bit using AnimatedGifs library
                 * for clarity.
                 */
                var numFrames = bmp.GetFrameCount(FrameDimension.Time);
                Console.WriteLine(" number of time frames: {0}", numFrames);
                for (var frameNo = 0; frameNo < numFrames; frameNo++)
                {
                    Console.WriteLine("     select active frame number: {0}", frameNo);
                    bmp.SelectActiveFrame(FrameDimension.Time, frameNo);
                }

                /*
                 * Here is the essential code that is failing all over the place.
                 * The Build method uses the AnimatedGifs class and fails in
                 * the method WriteAnimatedGif
                 */
            /*
                var builderConfig = new ImageResizer.Configuration.Config();
                new PrettyGifs().Install(builderConfig);
                new AnimatedGifs().Install(builderConfig);

                var imageBuilder = new ImageBuilder(
                    builderConfig.Plugins.ImageBuilderExtensions,
                    builderConfig.Plugins,
                    builderConfig.Pipeline,
                    builderConfig.Pipeline);
                imageBuilder.Build(bmp, outputStream, new ResizeSettings
                                                          {
                                                              MaxWidth = 500
                                                          }, false);
            */
            }
        }
开发者ID:cheezburger,项目名称:gdi-bug,代码行数:44,代码来源:Program.cs

示例9: Import

 public IEnumerable<IScannedImage> Import(string filePath)
 {
     Bitmap toImport;
     try
     {
         toImport = new Bitmap(filePath);
     }
     catch (Exception e)
     {
         Log.ErrorException("Error importing image: " + filePath, e);
         // Handle and notify the user outside the method so that errors importing multiple files can be aggregated
         throw;
     }
     using (toImport)
     {
         for (int i = 0; i < toImport.GetFrameCount(FrameDimension.Page); ++i)
         {
             toImport.SelectActiveFrame(FrameDimension.Page, i);
             yield return scannedImageFactory.Create(toImport, ScanBitDepth.C24Bit, IsLossless(toImport.RawFormat));
         }
     }
 }
开发者ID:rprenhol,项目名称:naps2,代码行数:22,代码来源:ImageImporter.cs

示例10: fromGifToolStripMenuItem_Click

 //End of Soulblighter Modification
 //My Soulblighter Modification
 private void fromGifToolStripMenuItem_Click(object sender, EventArgs e)
 {
     if (FileType != 0)
     {
         using (OpenFileDialog dialog = new OpenFileDialog())
         {
             dialog.Multiselect = false;
             dialog.Title = "Choose palette file";
             dialog.CheckFileExists = true;
             dialog.Filter = "Gif files (*.gif)|*.gif";
             if (dialog.ShowDialog() == DialogResult.OK)
             {
                 Bitmap bit = new Bitmap(dialog.FileName);
                 AnimIdx edit = Ultima.AnimationEdit.GetAnimation(FileType, CurrBody, CurrAction, CurrDir);
                 if (edit != null)
                 {
                     FrameDimension dimension = new FrameDimension(bit.FrameDimensionsList[0]);
                     // Number of frames
                     int frameCount = bit.GetFrameCount(dimension);
                     bit.SelectActiveFrame(dimension, 0);
                     edit.GetGifPalette(bit);
                     SetPaletteBox();
                     listView1.Invalidate();
                     Options.ChangedUltimaClass["Animations"] = true;
                 }
             }
         }
     }
 }
开发者ID:polserver,项目名称:poltools,代码行数:31,代码来源:AnimationEdit.cs

示例11: allDirectionsAddToolStripMenuItem_Click

        //Add in all Directions
        private void allDirectionsAddToolStripMenuItem_Click(object sender, EventArgs e)
        {
            if (FileType != 0)
            {
                using (OpenFileDialog dialog = new OpenFileDialog())
                {
                    dialog.Multiselect = true;
                    dialog.Title = "Choose 5 Gifs to add";
                    dialog.CheckFileExists = true;
                    dialog.Filter = "Gif files (*.gif;)|*.gif;";
                    if (dialog.ShowDialog() == DialogResult.OK)
                    {
                        trackBar1.Enabled = false;
                        if (dialog.FileNames.Length == 5)
                        {
                            trackBar1.Value = 0;
                            for (int w = 0; w < dialog.FileNames.Length; w++)
                            {
                                if (w < 5)
                                {
                                    Bitmap bmp = new Bitmap(dialog.FileNames[w]); // dialog.Filename replaced by dialog.FileNames[w]
                                    AnimIdx edit = Ultima.AnimationEdit.GetAnimation(FileType, CurrBody, CurrAction, CurrDir);
                                    if (edit != null)
                                    {
                                        //Gif Especial Properties
                                        if (dialog.FileName.Contains(".gif"))
                                        {
                                            FrameDimension dimension = new FrameDimension(bmp.FrameDimensionsList[0]);
                                            // Number of frames
                                            int frameCount = bmp.GetFrameCount(dimension);
                                            progressBar1.Maximum = frameCount;
                                            bmp.SelectActiveFrame(dimension, 0);
                                            edit.GetGifPalette(bmp);
                                            Bitmap[] bitbmp = new Bitmap[frameCount];
                                            // Return an Image at a certain index
                                            for (int index = 0; index < frameCount; index++)
                                            {
                                                bitbmp[index] = new Bitmap(bmp.Width, bmp.Height, PixelFormat.Format16bppArgb1555);
                                                bmp.SelectActiveFrame(dimension, index);
                                                bitbmp[index] = (Bitmap)bmp;
                                                bitbmp[index] = Utils.ConvertBmpAnim(bitbmp[index], (int)numericUpDown3.Value, (int)numericUpDown4.Value, (int)numericUpDown5.Value);
                                                edit.AddFrame(bitbmp[index]);
                                                TreeNode node = GetNode(CurrBody);
                                                if (node != null)
                                                {
                                                    node.ForeColor = Color.Black;
                                                    node.Nodes[CurrAction].ForeColor = Color.Black;
                                                }
                                                ListViewItem item;
                                                int i = edit.Frames.Count - 1;
                                                item = new ListViewItem(i.ToString(), 0);
                                                item.Tag = i;
                                                listView1.Items.Add(item);
                                                int width = listView1.TileSize.Width - 5;
                                                if (bmp.Width > listView1.TileSize.Width)
                                                    width = bmp.Width;
                                                int height = listView1.TileSize.Height - 5;
                                                if (bmp.Height > listView1.TileSize.Height)
                                                    height = bmp.Height;

                                                listView1.TileSize = new Size(width + 5, height + 5);
                                                trackBar2.Maximum = i;
                                                Options.ChangedUltimaClass["Animations"] = true;
                                                if (progressBar1.Value < progressBar1.Maximum)
                                                {
                                                    progressBar1.Value++;
                                                    progressBar1.Invalidate();
                                                }
                                            }
                                            progressBar1.Value = 0;
                                            progressBar1.Invalidate();
                                            SetPaletteBox();
                                            listView1.Invalidate();
                                            numericUpDownCx.Value = edit.Frames[trackBar2.Value].Center.X;
                                            numericUpDownCy.Value = edit.Frames[trackBar2.Value].Center.Y;
                                            Options.ChangedUltimaClass["Animations"] = true;
                                        }
                                    }
                                    if ((w < 4) & (w < dialog.FileNames.Length - 1))
                                        trackBar1.Value++;
                                }
                            }
                        }
                        //Looping if dialog.FileNames.Length != 5
                        while (dialog.FileNames.Length != 5)
                        {
                            if (dialog.ShowDialog() == DialogResult.Cancel)
                                break;
                            if (dialog.FileNames.Length != 5)
                                dialog.ShowDialog();
                            if (dialog.FileNames.Length == 5)
                            {
                                trackBar1.Value = 0;
                                for (int w = 0; w < dialog.FileNames.Length; w++)
                                {
                                    if (w < 5)
                                    {
                                        Bitmap bmp = new Bitmap(dialog.FileNames[w]); // dialog.Filename replaced by dialog.FileNames[w]
                                        AnimIdx edit = Ultima.AnimationEdit.GetAnimation(FileType, CurrBody, CurrAction, CurrDir);
//.........这里部分代码省略.........
开发者ID:polserver,项目名称:poltools,代码行数:101,代码来源:AnimationEdit.cs

示例12: ShowAnimation


//.........这里部分代码省略.........
                                currAnimation = woman_left_sure;
                                break;
                            case (int)ResponseType.LeftUnsure:
                                currAnimation = woman_left_unsure;
                                break;
                            case (int)ResponseType.RightSure:
                                currAnimation = woman_right_sure;
                                break;
                            case (int)ResponseType.RightUnsure:
                                currAnimation = woman_right_unsure;
                                break;
                            default:
                            {
                                 Console.WriteLine("Breaking with default");
                                 return;
                            }
                        }
                        break;

                    case ("Man"):
                        switch (respType)
                        {
                            case (int)ResponseType.LeftSure:
                                currAnimation = man_left_sure;
                                break;
                            case (int)ResponseType.LeftUnsure:
                                currAnimation = man_left_unsure;
                                break;
                            case (int)ResponseType.RightSure:
                                currAnimation = man_right_sure;
                                break;
                            case (int)ResponseType.RightUnsure:
                                currAnimation = man_right_unsure;
                                break;
                            default:
                                {
                                    Console.WriteLine("Breaking with default");
                                    return;
                                }
                        }
                        break;

                    case ("Boy"):
                        switch (respType)
                        {
                            case (int)ResponseType.LeftSure:
                                currAnimation = boy_left_sure;
                                break;
                            case (int)ResponseType.LeftUnsure:
                                currAnimation = boy_left_unsure;
                                break;
                            case (int)ResponseType.RightSure:
                                currAnimation = boy_right_sure;
                                break;
                            case (int)ResponseType.RightUnsure:
                                currAnimation = boy_right_unsure;
                                break;
                            default:
                                {
                                    Console.WriteLine("Breaking with default");
                                    return;
                                }
                        }
                        break;

                    case ("Girl"):
                        switch (respType)
                        {
                            case (int)ResponseType.LeftSure:
                                currAnimation = girl_left_sure;
                                break;
                            case (int)ResponseType.LeftUnsure:
                                currAnimation = girl_left_unsure;
                                break;
                            case (int)ResponseType.RightSure:
                                currAnimation = girl_right_sure;
                                break;
                            case (int)ResponseType.RightUnsure:
                                currAnimation = girl_right_unsure;
                                break;
                            default:
                                {
                                    Console.WriteLine("Breaking with default");
                                    return;
                                }
                        }
                        break;
                }

                #endregion;

                // get the number of frames
                numFrames = currAnimation.GetFrameCount(
                    new System.Drawing.Imaging.FrameDimension(
                    currAnimation.FrameDimensionsList[0]));

                //begin the animation
                AnimateImage();
            }
        }
开发者ID:jlaswell,项目名称:Virtual_Lab,代码行数:101,代码来源:PatientWindow.cs

示例13: GetImageFrameCount

 private static int GetImageFrameCount(Bitmap ImageToRetrieveFrameCountFrom)
 {
     return ImageToRetrieveFrameCountFrom.GetFrameCount(FrameDimension.Page);
 }
开发者ID:dibiancoj,项目名称:ToracLibrary,代码行数:4,代码来源:TiffCombiner.cs

示例14: CreatePdfBookMarks

        private void CreatePdfBookMarks(List<PdfDef> pdfDocuments, string outputFile)
        {
            Document    document    = new Document();
            PdfWriter   writer      = PdfWriter.GetInstance(document, new System.IO.FileStream(outputFile, System.IO.FileMode.Create));

            document.Open();

            foreach (PdfDef pdfDocument in pdfDocuments)
            {
                String [] tiffImages = new string[pdfDocument.TiffImages.Length];

                for (int i = 0; i < pdfDocument.TiffImages.Length; i++)
                    tiffImages[i] = pdfDocument.TiffImages[i];

                Chapter chapter = new Chapter(pdfDocument.ChapterTitle, pdfDocument.ChapterNumber);

                document.Add(chapter);

                for (int count = 0; count < tiffImages.Length; count++)
                {
                    Bitmap bitmap = new Bitmap(tiffImages[count]);
                    int total = bitmap.GetFrameCount(System.Drawing.Imaging.FrameDimension.Page);

                    PdfContentByte cb = writer.DirectContent;

                    for (int k = 0; k < total; ++k)
                    {
                        bitmap.SelectActiveFrame(System.Drawing.Imaging.FrameDimension.Page, k);
                        Image image = Image.GetInstance(bitmap, System.Drawing.Imaging.ImageFormat.Bmp);

                        image.ScalePercent(72f / image.DpiX * 100);
                        image.SetAbsolutePosition(0, 0);
                        cb.AddImage(image);
                        document.NewPage();
                    }
                }
            }
            UpdateProperties(document);
            document.Close();
        }
开发者ID:ebruning,项目名称:Enhanced-PDF-Export,代码行数:40,代码来源:PdfGenerator.cs

示例15: WriteAnimatedGif

        private void WriteAnimatedGif(Bitmap src, Stream output, IEncoder ios, ResizeSettings queryString)
        {
            //http://www.fileformat.info/format/gif/egff.htm
            //http://www.fileformat.info/format/gif/spec/44ed77668592476fb7a682c714a68bac/view.htm

            //Heavily modified and patched from comments on http://bloggingabout.net/blogs/rick/archive/2005/05/10/3830.aspx
            MemoryStream memoryStream = null;
            BinaryWriter writer = null;
            //Variable declaration
            try
            {
                writer = new BinaryWriter(output);
                memoryStream = new MemoryStream(4096);
                //Write the GIF 89a sig
                writer.Write(new byte[] { (byte)'G', (byte)'I', (byte)'F', (byte)'8', (byte)'9', (byte)'a' });

                //We parse this from the source image
                int loops = GetLoops(src.PropertyItems);
                int[] delays = GetDelays(src.PropertyItems);//20736 (delays) 20737 (loop);

                int frames = src.GetFrameCount(FrameDimension.Time);
                for (int frame = 0; frame < frames; frame++)
                {
                    //Select the frame
                    src.SelectActiveFrame(FrameDimension.Time, frame);

                    // http://radio.weblogs.com/0122832/2005/10/20.html
                    //src.MakeTransparent(); This call makes some GIFs replicate the first image on all frames.. i.e. SelectActiveFrame doesn't work.

                    using (Bitmap b = c.CurrentImageBuilder.Build(src,queryString,false)){
                        //Useful to check if animation is occuring - sometimes the problem isn't the output file, but the input frames are
                        //all the same.
                        //for (var i = 0; i < b.Height; i++) b.SetPixel(frame * 10, i, Color.Green);
                        // b.Save(memoryStream, ImageFormat.Gif);
                        ios.Write(b, memoryStream); //Allows quantization and dithering
                    }

                    GifClass gif = new GifClass();
                    gif.LoadGifPicture(memoryStream);
                    if (frame == 0)
                    {
                        //Only one screen descriptor per file. Steal from the first image
                        writer.Write(gif.m_ScreenDescriptor.ToArray());
                        //How many times to loop the image (unless it is 1) IE and FF3 loop endlessley if loop=1
                        if (loops != 1)
                            writer.Write(GifCreator.CreateLoopBlock(loops));
                    }
                    //Restore frame delay
                    int delay = 0;
                    if (delays != null && delays.Length > frame) delay = delays[frame];
                    writer.Write(GifCreator.CreateGraphicControlExtensionBlock(delay)); //The delay/transparent color block
                    writer.Write(gif.m_ImageDescriptor.ToArray()); //The image desc
                    writer.Write(gif.m_ColorTable.ToArray()); //The palette
                    writer.Write(gif.m_ImageData.ToArray()); //Image data

                    memoryStream.SetLength(0); //Clear the mem stream, but leave it allocated for now
                    memoryStream.Seek(0, SeekOrigin.Begin); //Reset memory buffer
                }

                writer.Write((byte)0x3B); //End file
            }
            finally
            {
               if (memoryStream != null) memoryStream.Dispose();
               //if (writer != null) writer.Close
            }
        }
开发者ID:eakova,项目名称:resizer,代码行数:67,代码来源:AnimatedGifs.cs


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