Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Updated AddFrame method to handle Gif as source #12

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -161,3 +161,4 @@ pip-log.txt

# Mac crap
.DS_Store
/.vs
19 changes: 16 additions & 3 deletions BumpKit/BumpKit/GifEncoder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -69,17 +69,30 @@ public GifEncoder(Stream stream, int? width = null, int? height = null, int? rep
/// <param name="y">The positioning y offset this image should be displayed at.</param>
public void AddFrame(Image img, int x = 0, int y = 0, TimeSpan? frameDelay = null)
{
Image imageToSave = null;

using (MemoryStream ms = new MemoryStream())
{
// save to memory
img.Save(ms, ImageFormat.Png);
ms.Seek(0, SeekOrigin.Begin);
// pull it back out
imageToSave = Image.FromStream(ms);
}

using (var gifStream = new MemoryStream())
{
img.Save(gifStream, ImageFormat.Gif);
imageToSave.Save(gifStream, ImageFormat.Gif);
if (_isFirstImage) // Steal the global color table info
{
InitHeader(gifStream, img.Width, img.Height);
InitHeader(gifStream, imageToSave.Width, imageToSave.Height);
}
WriteGraphicControlBlock(gifStream, frameDelay.GetValueOrDefault(FrameDelay));
WriteImageBlock(gifStream, !_isFirstImage, x, y, img.Width, img.Height);
WriteImageBlock(gifStream, !_isFirstImage, x, y, imageToSave.Width, imageToSave.Height);
}
_isFirstImage = false;

if (imageToSave != null) imageToSave.Dispose();
}

private void InitHeader(Stream sourceGif, int w, int h)
Expand Down
22 changes: 11 additions & 11 deletions BumpKit/Demonstrations/Form1.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

22 changes: 11 additions & 11 deletions BumpKit/Demonstrations/Form1.cs
Original file line number Diff line number Diff line change
@@ -1,14 +1,9 @@
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using BumpKit;
using System;
using System.Drawing;
using System.Drawing.Imaging;
using System.IO;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using BumpKit;

namespace Demonstrations
{
Expand All @@ -19,9 +14,14 @@ public Demonstrations()
InitializeComponent();
}

private void button1_Click(object sender, EventArgs e)
private void btnOpen_Click(object sender, EventArgs e)
{
var dlg = new OpenFileDialog { Title = "Please select an image to open:", Filter = "Jpeg|*.jpg|Jpeg|*.jpeg|Png|*.png|Bitmap|*.bmp" };
var dlg = new OpenFileDialog
{
Title = "Please select an image to open:",
Filter = "All Supported Images|*gif; *jpg; *png; *.bmp|Gif|*.gif|Jpeg|*.jpg|Jpeg|*.jpeg|Png|*.png|Bitmap|*.bmp"
};

if (dlg.ShowDialog() != DialogResult.OK)
return;

Expand All @@ -38,7 +38,7 @@ private void button1_Click(object sender, EventArgs e)

// Rotate and fit
_rotateFit.BackgroundImage = img.ScaleToFit(_rotateFit.Size, false).Rotate(45, ScalingMode.FitContent).ScaleToFit(_rotateOverflow.Size);

// Rotate and overflow
_rotateOverflow.BackgroundImage = img.ScaleToFit(_rotateOverflow.Size, false).Rotate(45);

Expand Down Expand Up @@ -86,7 +86,7 @@ private void button1_Click(object sender, EventArgs e)
using (var gfx = Graphics.FromImage(_textGen.BackgroundImage))
{
gfx.DrawString("A B C 1 2 3", new Font(FontFamily.Families.First(f => f.Name.Contains("Times")), 15), Brushes.Green, 15, 25, 10,
new[] {Color.Yellow, Color.Blue, Color.Red, Color.Green, Color.Purple, Color.Black},
new[] { Color.Yellow, Color.Blue, Color.Red, Color.Green, Color.Purple, Color.Black },
new[] { 0, (float).20, (float).40, (float).60, (float).80, 1 });
}
}
Expand Down
39 changes: 28 additions & 11 deletions BumpKit/Demonstrations/Program.cs
Original file line number Diff line number Diff line change
@@ -1,12 +1,7 @@
using System;
using System.Collections.Generic;
using System.Diagnostics;
using BumpKit;
using System;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Drawing.Text;
using System.Linq;
using System.Windows.Forms;
using BumpKit;
using System.IO;

namespace Demonstrations
{
Expand All @@ -18,9 +13,31 @@ static class Program
[STAThread]
static void Main()
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new Demonstrations());
//Application.EnableVisualStyles();
//Application.SetCompatibleTextRenderingDefault(false);
//Application.Run(new Demonstrations());


using (FileStream fs = new FileStream(@"E:\123.gif", FileMode.OpenOrCreate))
{
GifEncoder gifEncoder = new GifEncoder(fs);

foreach (string item in Directory.EnumerateFiles(@"E:\Pictures"))
{
try
{
Image img = Image.FromFile(item);
gifEncoder.AddFrame(Image.FromFile(item));
}
catch
{

}

}
}


}
}
}