Nana development: Image Mixing

Source: Internet
Author: User

Hybrid images are one of the most important ways to create powerful and fascinating user interfaces. This is a wizard that shows how to use the nana library to mix images and Display mixed results.

Before starting this wizard, we need to prepare two images for mixing.

Image01

Image02

These two images are in PNG format. before using them, we need to enable Nana library support for PNG.

Now let's encode:

# Include <Nana/GUI/wvl. HPP> # include <Nana/GUI/drawing. HPP> # include <Nana/GUI/Timer. HPP> class tsform: Public NANA: Gui: FORM {public: // the size of the image we prepared is 450*300, // The size of the window is the same as that of the image. tsform (): Nana: Gui: Form (NANA: Gui: API: make_center (450,300), fade_rate _ (0.1), delta _ (0.1) {// open the image file .image%.open(str(%image01.png%%%%%image2_.open(str(%image02.png "); timer _. make_tick (NANA: make_fun (* This, & tsform: _ m_blend); timer _. interval (10);} PRIVATE: void _ m_blend () {fade_rate _ + = delta _; If (fade_rate _> 1) {fade_rate _ = 1; delta _ =-0.01;} else if (fade_rate _ <0) {fade_rate _ = 0; Delta _ = 0.01;} // before mixing, copy the image to the graphics object. Nana: paint: Graphics graph1 (450,300); image1 _. paste (graph1, 0, 0); Nana: paint: Graphics graph2 (450,300); image2 _. paste (graph2, 0, 0); // execute a mixture and save the result to the graph2 object. graph1.blend (graph2, 0, 0, fade_rate _); // display the result and draw the content in graph2 to the window. NANA: Gui: Drawing drawing (* This); drawing. clear (); drawing. bitblt (0, 0,450,300, graph2, 0, 0); drawing. update ();} PRIVATE: Double fade_rate _; Double Delta _; Nana: Gui: timer _; Nana: paint: Image image1 _, image2 _;}; int main () {tsform FM; FM. show (); Nana: Gui: exec ();}

Run the program to check its actual running effect.

Initial Image

Mixed Images

Final Image

The program repeatedly performs image mixing.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.