本文整理汇总了C#中System.Drawing.Bitmap.SelectActiveFrame方法的典型用法代码示例。如果您正苦于以下问题:C# Bitmap.SelectActiveFrame方法的具体用法?C# Bitmap.SelectActiveFrame怎么用?C# Bitmap.SelectActiveFrame使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Drawing.Bitmap
的用法示例。
在下文中一共展示了Bitmap.SelectActiveFrame方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: 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();
}
示例2: 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;
}
示例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);
}
}
示例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);
}
示例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;
}
}
}
示例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);
}
示例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();
}
示例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);
*/
}
}
示例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));
}
}
}
示例10: addDirectionsAddWithCanvasUniqueImageToolStripMenuItem_Click
//Add Directions with Canvas ( CV5 style GIF )
private void addDirectionsAddWithCanvasUniqueImageToolStripMenuItem_Click(object sender, EventArgs e)
{
try
{
if (FileType != 0)
{
using (OpenFileDialog dialog = new OpenFileDialog())
{
dialog.Multiselect = false;
dialog.Title = "Choose 1 Gif ( with all directions in CV5 Style ) to add";
dialog.CheckFileExists = true;
dialog.Filter = "Gif files (*.gif;)|*.gif;";
if (dialog.ShowDialog() == DialogResult.OK)
{
Color CustomConvert = Color.FromArgb(255, (int)numericUpDown3.Value, (int)numericUpDown4.Value, (int)numericUpDown5.Value);
trackBar1.Enabled = false;
trackBar1.Value = 0;
Bitmap bmp = new Bitmap(dialog.FileName);
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;
}
//Canvas algorithm
int top = 0;
int bot = 0;
int left = 0;
int right = 0;
int RegressT = -1;
int RegressB = -1;
int RegressL = -1;
int RegressR = -1;
bool var = true;
bool breakOK = false;
// position 0
//Top
for (int Yf = 0; Yf < bitbmp[(frameCount / 8) * 4].Height; Yf++)
{
for (int fram = (frameCount / 8) * 4; fram < (frameCount / 8) * 5; fram++)
{
bitbmp[fram].SelectActiveFrame(dimension, fram);
for (int Xf = 0; Xf < bitbmp[(frameCount / 8) * 4].Width; Xf++)
{
Color pixel = bitbmp[fram].GetPixel(Xf, Yf);
if (pixel == WhiteConvert | pixel == GreyConvert | pixel == CustomConvert | pixel.A == 0)
var = true;
if (pixel != WhiteConvert & pixel != GreyConvert & pixel != CustomConvert & pixel.A != 0)
{
var = false;
if (Yf != 0)
{
RegressT++;
Yf -= 1;
Xf = -1;
fram = (frameCount / 8) * 4;
}
else
{
breakOK = true;
break;
}
}
if (var == true && Xf == bitbmp[fram].Width - 1 && fram == (((frameCount / 8) * 5) - 1) && RegressT == -1 && Yf < bitbmp[0].Height - 9)
top += 10;
if (var == true && Xf == bitbmp[fram].Width - 1 && fram == (((frameCount / 8) * 5) - 1) && RegressT == -1 && Yf >= bitbmp[0].Height - 9)
top++;
if (var == true && Xf == bitbmp[fram].Width - 1 && fram == (((frameCount / 8) * 5) - 1) && RegressT != -1)
{
top = top - RegressT;
breakOK = true;
break;
}
}
if (breakOK == true)
break;
}
if (Yf < bitbmp[(frameCount / 8) * 4].Height - 9)
Yf += 9; // 1 of for + 9
if (breakOK == true)
{
breakOK = false;
break;
}
}
//.........这里部分代码省略.........
示例11: OnClickAdd
private void OnClickAdd(object sender, EventArgs e)
{
if (FileType != 0)
{
using (OpenFileDialog dialog = new OpenFileDialog())
{
dialog.Multiselect = true;
dialog.Title = "Choose image file to add";
dialog.CheckFileExists = true;
dialog.Filter = "Gif files (*.gif;)|*.gif; |Bitmap files (*.bmp;)|*.bmp; |Tiff files (*.tiff;)|*tiff; |Png files (*.png;)|*.png; |Jpeg files (*.jpeg;*.jpg;)|*.jpeg;*.jpg;";
if (dialog.ShowDialog() == DialogResult.OK)
{
listView1.BeginUpdate();
//My Soulblighter Modifications
for (int w = 0; w < dialog.FileNames.Length; w++)
{
Bitmap bmp = new Bitmap(dialog.FileNames[w]); // dialog.Filename replaced by dialog.FileNames[w]
AnimIdx edit = Ultima.AnimationEdit.GetAnimation(FileType, CurrBody, CurrAction, CurrDir);
if (dialog.FileName.Contains(".bmp") | dialog.FileName.Contains(".tiff") | dialog.FileName.Contains(".png") | dialog.FileName.Contains(".jpeg") | dialog.FileName.Contains(".jpg"))
{
bmp = Utils.ConvertBmpAnim(bmp, (int)numericUpDown3.Value, (int)numericUpDown4.Value, (int)numericUpDown5.Value);
//edit.GetImagePalette(bmp);
}
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);
Bitmap[] bitbmp = new Bitmap[frameCount];
bmp.SelectActiveFrame(dimension, 0);
edit.GetGifPalette(bmp);
progressBar1.Maximum = 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();
numericUpDownCx.Value = edit.Frames[trackBar2.Value].Center.X;
numericUpDownCy.Value = edit.Frames[trackBar2.Value].Center.Y;
Options.ChangedUltimaClass["Animations"] = true;
}
//End of Soulblighter Modifications
else
{
edit.AddFrame(bmp);
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;
//.........这里部分代码省略.........
示例12: 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;
}
}
}
}
}
示例13: 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);
//.........这里部分代码省略.........
示例14: AddFrameToImage
private static void AddFrameToImage(Bitmap ImageToSaveInto, Bitmap ImageToAdd, int FrameId, EncoderParameters EncodeParameters)
{
//set the active page
ImageToAdd.SelectActiveFrame(FrameDimension.Page, FrameId);
//add the page to the image
ImageToSaveInto.SaveAdd(ImageToAdd, EncodeParameters);
}
示例15: 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();
}