graphics - Merge two images for "fade" transition with changing opacity? (C#/PNG) -


First of all, I would like to suggest that this question is not a duplicate. At least my opinion is :)

What I want to achieve is "Fade" is a series of frames for animation.

I select two PNG files (for example: they say they are the same size), for example:

  • I want to "simulate" them in the graphic editor to merge like layers. I put Pic1 at the top with the opacity 255, Pic2 with ambiguity 0 below, so firstly I only look at Pic1. Then I change my opacity, like:

    • Is there an easy way this?

      In a winforms app it can be done very easily Create user controls with some properties: < / P>

        get image from public image; Set; } Public Image ToImage {get; Set; } Private float opacity = 1;   

      Now open override

        protected override zero onpaint (paint event erg e) {if (semaj! = Null & amp; theme! = Null) {Color Matrix Matrix 1 = New Colors Matrix (); Matrix 1 Matrix 33 = opacity; ImageAttributes attributes1 = new image properties (); Features 1.SetColorMatrix (Matrix 1, ColorMatrixFlag.Default, ColorAdjustType.Bitmap); Color matrix matrix 2 = new color matrix (); Matrix 2 Metrics = 1 - Opacity; ImageAttributes Characteristics 2 = new image properties (); Attribute 2.SetColorMatrix (Matrix 2, Colormaticsflag.default, Color Atoicetype bitmap); E.Graphics.DrawImage (from image, new rectangle (0, 0, it.Withth, it .high), 0, 0, it .with it, .high, graphics unit.pixel, attribute 1); E.Graphics.DrawImage (ToImage, new rectangle (0, 0, this .Withth, this .high), 0, 0, with it, .high, graphics unit.pixel, attributes2); } Base.OnPaint (e); }   

      Now leave a timer in control, set it to be enabled with some time like 100ms to handle the tick event:

        private Zero timeric (object sender, eventAgps E) {if (opacity == 0) {this.timer.Stop (); Return; } This.opacity - = 0.01f; This.Invalidate (); }   

      However, it is one thing to be aware of it. It creates quite a flicker transition, which can be somewhat strange from this line in the control constructor:

        this.SetStyle (ControlStyles.OptimizedDoubleBuffer | ControlStyles.AllPaintingInWmPaint, true);   

      Update based on updates: You can convert it to a utility that takes 2 images and, using a lot of codes, each step in a new image Something like output:

        image capability of the public class [Personal image image1; Private image image2; Public Imaginity (Image Image 1, Image Image 2) {this.image1 = image1; This.image2 = image2; } Public Zero Save Transitions (int number steps, string outdoors) {var opacityChange = 1.0f / (float) number stages; (Use the image (new image). (Graphics = 1, I = 0, opacity, gt; opacity - = change opacity, i ++) {use (var image = new bitmap) (graphics1 = Graphics.frame image (image); Color matrix matrix 1 = new color matrix (); Matrix 1 Matrix 33 = opacity; ImageAttributes attributes1 = new image properties (); Features 1.SetColorMatrix (Matrix 1, ColorMatrixFlag.Default, ColorAdjustType.Bitmap); Color matrix matrix 2 = new color matrix (); Matrix 2 Metrics = 1 - Opacity; ImageAttributes Characteristics 2 = new image properties (); Attribute 2.SetColorMatrix (Matrix 2, Colormaticsflag.default, Color Atoicetype bitmap); G.DrawImage (image1, new rectangle (0, 0, image 1. with, image 1. height), 0, 0, image 1. with, image 1. high, graphics unit. Pixel, attributes 1); G.DrawImage (image2, new rectangle (0, 0, image2.Width, image2.Height), 0, 0, image2.Width, image2.Highlight, GraphicsUnit.Pixel, attributes2); Image. Save (Path. Cobain (Outdieer, "Image" + I + ". PNGG"), Image format.png); }}}   

      Usage:

        util = new ImageUtility ImageUtility (Image.FromFile (@ "C: \ path \ pic1.png"), image .FromFile (@ "C: \ path \ pic2.png")); Util.SaveTransitions (100, @ "C: \ Path \ Output"); // 100 saves images    

Comments

Popular posts from this blog

mysql - BLOB/TEXT column 'value' used in key specification without a key length -

c# - Using Vici cool Storage with monodroid -

c# - Confused over DLL entry points (entry point not found exception) -