void progress3_DoWork(object sender, System.ComponentModel.DoWorkEventArgs e) { var moduleSprite = currently_editing_animation.Owner as ModuleSprite; if (moduleSprite != null) { var ownerModule = moduleSprite.GetFirstModule <AnimationModule>(); float x = target * currently_editing_animation.Width; float y = 0; for (int i = 0; i < currently_editing_animation.Row; i++) { y += ownerModule.Animations[i].Height; } float width = currently_editing_animation.Width; float height = y + currently_editing_animation.Height; progress.ReportProgress(25, null, "Cloning sprite texture to bitmap..."); var result = new Bitmap(sprite.Texture.Bitmap); //Clone it using (var g = Graphics.FromImage(result)) { progress.ReportProgress(50, null, "Drawing onto bitmap.."); System.Drawing.Drawing2D.CompositingMode omode = g.CompositingMode; g.CompositingMode = System.Drawing.Drawing2D.CompositingMode.SourceCopy; using (var br = new System.Drawing.SolidBrush(System.Drawing.Color.FromArgb(0, 255, 255, 255))) { g.FillRectangle(br, x, y, width, height); } g.CompositingMode = omode; g.DrawImage(newImage, new RectangleF(x, y, width, height), new RectangleF(0f, 0f, width, height), GraphicsUnit.Pixel); } progress.ReportProgress(75, null, "Saving image.."); result.Save(image); progress.ReportProgress(100, null, "Reloading.."); Dispatcher.Invoke(new Action(delegate { Button_Click(null, null); Preview.IsSelected = true; Thread.Sleep(1500); TabEditor.IsSelected = true; })); result.Dispose(); } }
public static System.Drawing.Drawing2D.CompositingMode AsDrawingCompositingMode(this CompositingMode compositingMode) { System.Drawing.Drawing2D.CompositingMode drawingcompositingMode = System.Drawing.Drawing2D.CompositingMode.SourceOver; switch (compositingMode) { case CompositingMode.SourceCopy: drawingcompositingMode = System.Drawing.Drawing2D.CompositingMode.SourceCopy; break; case CompositingMode.SourceOver: drawingcompositingMode = System.Drawing.Drawing2D.CompositingMode.SourceOver; break; } return(drawingcompositingMode); }
public void ToggleCompositingMode() { _compositingMode = 1 - _compositingMode; }
void progress2_DoWork(object sender, System.ComponentModel.DoWorkEventArgs e) { var moduleSprite = currently_editing_animation.Owner as ModuleSprite; if (moduleSprite != null) { var ownerModule = moduleSprite.GetFirstModule <AnimationModule>(); float x = target * currently_editing_animation.Width; float y = 0; for (int i = 0; i < currently_editing_animation.Row; i++) { y += ownerModule.Animations[i].Height; } float width = currently_editing_animation.Width * (currently_editing_animation.Frames - 1); float height = y + currently_editing_animation.Height; var result = new Bitmap((int)width, (int)height); int totalWidth = Math.Max(sprite.Texture.Bitmap.Width, result.Width); var final = new Bitmap(totalWidth, sprite.Texture.Bitmap.Height); using (var g = Graphics.FromImage(result)) { //Clear frame System.Drawing.Drawing2D.CompositingMode omode = g.CompositingMode; g.CompositingMode = System.Drawing.Drawing2D.CompositingMode.SourceCopy; using (var br = new System.Drawing.SolidBrush(System.Drawing.Color.FromArgb(0, 255, 255, 255))) { g.FillRectangle(br, x, y, currently_editing_animation.Width, height); } g.CompositingMode = omode; //Move current frames over g.DrawImage(sprite.Texture.Bitmap, new RectangleF(x, 0, width, currently_editing_animation.Height), new RectangleF(x + currently_editing_animation.Width, y, width, height), GraphicsUnit.Pixel); progress.ReportProgress(25, null, "Moving frames over"); //Place all frames behind it if (x > 0) { g.DrawImage(sprite.Texture.Bitmap, new RectangleF(0f, 0, x, height), new RectangleF(0f, y, x, height), GraphicsUnit.Pixel); } } using (var finalG = Graphics.FromImage(final)) { //Draw entire texture to bitmap finalG.DrawImage(sprite.Texture.Bitmap, new RectangleF(0, 0, sprite.Texture.Bitmap.Width, sprite.Texture.Bitmap.Height), new RectangleF(0, 0, sprite.Texture.Bitmap.Width, sprite.Texture.Bitmap.Height), GraphicsUnit.Pixel); //Fill animation with nothing finalG.CompositingMode = System.Drawing.Drawing2D.CompositingMode.SourceCopy; using (var br = new System.Drawing.SolidBrush(System.Drawing.Color.FromArgb(0, 255, 255, 255))) { finalG.FillRectangle(br, x, y, width + currently_editing_animation.Width, height); } //Place new animation finalG.DrawImage(result, new RectangleF(0, y, width, height), new RectangleF(0, 0, result.Width, result.Height), GraphicsUnit.Pixel); } progress.ReportProgress(75, null, "Saving image.."); final.Save(this.image); progress.ReportProgress(100, null, "Reloading.."); Dispatcher.Invoke(new Action(delegate { RewriteJsonForFrames(-1); Button_Click(null, null); Preview.IsSelected = true; Thread.Sleep(1500); TabEditor.IsSelected = true; })); result.Dispose(); } }