public override void Draw() { switch (dir) { case Direction.Down: downImage.SelectActiveFrame(System.Drawing.Imaging.FrameDimension.Time, fDown); int newWidth = (int)Math.Round(((decimal)downImage.Width / downImage.Height) * width); g.DrawImage(downImage, x + (30 - newWidth) / 2, y, newWidth, 30); break; case Direction.Left: leftImage.SelectActiveFrame(System.Drawing.Imaging.FrameDimension.Time, fLeft); g.DrawImage(leftImage, x + 1, y, 27, 30); break; case Direction.Right: rightImage.SelectActiveFrame(System.Drawing.Imaging.FrameDimension.Time, fRight); g.DrawImage(rightImage, x + 1, y, 27, 30); break; case Direction.Up: upImage.SelectActiveFrame(System.Drawing.Imaging.FrameDimension.Time, fUp); g.DrawImage(upImage, x + 4, y, 22, 30); break; } }
public static void ConvertFirstApproach() { // creation of the document with a certain size and certain margins iTextSharp.text.Document document = new iTextSharp.text.Document(iTextSharp.text.PageSize.A4, 0, 0, 0, 0); // creation of the different writers iTextSharp.text.pdf.PdfWriter writer = iTextSharp.text.pdf.PdfWriter.GetInstance(document, new System.IO.FileStream(@"C:\Users\Mohd\Documents\visual studio 2013\Projects\TiffToPDF\TiffToPDF\tiff.tif.pdf", System.IO.FileMode.Create)); // load the tiff image and count the total pages System.Drawing.Bitmap bm = new System.Drawing.Bitmap(@"C:\Users\Mohd\Documents\visual studio 2013\Projects\TiffToPDF\TiffToPDF\tiff.tif"); int total = bm.GetFrameCount(System.Drawing.Imaging.FrameDimension.Page); document.Open(); iTextSharp.text.pdf.PdfContentByte cb = writer.DirectContent; for (int k = 0; k < total; ++k) { bm.SelectActiveFrame(System.Drawing.Imaging.FrameDimension.Page, k); iTextSharp.text.Image img = iTextSharp.text.Image.GetInstance(bm, ImageFormat.Jpeg); img.SetAbsolutePosition(0, 0); img.ScaleAbsolute(500, 500); // img.ScalePercent(72f / img.DpiX * 100); img.ScaleAbsoluteHeight(document.PageSize.Height); img.ScaleAbsoluteWidth(document.PageSize.Width); // img.CompressionLevel = 1; // img.Deflated = true; cb.AddImage(img); document.NewPage(); } document.Close(); }
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); } }
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(); }
private void button2_Click(object sender, EventArgs e) { if (textBox1.Text.Trim() != string.Empty) { iTextSharp.text.Document document = new iTextSharp.text.Document(iTextSharp.text.PageSize.A4, 0, 0, 0, 0); // creation of the different writers iTextSharp.text.pdf.PdfWriter writer = iTextSharp.text.pdf.PdfWriter.GetInstance(document, new System.IO.FileStream(@"C:\temp\Converted.pdf", System.IO.FileMode.Create)); // load the tiff image and count the total pages System.Drawing.Bitmap bm = new System.Drawing.Bitmap(this.openFileDialog1.FileName); int total = bm.GetFrameCount(System.Drawing.Imaging.FrameDimension.Page); document.Open(); iTextSharp.text.pdf.PdfContentByte cb = writer.DirectContent; for (int k = 0; k < total; ++k) { bm.SelectActiveFrame(System.Drawing.Imaging.FrameDimension.Page, k); iTextSharp.text.Image img = iTextSharp.text.Image.GetInstance(bm, ImageFormat.Tiff); img.SetAbsolutePosition(0, 0); img.ScaleAbsoluteHeight(document.PageSize.Height); img.ScaleAbsoluteWidth(document.PageSize.Width); cb.AddImage(img); document.NewPage(); } document.Close(); axAcroPDF1.LoadFile(@"C:\temp\Converted.pdf"); } }
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; }
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); }
private void PlayWin(object o, EventArgs e) { winImage.SelectActiveFrame(System.Drawing.Imaging.FrameDimension.Time, fWin++); g.FillRectangle(new SolidBrush(Color.Black), 20, 20, 30 + big, (int)((22 + big) * 1.375)); g.DrawImage(winImage, 20, 20, 30 + big, (int)(22 + big * 1.375)); System.Threading.Thread.Sleep(50); if (fWin > winImage.GetFrameCount(System.Drawing.Imaging.FrameDimension.Time) - 2) { fWin = 0; ImageAnimator.StopAnimate(winImage, new EventHandler(this.PlayWin)); } big += 5; }
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); }
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; } } }
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(); }
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); */ } }
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)); } } }
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; listView1.TileSize = new Size(width + 5, height + 5); trackBar2.Maximum = i; numericUpDownCx.Value = edit.Frames[trackBar2.Value].Center.X; numericUpDownCy.Value = edit.Frames[trackBar2.Value].Center.Y; Options.ChangedUltimaClass["Animations"] = true; } } } listView1.EndUpdate(); listView1.Invalidate(); } } } //Refresh List CurrDir = trackBar1.Value; AfterSelectTreeView(null, null); }
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 } }
internal static string SaveUploadFile(string strFileExt, byte[] data, string strSessionID) { string strFileName = GetNextFileIndex(strFileExt, strSessionID); if (strFileExt.ToLower() == "tif" || strFileExt.ToLower() == "tiff") { using (MemoryStream memdata = new MemoryStream(data)) { string strAryFileName = ""; using (Bitmap map = new Bitmap(memdata)) { string strFileNameTemp = strFileName; int pages = map.GetFrameCount(FrameDimension.Page); for(int i= 0; i< pages; i++) { if (strAryFileName.Length == 0) strAryFileName = strAryFileName + strFileNameTemp; else strAryFileName = strAryFileName + ":" + strFileNameTemp; map.SelectActiveFrame(FrameDimension.Page, i); Bitmap bitmap = new Bitmap(map); bitmap.Save(UploadFolder + System.IO.Path.DirectorySeparatorChar + strSessionID + System.IO.Path.DirectorySeparatorChar + strFileNameTemp, System.Drawing.Imaging.ImageFormat.Png); if (bitmap != null) bitmap.Dispose(); strFileNameTemp = (i + 1).ToString() + strFileName; } } strFileName = strAryFileName; } } else using (FileStream fs = File.Open(UploadFolder + System.IO.Path.DirectorySeparatorChar + strSessionID + System.IO.Path.DirectorySeparatorChar + strFileName, FileMode.Truncate, FileAccess.Write)) { fs.Write(data, 0, data.Length); } return strFileName; }
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(); }
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); }
public static Bitmap WaterMarkWithText(System.Drawing.Bitmap origialGif, string text, string filePath) { //用于存放桢 List <Frame> frames = new List <Frame>(); //如果不是gif文件,直接返回原图像 if (origialGif.RawFormat.Guid != System.Drawing.Imaging.ImageFormat.Gif.Guid) { return(origialGif); } //如果该图像是gif文件 foreach (Guid guid in origialGif.FrameDimensionsList) { System.Drawing.Imaging.FrameDimension frameDimension = new System.Drawing.Imaging.FrameDimension(guid); int frameCount = origialGif.GetFrameCount(frameDimension); for (int i = 0; i < frameCount; i++) { if (origialGif.SelectActiveFrame(frameDimension, i) == 0) { int delay = Convert.ToInt32(origialGif.GetPropertyItem(20736).Value.GetValue(i)); Image img = Image.FromHbitmap(origialGif.GetHbitmap()); Font font = new Font(new FontFamily("宋体"), 35.0f, FontStyle.Bold); Graphics g = Graphics.FromImage(img); g.DrawString(text, font, Brushes.BlanchedAlmond, new PointF(10.0f, 10.0f)); Frame frame = new Frame(img, delay); frames.Add(frame); } } //Gif.Components.AnimatedGifEncoder gif = //new Gif.Components.AnimatedGifEncoder(); //gif.Start(filePath); //gif.SetDelay(100); //gif.SetRepeat(0); //for (int i = 0; i < //frames.Count; i++) //{ // gif.AddFrame(frames[i].Image); //} //gif.Finish(); try { Bitmap gifImg = (Bitmap)Bitmap.FromFile(filePath); return(gifImg); } catch { return(origialGif); } } return(origialGif); }
//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); 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++; } } } } trackBar1.Enabled = true; } } } //Refresh List CurrDir = trackBar1.Value; AfterSelectTreeView(null, null); }
/// <summary> /// Parses individual Bitmap frames from a multi-frame Bitmap into an array of Bitmaps /// Get the number of animation frames to copy into a Bitmap array /// /// </summary> /// <param name="Animation"></param> /// <returns>Bitmap[] Copy the animation frame</returns> public Bitmap[] ParseFrames(Bitmap Animation) { // Get the number of animation frames to copy into a Bitmap array int Length = Animation.GetFrameCount(FrameDimension.Time); // Allocate a Bitmap array to hold individual frames from the animation Bitmap[] Frames = new Bitmap[Length]; // Copy the animation Bitmap frames into the Bitmap array for (int Index = 0; Index < Length; Index++) { // Set the current frame within the animation to be copied into the Bitmap array element Animation.SelectActiveFrame(FrameDimension.Time, Index); // Create a new Bitmap element within the Bitmap array in which to copy the next frame Frames[Index] = new Bitmap(Animation.Size.Width, Animation.Size.Height); // Copy the current animation frame into the new Bitmap array element Graphics.FromImage(Frames[Index]).DrawImage(Animation, new Point(0, 0)); } // Return the array of Bitmap frames return Frames; }
protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { String url = Page.Request.QueryString["url"]; String fromMemory = Page.Request.QueryString["memory"]; if (url != null) { try { lblError.Text = ""; System.Net.HttpWebRequest request = (System.Net.HttpWebRequest)System.Net.WebRequest.Create(url); request.UseDefaultCredentials = true; System.Net.HttpWebResponse response = (System.Net.HttpWebResponse)request.GetResponse(); System.IO.Stream responseStream = response.GetResponseStream(); string fileName = Path.GetRandomFileName(); //new System.Drawing.Bitmap(responseStream).Save(@"C:\Digitas\" + fileName + ".tif", System.Drawing.Imaging.ImageFormat.Tiff); //System.IO.Stream tbStream = File.OpenRead(@"C:\Digitas\" + fileName + ".tif"); decoder = new TiffBitmapDecoder(responseStream, BitmapCreateOptions.PreservePixelFormat, BitmapCacheOption.Default); int pagecount = decoder.Frames.Count; //lblError.Text = pagecount.ToString(); TiffBitmapEncoder encoderFile = new TiffBitmapEncoder(); images = new List <System.Drawing.Image>(); for (int i = 0; i < decoder.Frames.Count; i++) { MemoryStream ms = new MemoryStream(); TiffBitmapEncoder encoder = new TiffBitmapEncoder(); //ddlPaginas.Items.Add("Página " + (i + 1)); encoder.Frames.Add(decoder.Frames[i]); encoder.Save(ms); System.Drawing.Image img = System.Drawing.Image.FromStream(ms); images.Add(img); MemoryStream ms3 = new MemoryStream(); images[i].Save(ms3, System.Drawing.Imaging.ImageFormat.Tiff); System.Windows.Media.Imaging.BitmapFrame bmFrame = System.Windows.Media.Imaging.BitmapFrame.Create(ms3); encoderFile.Frames.Add(bmFrame); } Session["images"] = images; System.IO.FileStream fsTemp = new System.IO.FileStream(@"C:\Digitas\" + fileName + ".tif", FileMode.Create); encoderFile.Save(fsTemp); fsTemp.Close(); //Response.ContentType = "image/jpeg"; //new System.Drawing.Bitmap(responseStream).Save(@"C:\Digitas\Temp_Tiff.tif", System.Drawing.Imaging.ImageFormat.Tiff); iTextSharp.text.Document document = new iTextSharp.text.Document(iTextSharp.text.PageSize.LETTER, 5, 5, 5, 5); iTextSharp.text.pdf.PdfWriter writer = iTextSharp.text.pdf.PdfWriter.GetInstance(document, new System.IO.FileStream(@"C:\Digitas\" + fileName + ".pdf", System.IO.FileMode.Create)); System.Drawing.Bitmap bm = new System.Drawing.Bitmap(@"C:\Digitas\" + fileName + ".tif"); int total = bm.GetFrameCount(System.Drawing.Imaging.FrameDimension.Page); document.Open(); iTextSharp.text.pdf.PdfContentByte cb = writer.DirectContent; for (int k = 0; k < total; ++k) { bm.SelectActiveFrame(System.Drawing.Imaging.FrameDimension.Page, k); iTextSharp.text.Image img = iTextSharp.text.Image.GetInstance(bm, System.Drawing.Imaging.ImageFormat.Bmp); // scale the image to fit in the page img.ScaleAbsolute(600, 800); img.SetAbsolutePosition(0, 0); cb.AddImage(img); document.NewPage(); } document.Close(); Response.ContentType = "Application/pdf"; Response.TransmitFile(@"C:\Digitas\" + fileName + ".pdf"); /* * System.Drawing.Image img = System.Drawing.Image.FromStream(responseStream); * * Tiff image = Tiff.ClientOpen("memory", "r", responseStream, new TiffStream()); * * if (img == null) * { * lblError.Text = "Null image s"; * } * else * { * img.Save(@"C:\Digitas\digit.tif"); * } * * if (image == null) * { * lblError.Text = "Null image tiff"; * } * else * { * var num = image.NumberOfDirectories(); * lblError.Text = num.ToString(); * } */ /* * MemoryStream ms2 = new MemoryStream(); * images[0].Save(ms2, System.Drawing.Imaging.ImageFormat.Jpeg); * //BinaryReader br = new BinaryReader(ms2); * //Byte[] bytes = br.ReadBytes((Int32)ms2.Length); * byte[] bytes = ms2.ToArray(); * //string base64String = Convert.ToBase64String(bytes, 0, bytes.Length); * string base64String = Convert.ToBase64String(bytes); * //string base64String = Convert.ToBase64String((byte[])img); * Image1.ImageUrl = "data:image/jpg;base64," + base64String; */ /* * Session["images"] = images; * * * var document = new Document(PageSize.LETTER, 5, 5, 5, 5); * * // Create a new PdfWriter object, specifying the output stream * var output = new MemoryStream(); * var writer = PdfWriter.GetInstance(document, output); * * document.Open(); * * for (int i = 0; i < images.Count; i++) * { * var image = iTextSharp.text.Image.GetInstance(images[i], iTextSharp.text.BaseColor.WHITE); * image.ScaleAbsolute(600, 800); * document.Add(image); * document.NewPage(); * } * * document.Close(); * * Response.ContentType = "application/pdf"; * //Response.AddHeader("Content-Disposition", string.Format("attachment;filename=Receipt-{0}.pdf", txtOrderID.Text)); * Response.BinaryWrite(output.ToArray()); * * * // Open the Document for writing * * //img.Save(@"C:\Digitas\digit2.jpg"); * * //Response.ContentType = "image/jpeg"; * //new System.Drawing.Bitmap(ms).Save(Response.OutputStream, System.Drawing.Imaging.ImageFormat.Jpeg); * * //HttpContext.Current.Response.Flush(); * //HttpContext.Current.Response.SuppressContent = true; * //HttpContext.Current.ApplicationInstance.CompleteRequest(); * * /*HttpContext.Current.Response.Flush(); * HttpContext.Current.Response.SuppressContent = true; * HttpContext.Current.ApplicationInstance.CompleteRequest(); * * /*FileWebRequest request = (FileWebRequest)WebRequest.Create(url); * * request.UseDefaultCredentials = true; * * System.Net.FileWebResponse response = (System.Net.FileWebResponse)request.GetResponse();*/ //System.IO.Stream responseStream = response.GetResponseStream(); /*System.IO.StreamReader reader = new StreamReader(responseStream); * * if (reader == null) * { * lblError.Text = "Null"; * } * else * { * MemoryStream ms = new MemoryStream(); * responseStream.CopyTo(ms); * /*responseStream.Close(); * reader.Close(); * * Tiff image = Tiff.ClientOpen("memory", "r", ms, new TiffStream()); * * if (image == null) * { * lblError.Text = "Null image"; * } * lblError.Text = ms.Length.ToString(); * using (FileStream file = new FileStream(@"C:\Digitas\digit.tif", FileMode.Create, System.IO.FileAccess.Write)) * { * byte[] bytes = new byte[ms.Length]; * ms.Read(bytes, 0, (int)ms.Length); * file.Write(bytes, 0, bytes.Length); * //ms.Close(); * //file.Close(); * } * * Tiff image = Tiff.Open(@"C:\Digitas\digit.tif", "r"); * if (image == null) * { * lblError.Text = "Null image"; * } * else * { * var num = image.NumberOfDirectories(); * lblError.Text = num.ToString(); * } * * * }*/ } catch (System.Exception ex) { lblError.Text = lblError.Text + " 0.- " + ex.Message; } } else if (fromMemory == null) { try { RPPMain.SharepointLibrary spLibrary = new RPPMain.SharepointLibrary("http://servidors04/sitios/digitalizacion", "Seccion Primera", "autostore", "Rpp1234"); //RPPMain.SharepointLibrary spLibrary = new RPPMain.SharepointLibrary("http://servidors04/sitios/digitalizacion", "Seccion Primera", "administrador", "Zmy45r1"); //int documentoID = int.Parse(Page.Request.QueryString["documentoID"]); String reg_act_tomo = Page.Request.QueryString["tomo"]; String reg_act_semestre = Page.Request.QueryString["semestre"]; String reg_act_año = Page.Request.QueryString["anio"]; String reg_act_seccion = Page.Request.QueryString["seccion"]; String reg_act_serie = Page.Request.QueryString["serie"]; String reg_act_partida = Page.Request.QueryString["partida"]; String reg_act_libro = Page.Request.QueryString["libro"]; bool firstParameter = true; bool secondParameter = false; bool nextParameter = false; string query = ""; if (reg_act_tomo.Length > 0) { if (firstParameter) { query = query + "<And><Eq><FieldRef Name='Fec_Reg_Tomo' /><Value Type='Text'>{0}</Value></Eq>"; firstParameter = false; secondParameter = true; } else { if (secondParameter) { query = query + "<Eq><FieldRef Name='Fec_Reg_Tomo' /><Value Type='Text'>{0}</Value></Eq></And>"; secondParameter = false; nextParameter = true; } else { query = "<And>" + query + "<Eq><FieldRef Name='Fec_Reg_Tomo' /><Value Type='Text'>{0}</Value></Eq></And>"; } } } if (reg_act_semestre.Length > 0) { if (firstParameter) { query = query + "<And><Eq><FieldRef Name='Fec_Reg_Semestre' /><Value Type='Text'>{1}</Value></Eq>"; firstParameter = false; secondParameter = true; } else { if (secondParameter) { query = query + "<Eq><FieldRef Name='Fec_Reg_Semestre' /><Value Type='Text'>{1}</Value></Eq></And>"; secondParameter = false; nextParameter = true; } else { query = "<And>" + query + "<Eq><FieldRef Name='Fec_Reg_Semestre' /><Value Type='Text'>{1}</Value></Eq></And>"; } } } if (reg_act_año.Length > 0) { if (firstParameter) { query = query + "<And><Eq><FieldRef Name='Fec_Reg_A_x00f1_o_x0020_Semestre' /><Value Type='Text'>{2}</Value></Eq>"; firstParameter = false; secondParameter = true; } else { if (secondParameter) { query = query + "<Eq><FieldRef Name='Fec_Reg_A_x00f1_o_x0020_Semestre' /><Value Type='Text'>{2}</Value></Eq></And>"; secondParameter = false; nextParameter = true; } else { query = "<And>" + query + "<Eq><FieldRef Name='Fec_Reg_A_x00f1_o_x0020_Semestre' /><Value Type='Text'>{2}</Value></Eq></And>"; } } } if (reg_act_seccion.Length > 0) { if (firstParameter) { query = query + "<And><Eq><FieldRef Name='Fec_Reg_Seccion' /><Value Type='Text'>{3}</Value></Eq>"; firstParameter = false; secondParameter = true; } else { if (secondParameter) { query = query + "<Eq><FieldRef Name='Fec_Reg_Seccion' /><Value Type='Text'>{3}</Value></Eq></And>"; secondParameter = false; nextParameter = true; } else { query = "<And>" + query + "<Eq><FieldRef Name='Fec_Reg_Seccion' /><Value Type='Text'>{3}</Value></Eq></And>"; } } } if (reg_act_serie.Length > 0) { if (firstParameter) { query = query + "<And><Eq><FieldRef Name='Fec_Reg_Partida' /><Value Type='Text'>{4}</Value></Eq>"; firstParameter = false; secondParameter = true; } else { if (secondParameter) { query = query + "<Eq><FieldRef Name='Fec_Reg_Partida' /><Value Type='Text'>{4}</Value></Eq></And>"; secondParameter = false; nextParameter = true; } else { query = "<And>" + query + "<Eq><FieldRef Name='Fec_Reg_Partida' /><Value Type='Text'>{4}</Value></Eq></And>"; } } } if (reg_act_partida.Length > 0) { if (firstParameter) { query = query + "<And><Eq><FieldRef Name='Partida' /><Value Type='Text'>{5}</Value></Eq>"; firstParameter = false; secondParameter = true; } else { if (secondParameter) { query = query + "<Eq><FieldRef Name='Partida' /><Value Type='Text'>{5}</Value></Eq></And>"; secondParameter = false; nextParameter = true; } else { query = "<And>" + query + "<Eq><FieldRef Name='Partida' /><Value Type='Text'>{5}</Value></Eq></And>"; } } } if (reg_act_libro.Length > 0) { if (firstParameter) { query = query + "<And><Eq><FieldRef Name='Fec_Reg_Libro' /><Value Type='Text'>{6}</Value></Eq>"; firstParameter = false; secondParameter = true; } else { if (secondParameter) { query = query + "<Eq><FieldRef Name='Fec_Reg_Libro' /><Value Type='Text'>{6}</Value></Eq></And>"; secondParameter = false; nextParameter = true; } else { query = "<And>" + query + "<Eq><FieldRef Name='Fec_Reg_Libro' /><Value Type='Text'>{6}</Value></Eq></And>"; } } } query = "<View><Query><Where>" + query + "</Where></Query></View>"; query = string.Format(@"<View> <Query> <Where> <And> <And> <And> <And> <And> <And> <Eq><FieldRef Name='Fec_Reg_Tomo' /><Value Type='Text'>{0}</Value></Eq> <Eq><FieldRef Name='Fec_Reg_Semestre' /><Value Type='Text'>{1}</Value></Eq> </And> <Eq><FieldRef Name='Fec_Reg_A_x00f1_o_x0020_Semestre' /><Value Type='Text'>{2}</Value></Eq> </And> <Eq><FieldRef Name='Fec_Reg_Seccion' /><Value Type='Text'>{3}</Value></Eq> </And> <Eq><FieldRef Name='Fec_Reg_Partida' /><Value Type='Text'>{4}</Value></Eq> </And> <Eq><FieldRef Name='Partida' /><Value Type='Text'>{5}</Value></Eq> </And> <Eq><FieldRef Name='Fec_Reg_Libro' /><Value Type='Text'>{6}</Value></Eq> </And> </Where> </Query> </View>", reg_act_tomo, reg_act_semestre, reg_act_año, reg_act_seccion, reg_act_serie, reg_act_partida, reg_act_libro); /*query = string.Format(@query, * reg_act_tomo, * reg_act_semestre, * reg_act_año, * reg_act_seccion, * reg_act_serie, * reg_act_partida, * reg_act_libro);*/ /*string query = string.Format(@"<View> * <Query> * <Where> * <And> * <And> * <And> * <Eq><FieldRef Name='Fec_Reg_Libro' /><Value Type='Text'>{0}</Value></Eq> * <Eq><FieldRef Name='Partida' /><Value Type='Text'>{1}</Value></Eq> * </And> * <Eq><FieldRef Name='Fec_Reg_Seccion' /><Value Type='Text'>{2}</Value></Eq> * </And> * <Eq><FieldRef Name='Fec_Reg_Partida' /><Value Type='Text'>{3}</Value></Eq> * </And> * </Where> * </Query> * </View>", * 2384, * 1, * 1, * "A");*/ System.Collections.ArrayList arlRows = spLibrary.GetLibraryItem(query); if (arlRows.Count > 0) { lblError.Text = ""; Microsoft.SharePoint.Client.ListItem itemRepositorio = (Microsoft.SharePoint.Client.ListItem)arlRows[0]; Dictionary <string, object> dc = (Dictionary <string, object>)itemRepositorio.FieldValues; Microsoft.SharePoint.Client.FieldUrlValue fURl = (Microsoft.SharePoint.Client.FieldUrlValue)dc["Pagina"]; try { System.Net.HttpWebRequest request = (System.Net.HttpWebRequest)System.Net.WebRequest.Create(fURl.Url); request.UseDefaultCredentials = true; System.Net.HttpWebResponse response = (System.Net.HttpWebResponse)request.GetResponse(); System.IO.Stream responseStream = response.GetResponseStream(); /*Response.ContentType = "image/jpeg"; * new System.Drawing.Bitmap(responseStream).Save(Response.OutputStream, System.Drawing.Imaging.ImageFormat.Jpeg); * * HttpContext.Current.Response.Flush(); * HttpContext.Current.Response.SuppressContent = true; * HttpContext.Current.ApplicationInstance.CompleteRequest();*/ } catch (System.Exception ex) { lblError.Text = lblError.Text + " 1.- " + ex.Message; } } } catch (System.Exception ex) { lblError.Text = lblError.Text + " 2.- " + ex.Message; } } else if (fromMemory != null) { try { images = new List <System.Drawing.Image>(); images = (List <System.Drawing.Image>)Session["images"]; TiffBitmapEncoder encoder = new TiffBitmapEncoder(); MemoryStream ms3 = new MemoryStream(); for (int i = 0; i < images.Count; i++) { //ddlPaginas.Items.Add("Página " + (i + 1)); ms3 = new MemoryStream(); images[i].Save(ms3, System.Drawing.Imaging.ImageFormat.Tiff); System.Windows.Media.Imaging.BitmapFrame bmFrame = System.Windows.Media.Imaging.BitmapFrame.Create(ms3); encoder.Frames.Add(bmFrame); } /* * MemoryStream ms2 = new MemoryStream(); * images[0].Save(ms2, System.Drawing.Imaging.ImageFormat.Jpeg); * byte[] bytes = ms2.ToArray(); * string base64String = Convert.ToBase64String(bytes); * Image1.ImageUrl = "data:image/jpg;base64," + base64String; * * /*string fileName = Path.GetTempFileName(); * * lblError.Text = fileName; * * Session["tempFileName"] = fileName;*/ string fileName = Path.GetRandomFileName(); Session["tempFileName"] = fileName + ".tif"; System.IO.FileStream fsTemp = new System.IO.FileStream(@"C:\Digitas\" + fileName + ".tif", FileMode.Create); encoder.Save(fsTemp); fsTemp.Close(); iTextSharp.text.Document document = new iTextSharp.text.Document(iTextSharp.text.PageSize.LETTER, 5, 5, 5, 5); iTextSharp.text.pdf.PdfWriter writer = iTextSharp.text.pdf.PdfWriter.GetInstance(document, new System.IO.FileStream(@"C:\Digitas\" + fileName + ".pdf", System.IO.FileMode.Create)); System.Drawing.Bitmap bm = new System.Drawing.Bitmap(@"C:\Digitas\" + fileName + ".tif"); int total = bm.GetFrameCount(System.Drawing.Imaging.FrameDimension.Page); document.Open(); iTextSharp.text.pdf.PdfContentByte cb = writer.DirectContent; for (int k = 0; k < total; ++k) { bm.SelectActiveFrame(System.Drawing.Imaging.FrameDimension.Page, k); iTextSharp.text.Image img = iTextSharp.text.Image.GetInstance(bm, System.Drawing.Imaging.ImageFormat.Bmp); // scale the image to fit in the page img.ScaleAbsolute(600, 800); img.SetAbsolutePosition(0, 0); cb.AddImage(img); document.NewPage(); } document.Close(); Response.ContentType = "Application/pdf"; Response.TransmitFile(@"C:\Digitas\" + fileName + ".pdf"); } catch (Exception exc) { lblError.Text = exc.Message; } } } else { //decoder = (TiffBitmapDecoder)Session["decoder"]; images = new List <System.Drawing.Image>(); images = (List <System.Drawing.Image>)Session["images"]; } }
private IImageBuffer BuildBuffer(Size size, Bitmap bmp, FrameDimension frameDimension, int idx) { ConsolePixel[,] buffer = new ConsolePixel[size.Height, size.Width]; bmp.SelectActiveFrame(frameDimension, idx); for (int i = 0; i < size.Height; i++) { for (int j = 0; j < size.Width; j++) { Color c = _sampler.GetSampleColor(size, bmp, j, i, _transparencyColor); ConsolePixel pixel = _converter.CreatePixel(c); buffer[i, j] = pixel; } } Dictionary<string, object> properties = null; // TODO: Move PropertyItem parsing out into separate classes? Do existing libraries exist that might // do this for us? // TODO: Are there any other per-frame properties we want? PropertyItem gifFrameTimeProp = bmp.PropertyItems.FirstOrDefault(pi => pi.Id == 0x5100); if (gifFrameTimeProp != null) { byte[] b = gifFrameTimeProp.Value; long value = b[idx * 4] | (b[(idx * 4) + 1] << 8) | (b[(idx * 4) + 2] << 16) | (b[(idx * 4) + 3] << 24); value = value * 10; // gif frame times are in centi-seconds, not milli-seconds properties = new Dictionary<string, object>(); properties.Add(ImagePropertyConstants.GifFrameTimeMs, value); } return new ImageBuffer(size, buffer, properties); }
static void AnalyzeImage(string filename) { Bitmap bmp; bool page; bool time; bool resolution; int current_frame; int frame_count; BitmapData bitmap_data; page = false; time = false; resolution = false; current_frame = 0; frame_count = 0; bmp = new Bitmap(filename); if (bmp != null) { Guid[] list; PropertyItem[] items; Console.WriteLine("Loaded image '{0}'", filename); list = bmp.FrameDimensionsList; Console.Write("Supported dimensions:"); for (int i = 0; i < list.Length; i++) { if (FrameDimension.Page.Guid == list[i]) { Console.Write(" Page"); page = true; } else if (FrameDimension.Time.Guid == list[i]) { Console.Write(" Time"); time = true; } else if (FrameDimension.Resolution.Guid == list[i]) { Console.Write(" Resolution"); resolution = true; } } Console.WriteLine(""); if (resolution) { frame_count = bmp.GetFrameCount(FrameDimension.Resolution); Console.WriteLine("FrameCount(Resolution):{0}", frame_count); } if (time) { frame_count = bmp.GetFrameCount(FrameDimension.Time); Console.WriteLine("FrameCount(Time):{0}", frame_count); } if (page) { frame_count = bmp.GetFrameCount(FrameDimension.Page); Console.WriteLine("FrameCount(Page):{0}", frame_count); } do { if (page) { bmp.SelectActiveFrame(FrameDimension.Page, current_frame); } else if (time) { bmp.SelectActiveFrame(FrameDimension.Time, current_frame); } else if (resolution) { bmp.SelectActiveFrame(FrameDimension.Resolution, current_frame); } Console.WriteLine("Active Frame: {0}", current_frame); Console.WriteLine(" {0}x{1} pixels", bmp.Width, bmp.Height); Console.WriteLine(" {0}x{1} physical dimensions", bmp.PhysicalDimension.Width, bmp.PhysicalDimension.Height); Console.WriteLine(" {0}x{1} dpi", bmp.HorizontalResolution, bmp.VerticalResolution); Console.WriteLine(" Flags: {0}", (ImageFlags)bmp.Flags); bitmap_data = bmp.LockBits(new Rectangle(0, 0, bmp.Width, bmp.Height), ImageLockMode.ReadOnly, PixelFormat.Format32bppArgb); if (bitmap_data != null) { Console.WriteLine(" BitmapData: {0}x{1} pixels, Stride:{2}, PixelFormat:{3}", bitmap_data.Width, bitmap_data.Height, bitmap_data.Stride, bitmap_data.PixelFormat); bmp.UnlockBits(bitmap_data); } else { Console.WriteLine("Error: Could not get BitmapData"); } items = bmp.PropertyItems; Console.WriteLine("\n Frame {0}, Property count: {1}", current_frame, items.Length); for (int i = 0; i < items.Length; i++) { Console.WriteLine(" [{0,2}]: {1,-11} {2,23} = {3}", i, PropertyTypeAndSize(items[i]), (PropertyTag)items[i].Id, PropertyToString((PropertyTagType)items[i].Type, items[i].Value)); } Console.WriteLine(""); current_frame++; if (current_frame >= frame_count) { if (page) { page = false; if (time || resolution) { frame_count = 0; } } if (time) { time = false; if (resolution) { frame_count = 0; } } } } while (current_frame < frame_count); // bmp.Save("saved" + filename); bmp.Dispose(); } }
public void Frames() { string sInFile = getInFile ("bitmaps/almogaver24bits.bmp"); Bitmap bmp = new Bitmap(sInFile); int cnt = bmp.GetFrameCount(FrameDimension.Page); int active = bmp.SelectActiveFrame (FrameDimension.Page, 0); Assert.AreEqual (1, cnt); Assert.AreEqual (0, active); }
//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; } } } } }
private void bwImport_DoWork(object sender, DoWorkEventArgs e) { bwImport.ReportProgress(0, ""); while (true) { String fptry = null; lock (importFiles) { if (importFiles.Count == 0) break; fptry = importFiles[0]; importFiles.RemoveAt(0); } String fpTIF = null; bool isPDF = false; if (FIUt.IsPDF(fptry)) { fpTIF = tempFiles.NewFile(".tif"); bwImport.ReportProgress(0, "PDF �摜�ϊ�"); if (!PDFUt.PDF2TIF(fptry, fpTIF, null, sizeThumb.Width, null)) { continue; } isPDF = true; } else { fpTIF = fptry; } if (fpTIF != null) { #if true FIMULTIBITMAP tif = FreeImage.OpenMultiBitmapEx(fpTIF, true, false); List<PicProvider> providers = new List<PicProvider>(); try { int nPages = FreeImage.GetPageCount(tif); for (int x = 0; x < nPages; x++) { FIBITMAP dib = FreeImage.LockPage(tif, x); try { FIBITMAP thumb = FreeImage.MakeThumbnail(dib, sizeThumb.Width, true); try { bwImport.ReportProgress(0, String.Format("{0}/{1} from {2}", 1 + x, nPages, fptry)); providers.Add(new PicProvider(FreeImage.GetBitmap(thumb), fpTIF, isPDF ? fptry : null, x, FreeImage.GetBPP(dib) == 1)); } finally { FreeImage.UnloadEx(ref thumb); } } finally { FreeImage.UnlockPage(tif, dib, false); } } } finally { FreeImage.CloseMultiBitmapEx(ref tif); } foreach (PicProvider pp in providers) { AddPage(pp); } #else using (Bitmap pic = new Bitmap(fpTIF)) { int nPages = pic.GetFrameCount(FrameDimension.Page); for (int x = 0; x < nPages; x++) { pic.SelectActiveFrame(FrameDimension.Page, x); AddPage(new PicProvider(ThumbUtil.Make(pic, sizeThumb), fpTIF, isPDF ? fptry : null, x, pic.PixelFormat == PixelFormat.Format1bppIndexed)); } } #endif } } }
//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; } } //Bot for (int Yf = bitbmp[(frameCount / 8) * 4].Height - 1; Yf > 0; 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 != bitbmp[(frameCount / 8) * 4].Height - 1) { RegressB++; 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) && RegressB == -1 && Yf > 9) bot += 10; if (var == true && Xf == bitbmp[fram].Width - 1 && fram == (((frameCount / 8) * 5) - 1) && RegressB == -1 && Yf <= 9) bot++; if (var == true && Xf == bitbmp[fram].Width - 1 && fram == (((frameCount / 8) * 5) - 1) && RegressB != -1) { bot = bot - RegressB; breakOK = true; break; } } if (breakOK == true) break; } if (Yf > 9) Yf -= 9; // 1 of for + 9 if (breakOK == true) { breakOK = false; break; } } //Left for (int Xf = 0; Xf < bitbmp[(frameCount / 8) * 4].Width; Xf++) { for (int fram = (frameCount / 8) * 4; fram < (frameCount / 8) * 5; fram++) { bitbmp[fram].SelectActiveFrame(dimension, fram); for (int Yf = 0; Yf < bitbmp[(frameCount / 8) * 4].Height; Yf++) { 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 (Xf != 0) { RegressL++; Xf -= 1; Yf = -1; fram = (frameCount / 8) * 4; } else { breakOK = true; break; } } if (var == true && Yf == bitbmp[fram].Height - 1 && fram == (((frameCount / 8) * 5) - 1) && RegressL == -1 && Xf < bitbmp[0].Width - 9) left += 10; if (var == true && Yf == bitbmp[fram].Height - 1 && fram == (((frameCount / 8) * 5) - 1) && RegressL == -1 && Xf >= bitbmp[0].Width - 9) left++; if (var == true && Yf == bitbmp[fram].Height - 1 && fram == (((frameCount / 8) * 5) - 1) && RegressL != -1) { left = left - RegressL; breakOK = true; break; } } if (breakOK == true) break; } if (Xf < bitbmp[(frameCount / 8) * 4].Width - 9) Xf += 9; // 1 of for + 9 if (breakOK == true) { breakOK = false; break; } } //Right for (int Xf = bitbmp[(frameCount / 8) * 4].Width - 1; Xf > 0; Xf--) { for (int fram = (frameCount / 8) * 4; fram < (frameCount / 8) * 5; fram++) { bitbmp[fram].SelectActiveFrame(dimension, fram); for (int Yf = 0; Yf < bitbmp[(frameCount / 8) * 4].Height; Yf++) { 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 (Xf != bitbmp[(frameCount / 8) * 4].Width - 1) { RegressR++; Xf += 1; Yf = -1; fram = (frameCount / 8) * 4; } else { breakOK = true; break; } } if (var == true && Yf == bitbmp[fram].Height - 1 && fram == (((frameCount / 8) * 5) - 1) && RegressR == -1 && Xf > 9) right += 10; if (var == true && Yf == bitbmp[fram].Height - 1 && fram == (((frameCount / 8) * 5) - 1) && RegressR == -1 && Xf <= 9) right++; if (var == true && Yf == bitbmp[fram].Height - 1 && fram == (((frameCount / 8) * 5) - 1) && RegressR != -1) { right = right - RegressR; breakOK = true; break; } } if (breakOK == true) break; } if (Xf > 9) Xf -= 9; // 1 of for + 9 if (breakOK == true) { breakOK = false; break; } } for (int index = (frameCount / 8) * 4; index < (frameCount / 8) * 5; index++) { Rectangle rect = new Rectangle(left, top, (bitbmp[index].Width - left - right), (bitbmp[index].Height - top - bot)); bitbmp[index].SelectActiveFrame(dimension, index); Bitmap myImage2 = bitbmp[index].Clone(rect, System.Drawing.Imaging.PixelFormat.Format16bppArgb1555); bitbmp[index] = myImage2; } //Reseta cordenadas top = 0; bot = 0; left = 0; right = 0; RegressT = -1; RegressB = -1; RegressL = -1; RegressR = -1; var = true; breakOK = false; // position 1 //Top for (int Yf = 0; Yf < bitbmp[0].Height; Yf++) { for (int fram = 0; fram < frameCount / 8; fram++) { bitbmp[fram].SelectActiveFrame(dimension, fram); for (int Xf = 0; Xf < bitbmp[0].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 = 0; } else { breakOK = true; break; } } if (var == true && Xf == bitbmp[fram].Width - 1 && fram == (((frameCount / 8)) - 1) && RegressT == -1 && Yf < bitbmp[0].Height - 9) top += 10; if (var == true && Xf == bitbmp[fram].Width - 1 && fram == (((frameCount / 8)) - 1) && RegressT == -1 && Yf >= bitbmp[0].Height - 9) top++; if (var == true && Xf == bitbmp[fram].Width - 1 && fram == (((frameCount / 8)) - 1) && RegressT != -1) { top = top - RegressT; breakOK = true; break; } } if (breakOK == true) break; } if (Yf < bitbmp[0].Height - 9) Yf += 9; // 1 of for + 9 if (breakOK == true) { breakOK = false; break; } } //Bot for (int Yf = bitbmp[0].Height - 1; Yf > 0; Yf--) { for (int fram = 0; fram < frameCount / 8; fram++) { bitbmp[fram].SelectActiveFrame(dimension, fram); for (int Xf = 0; Xf < bitbmp[0].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 != bitbmp[0].Height - 1) { RegressB++; Yf += 1; Xf = -1; fram = 0; } else { breakOK = true; break; } } if (var == true && Xf == bitbmp[fram].Width - 1 && fram == (((frameCount / 8)) - 1) && RegressB == -1 && Yf > 9) bot += 10; if (var == true && Xf == bitbmp[fram].Width - 1 && fram == (((frameCount / 8)) - 1) && RegressB == -1 && Yf <= 9) bot++; if (var == true && Xf == bitbmp[fram].Width - 1 && fram == (((frameCount / 8)) - 1) && RegressB != -1) { bot = bot - RegressB; breakOK = true; break; } } if (breakOK == true) break; } if (Yf > 9) Yf -= 9; // 1 of for + 9 if (breakOK == true) { breakOK = false; break; } } //Left for (int Xf = 0; Xf < bitbmp[0].Width; Xf++) { for (int fram = 0; fram < frameCount / 8; fram++) { bitbmp[fram].SelectActiveFrame(dimension, fram); for (int Yf = 0; Yf < bitbmp[0].Height; Yf++) { 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 (Xf != 0) { RegressL++; Xf -= 1; Yf = -1; fram = 0; } else { breakOK = true; break; } } if (var == true && Yf == bitbmp[fram].Height - 1 && fram == (((frameCount / 8)) - 1) && RegressL == -1 && Xf < bitbmp[0].Width - 9) left += 10; if (var == true && Yf == bitbmp[fram].Height - 1 && fram == (((frameCount / 8)) - 1) && RegressL == -1 && Xf >= bitbmp[0].Width - 9) left++; if (var == true && Yf == bitbmp[fram].Height - 1 && fram == (((frameCount / 8)) - 1) && RegressL != -1) { left = left - RegressL; breakOK = true; break; } } if (breakOK == true) break; } if (Xf < bitbmp[0].Width - 9) Xf += 9; // 1 of for + 9 if (breakOK == true) { breakOK = false; break; } } //Right for (int Xf = bitbmp[0].Width - 1; Xf > 0; Xf--) { for (int fram = 0; fram < frameCount / 8; fram++) { bitbmp[fram].SelectActiveFrame(dimension, fram); for (int Yf = 0; Yf < bitbmp[0].Height; Yf++) { 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 (Xf != bitbmp[0].Width - 1) { RegressR++; Xf += 1; Yf = -1; fram = 0; } else { breakOK = true; break; } } if (var == true && Yf == bitbmp[fram].Height - 1 && fram == (((frameCount / 8)) - 1) && RegressR == -1 && Xf > 9) right += 10; if (var == true && Yf == bitbmp[fram].Height - 1 && fram == (((frameCount / 8)) - 1) && RegressR == -1 && Xf <= 9) right++; if (var == true && Yf == bitbmp[fram].Height - 1 && fram == (((frameCount / 8)) - 1) && RegressR != -1) { right = right - RegressR; breakOK = true; break; } } if (breakOK == true) break; } if (Xf > 9) Xf -= 9; // 1 of for + 9 if (breakOK == true) { breakOK = false; break; } } for (int index = 0; index < frameCount / 8; index++) { Rectangle rect = new Rectangle(left, top, (bitbmp[index].Width - left - right), (bitbmp[index].Height - top - bot)); bitbmp[index].SelectActiveFrame(dimension, index); Bitmap myImage2 = bitbmp[index].Clone(rect, System.Drawing.Imaging.PixelFormat.Format16bppArgb1555); bitbmp[index] = myImage2; } //Reseta cordenadas top = 0; bot = 0; left = 0; right = 0; RegressT = -1; RegressB = -1; RegressL = -1; RegressR = -1; var = true; breakOK = false; // position 2 //Top for (int Yf = 0; Yf < bitbmp[((frameCount / 8) * 5)].Height; Yf++) { for (int fram = ((frameCount / 8) * 5); fram < (frameCount / 8) * 6; fram++) { bitbmp[fram].SelectActiveFrame(dimension, fram); for (int Xf = 0; Xf < bitbmp[((frameCount / 8) * 5)].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) * 5); } else { breakOK = true; break; } } if (var == true && Xf == bitbmp[fram].Width - 1 && fram == (((frameCount / 8) * 6) - 1) && RegressT == -1 && Yf < bitbmp[0].Height - 9) top += 10; if (var == true && Xf == bitbmp[fram].Width - 1 && fram == (((frameCount / 8) * 6) - 1) && RegressT == -1 && Yf >= bitbmp[0].Height - 9) top++; if (var == true && Xf == bitbmp[fram].Width - 1 && fram == (((frameCount / 8) * 6) - 1) && RegressT != -1) { top = top - RegressT; breakOK = true; break; } } if (breakOK == true) break; } if (Yf < bitbmp[((frameCount / 8) * 5)].Height - 9) Yf += 9; // 1 of for + 9 if (breakOK == true) { breakOK = false; break; } } //Bot for (int Yf = bitbmp[((frameCount / 8) * 5)].Height - 1; Yf > 0; Yf--) { for (int fram = ((frameCount / 8) * 5); fram < (frameCount / 8) * 6; fram++) { bitbmp[fram].SelectActiveFrame(dimension, fram); for (int Xf = 0; Xf < bitbmp[((frameCount / 8) * 5)].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 != bitbmp[((frameCount / 8) * 5)].Height - 1) { RegressB++; Yf += 1; Xf = -1; fram = ((frameCount / 8) * 5); } else { breakOK = true; break; } } if (var == true && Xf == bitbmp[fram].Width - 1 && fram == (((frameCount / 8) * 6) - 1) && RegressB == -1 && Yf > 9) bot += 10; if (var == true && Xf == bitbmp[fram].Width - 1 && fram == (((frameCount / 8) * 6) - 1) && RegressB == -1 && Yf <= 9) bot++; if (var == true && Xf == bitbmp[fram].Width - 1 && fram == (((frameCount / 8) * 6) - 1) && RegressB != -1) { bot = bot - RegressB; breakOK = true; break; } } if (breakOK == true) break; } if (Yf > 9) Yf -= 9; // 1 of for + 9 if (breakOK == true) { breakOK = false; break; } } //Left for (int Xf = 0; Xf < bitbmp[((frameCount / 8) * 5)].Width; Xf++) { for (int fram = ((frameCount / 8) * 5); fram < (frameCount / 8) * 6; fram++) { bitbmp[fram].SelectActiveFrame(dimension, fram); for (int Yf = 0; Yf < bitbmp[((frameCount / 8) * 5)].Height; Yf++) { 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 (Xf != 0) { RegressL++; Xf -= 1; Yf = -1; fram = ((frameCount / 8) * 5); } else { breakOK = true; break; } } if (var == true && Yf == bitbmp[fram].Height - 1 && fram == (((frameCount / 8) * 6) - 1) && RegressL == -1 && Xf < bitbmp[0].Width - 9) left += 10; if (var == true && Yf == bitbmp[fram].Height - 1 && fram == (((frameCount / 8) * 6) - 1) && RegressL == -1 && Xf >= bitbmp[0].Width - 9) left++; if (var == true && Yf == bitbmp[fram].Height - 1 && fram == (((frameCount / 8) * 6) - 1) && RegressL != -1) { left = left - RegressL; breakOK = true; break; } } if (breakOK == true) break; } if (Xf < bitbmp[((frameCount / 8) * 5)].Width - 9) Xf += 9; // 1 of for + 9 if (breakOK == true) { breakOK = false; break; } } //Right for (int Xf = bitbmp[((frameCount / 8) * 5)].Width - 1; Xf > 0; Xf--) { for (int fram = ((frameCount / 8) * 5); fram < (frameCount / 8) * 6; fram++) { bitbmp[fram].SelectActiveFrame(dimension, fram); for (int Yf = 0; Yf < bitbmp[((frameCount / 8) * 5)].Height; Yf++) { 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 (Xf != bitbmp[((frameCount / 8) * 5)].Width - 1) { RegressR++; Xf += 1; Yf = -1; fram = ((frameCount / 8) * 5); } else { breakOK = true; break; } } if (var == true && Yf == bitbmp[fram].Height - 1 && fram == (((frameCount / 8) * 6) - 1) && RegressR == -1 && Xf > 9) right += 10; if (var == true && Yf == bitbmp[fram].Height - 1 && fram == (((frameCount / 8) * 6) - 1) && RegressR == -1 && Xf <= 9) right++; if (var == true && Yf == bitbmp[fram].Height - 1 && fram == (((frameCount / 8) * 6) - 1) && RegressR != -1) { right = right - RegressR; breakOK = true; break; } } if (breakOK == true) break; } if (Xf > 9) Xf -= 9; // 1 of for + 9 if (breakOK == true) { breakOK = false; break; } } for (int index = ((frameCount / 8) * 5); index < (frameCount / 8) * 6; index++) { Rectangle rect = new Rectangle(left, top, (bitbmp[index].Width - left - right), (bitbmp[index].Height - top - bot)); bitbmp[index].SelectActiveFrame(dimension, index); Bitmap myImage2 = bitbmp[index].Clone(rect, System.Drawing.Imaging.PixelFormat.Format16bppArgb1555); bitbmp[index] = myImage2; } //Reseta cordenadas top = 0; bot = 0; left = 0; right = 0; RegressT = -1; RegressB = -1; RegressL = -1; RegressR = -1; var = true; breakOK = false; // position 3 //Top for (int Yf = 0; Yf < bitbmp[((frameCount / 8) * 1)].Height; Yf++) { for (int fram = ((frameCount / 8) * 1); fram < (frameCount / 8) * 2; fram++) { bitbmp[fram].SelectActiveFrame(dimension, fram); for (int Xf = 0; Xf < bitbmp[((frameCount / 8) * 1)].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) * 1); } else { breakOK = true; break; } } if (var == true && Xf == bitbmp[fram].Width - 1 && fram == (((frameCount / 8) * 2) - 1) && RegressT == -1 && Yf < bitbmp[0].Height - 9) top += 10; if (var == true && Xf == bitbmp[fram].Width - 1 && fram == (((frameCount / 8) * 2) - 1) && RegressT == -1 && Yf >= bitbmp[0].Height - 9) top++; if (var == true && Xf == bitbmp[fram].Width - 1 && fram == (((frameCount / 8) * 2) - 1) && RegressT != -1) { top = top - RegressT; breakOK = true; break; } } if (breakOK == true) break; } if (Yf < bitbmp[((frameCount / 8) * 1)].Height - 9) Yf += 9; // 1 of for + 9 if (breakOK == true) { breakOK = false; break; } } //Bot for (int Yf = bitbmp[((frameCount / 8) * 1)].Height - 1; Yf > 0; Yf--) { for (int fram = ((frameCount / 8) * 1); fram < (frameCount / 8) * 2; fram++) { bitbmp[fram].SelectActiveFrame(dimension, fram); for (int Xf = 0; Xf < bitbmp[((frameCount / 8) * 1)].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 != bitbmp[((frameCount / 8) * 1)].Height - 1) { RegressB++; Yf += 1; Xf = -1; fram = ((frameCount / 8) * 1); } else { breakOK = true; break; } } if (var == true && Xf == bitbmp[fram].Width - 1 && fram == (((frameCount / 8) * 2) - 1) && RegressB == -1 && Yf > 9) bot += 10; if (var == true && Xf == bitbmp[fram].Width - 1 && fram == (((frameCount / 8) * 2) - 1) && RegressB == -1 && Yf <= 9) bot++; if (var == true && Xf == bitbmp[fram].Width - 1 && fram == (((frameCount / 8) * 2) - 1) && RegressB != -1) { bot = bot - RegressB; breakOK = true; break; } } if (breakOK == true) break; } if (Yf > 9) Yf -= 9; // 1 of for + 9 if (breakOK == true) { breakOK = false; break; } } //Left for (int Xf = 0; Xf < bitbmp[((frameCount / 8) * 1)].Width; Xf++) { for (int fram = ((frameCount / 8) * 1); fram < (frameCount / 8) * 2; fram++) { bitbmp[fram].SelectActiveFrame(dimension, fram); for (int Yf = 0; Yf < bitbmp[((frameCount / 8) * 1)].Height; Yf++) { 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 (Xf != 0) { RegressL++; Xf -= 1; Yf = -1; fram = ((frameCount / 8) * 1); } else { breakOK = true; break; } } if (var == true && Yf == bitbmp[fram].Height - 1 && fram == (((frameCount / 8) * 2) - 1) && RegressL == -1 && Xf < bitbmp[0].Width - 9) left += 10; if (var == true && Yf == bitbmp[fram].Height - 1 && fram == (((frameCount / 8) * 2) - 1) && RegressL == -1 && Xf >= bitbmp[0].Width - 9) left++; if (var == true && Yf == bitbmp[fram].Height - 1 && fram == (((frameCount / 8) * 2) - 1) && RegressL != -1) { left = left - RegressL; breakOK = true; break; } } if (breakOK == true) break; } if (Xf < bitbmp[((frameCount / 8) * 1)].Width - 9) Xf += 9; // 1 of for + 9 if (breakOK == true) { breakOK = false; break; } } //Right for (int Xf = bitbmp[((frameCount / 8) * 1)].Width - 1; Xf > 0; Xf--) { for (int fram = ((frameCount / 8) * 1); fram < (frameCount / 8) * 2; fram++) { bitbmp[fram].SelectActiveFrame(dimension, fram); for (int Yf = 0; Yf < bitbmp[((frameCount / 8) * 1)].Height; Yf++) { 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 (Xf != bitbmp[((frameCount / 8) * 1)].Width - 1) { RegressR++; Xf += 1; Yf = -1; fram = ((frameCount / 8) * 1); } else { breakOK = true; break; } } if (var == true && Yf == bitbmp[fram].Height - 1 && fram == (((frameCount / 8) * 2) - 1) && RegressR == -1 && Xf > 9) right += 10; if (var == true && Yf == bitbmp[fram].Height - 1 && fram == (((frameCount / 8) * 2) - 1) && RegressR == -1 && Xf <= 9) right++; if (var == true && Yf == bitbmp[fram].Height - 1 && fram == (((frameCount / 8) * 2) - 1) && RegressR != -1) { right = right - RegressR; breakOK = true; break; } } if (breakOK == true) break; } if (Xf > 9) Xf -= 9; // 1 of for + 9 if (breakOK == true) { breakOK = false; break; } } for (int index = ((frameCount / 8) * 1); index < (frameCount / 8) * 2; index++) { Rectangle rect = new Rectangle(left, top, (bitbmp[index].Width - left - right), (bitbmp[index].Height - top - bot)); bitbmp[index].SelectActiveFrame(dimension, index); Bitmap myImage2 = bitbmp[index].Clone(rect, System.Drawing.Imaging.PixelFormat.Format16bppArgb1555); bitbmp[index] = myImage2; } //Reseta cordenadas top = 0; bot = 0; left = 0; right = 0; RegressT = -1; RegressB = -1; RegressL = -1; RegressR = -1; var = true; breakOK = false; // position 4 //Top for (int Yf = 0; Yf < bitbmp[((frameCount / 8) * 6)].Height; Yf++) { for (int fram = ((frameCount / 8) * 6); fram < (frameCount / 8) * 7; fram++) { bitbmp[fram].SelectActiveFrame(dimension, fram); for (int Xf = 0; Xf < bitbmp[((frameCount / 8) * 6)].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) * 6); } else { breakOK = true; break; } } if (var == true && Xf == bitbmp[fram].Width - 1 && fram == (((frameCount / 8) * 7) - 1) && RegressT == -1 && Yf < bitbmp[0].Height - 9) top += 10; if (var == true && Xf == bitbmp[fram].Width - 1 && fram == (((frameCount / 8) * 7) - 1) && RegressT == -1 && Yf >= bitbmp[0].Height - 9) top++; if (var == true && Xf == bitbmp[fram].Width - 1 && fram == (((frameCount / 8) * 7) - 1) && RegressT != -1) { top = top - RegressT; breakOK = true; break; } } if (breakOK == true) break; } if (Yf < bitbmp[((frameCount / 8) * 6)].Height - 9) Yf += 9; // 1 of for + 9 if (breakOK == true) { breakOK = false; break; } } //Bot for (int Yf = bitbmp[((frameCount / 8) * 6)].Height - 1; Yf > 0; Yf--) { for (int fram = ((frameCount / 8) * 6); fram < (frameCount / 8) * 7; fram++) { bitbmp[fram].SelectActiveFrame(dimension, fram); for (int Xf = 0; Xf < bitbmp[((frameCount / 8) * 6)].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 != bitbmp[((frameCount / 8) * 6)].Height - 1) { RegressB++; Yf += 1; Xf = -1; fram = ((frameCount / 8) * 6); } else { breakOK = true; break; } } if (var == true && Xf == bitbmp[fram].Width - 1 && fram == (((frameCount / 8) * 7) - 1) && RegressB == -1 && Yf > 9) bot += 10; if (var == true && Xf == bitbmp[fram].Width - 1 && fram == (((frameCount / 8) * 7) - 1) && RegressB == -1 && Yf <= 9) bot++; if (var == true && Xf == bitbmp[fram].Width - 1 && fram == (((frameCount / 8) * 7) - 1) && RegressB != -1) { bot = bot - RegressB; breakOK = true; break; } } if (breakOK == true) break; } if (Yf > 9) Yf -= 9; // 1 of for + 9 if (breakOK == true) { breakOK = false; break; } } //Left for (int Xf = 0; Xf < bitbmp[((frameCount / 8) * 6)].Width; Xf++) { for (int fram = ((frameCount / 8) * 6); fram < (frameCount / 8) * 7; fram++) { bitbmp[fram].SelectActiveFrame(dimension, fram); for (int Yf = 0; Yf < bitbmp[((frameCount / 8) * 6)].Height; Yf++) { 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 (Xf != 0) { RegressL++; Xf -= 1; Yf = -1; fram = ((frameCount / 8) * 6); } else { breakOK = true; break; } } if (var == true && Yf == bitbmp[fram].Height - 1 && fram == (((frameCount / 8) * 7) - 1) && RegressL == -1 && Xf < bitbmp[0].Width - 9) left += 10; if (var == true && Yf == bitbmp[fram].Height - 1 && fram == (((frameCount / 8) * 7) - 1) && RegressL == -1 && Xf >= bitbmp[0].Width - 9) left++; if (var == true && Yf == bitbmp[fram].Height - 1 && fram == (((frameCount / 8) * 7) - 1) && RegressL != -1) { left = left - RegressL; breakOK = true; break; } } if (breakOK == true) break; } if (Xf < bitbmp[((frameCount / 8) * 6)].Width - 9) Xf += 9; // 1 of for + 9 if (breakOK == true) { breakOK = false; break; } } //Right for (int Xf = bitbmp[((frameCount / 8) * 6)].Width - 1; Xf > 0; Xf--) { for (int fram = ((frameCount / 8) * 6); fram < (frameCount / 8) * 7; fram++) { bitbmp[fram].SelectActiveFrame(dimension, fram); for (int Yf = 0; Yf < bitbmp[((frameCount / 8) * 6)].Height; Yf++) { 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 (Xf != bitbmp[((frameCount / 8) * 6)].Width - 1) { RegressR++; Xf += 1; Yf = -1; fram = ((frameCount / 8) * 6); } else { breakOK = true; break; } } if (var == true && Yf == bitbmp[fram].Height - 1 && fram == (((frameCount / 8) * 7) - 1) && RegressR == -1 && Xf > 9) right += 10; if (var == true && Yf == bitbmp[fram].Height - 1 && fram == (((frameCount / 8) * 7) - 1) && RegressR == -1 && Xf <= 9) right++; if (var == true && Yf == bitbmp[fram].Height - 1 && fram == (((frameCount / 8) * 7) - 1) && RegressR != -1) { right = right - RegressR; breakOK = true; break; } } if (breakOK == true) break; } if (Xf > 9) Xf -= 9; // 1 of for + 9 if (breakOK == true) { breakOK = false; break; } } for (int index = ((frameCount / 8) * 6); index < (frameCount / 8) * 7; index++) { Rectangle rect = new Rectangle(left, top, (bitbmp[index].Width - left - right), (bitbmp[index].Height - top - bot)); bitbmp[index].SelectActiveFrame(dimension, index); Bitmap myImage2 = bitbmp[index].Clone(rect, System.Drawing.Imaging.PixelFormat.Format16bppArgb1555); bitbmp[index] = myImage2; } //End of Canvas //posicao 0 for (int index = ((frameCount / 8) * 4); index < (frameCount / 8) * 5; index++) { bitbmp[index].SelectActiveFrame(dimension, index); bitbmp[index] = Utils.ConvertBmpAnimCV5(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(); } if (index == ((frameCount / 8) * 5) - 1) trackBar1.Value++; } //posicao 1 edit = Ultima.AnimationEdit.GetAnimation(FileType, CurrBody, CurrAction, CurrDir); bmp.SelectActiveFrame(dimension, 0); edit.GetGifPalette(bmp); for (int index = 0; index < (frameCount / 8); index++) { bitbmp[index].SelectActiveFrame(dimension, index); bitbmp[index] = Utils.ConvertBmpAnimCV5(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(); } if (index == (frameCount / 8) - 1) trackBar1.Value++; } //posicao 2 edit = Ultima.AnimationEdit.GetAnimation(FileType, CurrBody, CurrAction, CurrDir); bmp.SelectActiveFrame(dimension, 0); edit.GetGifPalette(bmp); for (int index = ((frameCount / 8) * 5); index < (frameCount / 8) * 6; index++) { bitbmp[index].SelectActiveFrame(dimension, index); bitbmp[index] = Utils.ConvertBmpAnimCV5(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(); } if (index == ((frameCount / 8) * 6) - 1) trackBar1.Value++; } //posicao 3 edit = Ultima.AnimationEdit.GetAnimation(FileType, CurrBody, CurrAction, CurrDir); bmp.SelectActiveFrame(dimension, 0); edit.GetGifPalette(bmp); for (int index = ((frameCount / 8) * 1); index < (frameCount / 8) * 2; index++) { bitbmp[index].SelectActiveFrame(dimension, index); bitbmp[index] = Utils.ConvertBmpAnimCV5(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(); } if (index == ((frameCount / 8) * 2) - 1) trackBar1.Value++; } //posicao 4 edit = Ultima.AnimationEdit.GetAnimation(FileType, CurrBody, CurrAction, CurrDir); bmp.SelectActiveFrame(dimension, 0); edit.GetGifPalette(bmp); for (int index = ((frameCount / 8) * 6); index < (frameCount / 8) * 7; index++) { bitbmp[index].SelectActiveFrame(dimension, index); bitbmp[index] = Utils.ConvertBmpAnimCV5(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; } } trackBar1.Enabled = true; } } } //Refresh List after Canvas reduction CurrDir = trackBar1.Value; AfterSelectTreeView(null, null); } catch (System.NullReferenceException) { trackBar1.Enabled = true; } }
IEnumerable<Bitmap> CreateFrames(Bitmap original, bool opacify, bool transparent, bool smooth, SizingCallback resolve) { EnsureUndisposed(); FramePlacement placement = FramePlacement.TopLeft; FrameSizing sizing = FrameSizing.OriginalSize; if (frames.Count == 0) sizing = FrameSizing.NewSize; else if (original.Width != width || original.Height != height) if (resolve != null) resolve(out placement, out sizing); bool newsize = false; if (sizing == FrameSizing.NewSize) { width = original.Width; height = original.Height; newsize = true; } else if (sizing == FrameSizing.MaximumSize) { if (original.Width*original.Height > width*height) { width = original.Width; height = original.Height; newsize = true; } } if (newsize) { for (int i = 0; i < frames.Count; i++) { Bitmap b = frames[i]; frames[i] = Resize(b, width, height, placement); b.Dispose(); } } FrameDimension fd = new FrameDimension(original.FrameDimensionsList[0]); int c = original.GetFrameCount(fd); for (int f = 0; f < c; f++) { original.SelectActiveFrame(fd, f); Bitmap temp = Resize(original, original.Width, original.Height, FramePlacement.TopLeft); // Don't modify the bitmap, just make a new one from the frame with format32bppargb; BitmapData bd = temp.LockBits(new Rectangle(0, 0, temp.Width, temp.Height), ImageLockMode.ReadWrite, PixelFormat.Format32bppArgb); if (opacify) { for (int i = 0; i < bd.Height; i++) for (int j = 0; j < bd.Width; j++) { int ofs = bd.Stride * i + j * 4; System.Runtime.InteropServices.Marshal.WriteInt32(bd.Scan0, ofs, unchecked(System.Runtime.InteropServices.Marshal.ReadInt32(bd.Scan0, ofs) & (int)0xFF000000)); } } if (transparent) { int col = System.Runtime.InteropServices.Marshal.ReadInt32(bd.Scan0, bd.Stride * (bd.Height - 1)) & 0xFFFFFF; for (int i = 0; i < bd.Height; i++) for (int j = 0; j < bd.Width; j++) { int ofs = bd.Stride * i + j * 4; if ((System.Runtime.InteropServices.Marshal.ReadInt32(bd.Scan0, ofs) & 0xFFFFFF) == col) System.Runtime.InteropServices.Marshal.WriteInt32(bd.Scan0, ofs, col); } } temp.UnlockBits(bd); Bitmap bmp = temp; if (original.Width != width || original.Height != height) { bmp = Resize(temp, width, height, placement); temp.Dispose(); } if (smooth) { temp = bmp; bmp = SmoothEdges(temp); temp.Dispose(); } yield return bmp; // me likes ;D } }
// TODO: move to separate file public static void WriteImage(Stream inStream, Stream outStream, int panelWidth, int panelHeight, RenderModes mode) { Bitmap bmpSrc = null, bmpTrg = null; try { inStream.Position = 0; bmpSrc = new Bitmap(inStream); // convert TIFF to BMP, use only the first page FrameDimension fd = new FrameDimension(bmpSrc.FrameDimensionsList[0]); bmpSrc.SelectActiveFrame(fd, 0); // crop/fit/stretch int imageHeight = bmpSrc.Height, imageWidth = bmpSrc.Width, targetWidth, targetHeight; if (panelWidth <= 0) panelWidth = imageWidth; if (panelHeight <= 0) panelHeight = imageHeight; if (panelWidth != imageWidth || panelHeight != imageHeight) { switch (mode) { case RenderModes.RenderMode_Stretch: if (panelWidth <= 120 && panelHeight <= 120) bmpTrg = new Bitmap(bmpSrc.GetThumbnailImage(panelWidth, panelHeight, () => false, IntPtr.Zero)); else bmpTrg = new Bitmap(bmpSrc, new Size(panelWidth, panelHeight)); break; case RenderModes.RenderMode_Fit: targetWidth = imageWidth; targetHeight = imageHeight; float scale = 1F; // a. panel is greater than image: grow if (panelHeight > imageHeight && panelWidth > imageWidth) { scale = Math.Min((float)panelWidth / imageWidth, (float)panelHeight / imageHeight); targetHeight = Math.Min((int)((float)imageHeight * scale), panelHeight); targetWidth = Math.Min((int)((float)imageWidth * scale), panelWidth); } // b. image is greater than panel: shrink else { scale = Math.Max((float)imageWidth / panelWidth, (float)imageHeight / panelHeight); targetWidth = Math.Min((int)((float)imageWidth / scale), panelWidth); targetHeight = Math.Min((int)((float)imageHeight / scale), panelHeight); } if (targetWidth <= 120 && targetHeight <= 120) bmpTrg = new Bitmap(bmpSrc.GetThumbnailImage(targetWidth, targetHeight, () => false, IntPtr.Zero)); else bmpTrg = new Bitmap(bmpSrc, new Size(targetWidth, targetHeight)); break; case RenderModes.RenderMode_Crop: targetWidth = Math.Min(panelWidth, imageWidth); targetHeight = Math.Min(panelHeight, imageHeight); bmpTrg = bmpSrc.Clone( new Rectangle(0, 0, targetWidth, targetHeight), bmpSrc.PixelFormat ); break; } bmpTrg.Save(outStream, ImageFormat.Png); } else bmpSrc.Save(outStream, ImageFormat.Png); outStream.Seek(0, SeekOrigin.Begin); } finally { if (bmpTrg != null) bmpTrg.Dispose(); if (bmpSrc != null) bmpSrc.Dispose(); GC.Collect(); } }
public static void WriteImage(Stream inStream, Stream outStream, int boundWidth, int boundHeight, RenderModes mode) { Bitmap bmpSrc = null, bmpTrg = null; try { bmpSrc = new Bitmap(inStream); // convert TIFF to BMP, use only the first page FrameDimension fd = new FrameDimension(bmpSrc.FrameDimensionsList[0]); bmpSrc.SelectActiveFrame(fd, 0); // crop/fit/stretch int imageHeight = bmpSrc.Height, imageWidth = bmpSrc.Width, targetWidth, targetHeight; if (boundWidth < 0) boundWidth = imageWidth; if (boundHeight < 0) boundHeight = imageHeight; if (boundWidth != imageWidth || boundHeight != imageHeight) { switch (mode) { case RenderModes.RenderMode_Stretch: bmpTrg = new Bitmap(bmpSrc, new Size(boundWidth, boundHeight)); break; case RenderModes.RenderMode_Fit: targetWidth = imageWidth; targetHeight = imageHeight; float scale = 1F; // a. panel is greater than image: grow if (boundHeight > imageHeight && boundWidth > imageWidth) { scale = Math.Min((float)boundWidth / imageWidth, (float)boundHeight / imageHeight); targetHeight = Math.Min((int)((float)imageHeight * scale), boundHeight); targetWidth = Math.Min((int)((float)imageWidth * scale), boundWidth); } // b. image is greater than panel: shrink else { scale = Math.Max((float)imageWidth / boundWidth, (float)imageHeight / boundHeight); targetWidth = Math.Min((int)((float)imageWidth / scale), boundWidth); targetHeight = Math.Min((int)((float)imageHeight / scale), boundHeight); } bmpTrg = new Bitmap(bmpSrc, new Size(targetWidth, targetHeight)); break; case RenderModes.RenderMode_Crop: targetWidth = Math.Min(boundWidth, imageWidth); targetHeight = Math.Min(boundHeight, imageHeight); bmpTrg = bmpSrc.Clone( new Rectangle(0, 0, targetWidth, targetHeight), bmpSrc.PixelFormat ); break; } bmpTrg.Save(outStream, ImageFormat.Png); } else bmpSrc.Save(outStream, ImageFormat.Png); } finally { if (bmpTrg != null) bmpTrg.Dispose(); if (bmpSrc != null) bmpSrc.Dispose(); GC.Collect(); } }
//Adds an Image to Image <rDoc> for editing and storage (Stores in memory compared to old 'void addimage' disk method. // void addimage2(string filename) // { // // tempdi = Globals.tempdi; // fs = File.Open(filename, FileMode.Open, FileAccess.ReadWrite); // srcBmp = (Bitmap)Bitmap.FromStream(fs); // totalPages = Convert.ToInt32(srcBmp.GetFrameCount(FrameDimension.Page) - 1); // int i; // for (i = 0; i <= totalPages; i++) // { // srcBmp.SelectActiveFrame(FrameDimension.Page, i); // // //resized = new Bitmap(srcBmp, srcBmp.Width, srcBmp.Height); // double resizefactor = 2.3; // resized = new Bitmap(srcBmp, Convert.ToInt32(srcBmp.Width / resizefactor), Convert.ToInt32(srcBmp.Height / resizefactor)); // // if (srcBmp.Width > 1200) // // { // // resized = ResizeImage(resized, new Size(Convert.ToInt32(srcBmp.Width / 2.8), Convert.ToInt32(srcBmp.Height / 3.2)), true); // // } // int num = tempdi.GetFiles().Count(); // RedactDoc rDoc = new RedactDoc(); // rDoc.PageNum = string.Format("Page {0}", num + 1); // resized.Save(Application.StartupPath + "\\temp\\temp" + num + ".png", System.Drawing.Imaging.ImageFormat.Png); // // rDoc.PageNum = string.Format("Page {0}", num +1); // ms = new MemoryStream(); // resized.Save(ms, ImageFormat.Jpeg); // rDoc.ImageStream = ms; // rDoc.FileName = Application.StartupPath + "\\temp\\temp" + num + ".png"; // imgLst.Add(rDoc); // ms = null; // srcBmp.Dispose(); // srcBmp = null; // // resized.Dispose(); // } // fs.Dispose(); // ProgressBar1.PerformStep(); // // fs = null; // } void addimage(string filename) { fs = File.Open(filename, FileMode.Open, FileAccess.ReadWrite); srcBmp = (Bitmap)Bitmap.FromStream(fs); totalPages = Convert.ToInt32(srcBmp.GetFrameCount(FrameDimension.Page) - 1); int i; for (i = 0; i <= totalPages; i++) { srcBmp.SelectActiveFrame(FrameDimension.Page, i); //resized = new Bitmap(srcBmp, srcBmp.Width, srcBmp.Height); double resizefactor = 2.6; resized = new Bitmap(srcBmp, Convert.ToInt32(srcBmp.Width / resizefactor), Convert.ToInt32(srcBmp.Height / resizefactor)); // if (srcBmp.Width > 1200) // { // resized = ResizeImage(resized, new Size(Convert.ToInt32(srcBmp.Width / 2.8), Convert.ToInt32(srcBmp.Height / 3.2)), true); // } //int num = Globals.tempdi.GetFiles().Count(); int num = _Doc.Pages.Count(); resized.Save(Application.StartupPath + "\\temp\\temp" + num + ".png", System.Drawing.Imaging.ImageFormat.Png); ms = new MemoryStream(); resized.Save(ms, ImageFormat.Png); _Doc.Pages.Add(new Page(num +1, ms, Application.StartupPath + "\\temp\\temp" + (num -1) + ".png")); ms = null; srcBmp.Dispose(); srcBmp = null; resized.Dispose(); } fs.Dispose(); ProgressBar1.PerformStep(); fs = null; }
internal static bool Eat(String fp, out Bitmap pic2) { int cz = 0; if (String.Compare(Path.GetExtension(fp), ".pdf", true) == 0) { using (UtPDFio io = new UtPDFio(fp)) { cz = io.NumPages; } } else { using (Bitmap pic = new Bitmap(fp)) { cz = pic.GetFrameCount(FrameDimension.Page); } } using (PSelForm form = new PSelForm()) { form.numPage.Maximum = cz; if (form.ShowDialog() == DialogResult.OK) { int z = (int)form.numPage.Value; if (String.Compare(Path.GetExtension(fp), ".pdf", true) == 0) { using (UtPDFio io = new UtPDFio(fp)) { pic2 = (io.Rasterize(z - 1)); } } else { using (Bitmap pic = new Bitmap(fp)) { pic.SelectActiveFrame(FrameDimension.Page, z - 1); pic2 = ((Bitmap)pic.Clone()); } } return true; } else { pic2 = null; return false; } } }