Multi-layer image synthesis

zhaozj2021-02-11  183

Multi-layer image synthesis

Keywords: image synthesis

Related Background: The synthesis of multi-layer images has a very broad application in actual development. First, the two devices DC are loaded into the foreground map and background diagram, and then another DC loads a binary image as a Mask. The background color of the device environment M_DCFore loaded into the foreground map is set as the background color of the foreground map, copied M_DCFORE to the device environment Maskdc loaded into the Mask map, get a new Mask diagram. The new MASK figure is the place where the background colors in the foreground map is turned on white, and the other turned black. In the process of copying the foreground graph to the Mask diagram, the system first converts the foreground map to a monochrome map. When the bitmap is converted between colors and monochrome, the system uses the background color of the device, the same place as white, and other conversion to black. The foreground of M_DCFore is white, the background color is black, M_DcFore and Maskdc do 'and' calculations, get new foreground maps. When doing 'and' operation, the system first converts a monochrome map into a color chart, and uses the foreground color of the color chart and the background colors as the conversion colors. Therefore, the background color of the new foreground map is transformed into black, and the other remains unchanged. The foreground color of the background chart is black, the background color is white, which is loaded into the background diagram of the equipment environment m_dcbk and maskdc 'and' calculation, get a new background illustration. The new background map is transformed into black, and the other remains unchanged. Put the new background diagram with the new foreground map 'or' calculation, the new map is given the background of the background, more integrated foreground, and reaches the ideal effect we want.

Environment: Visual C 6.0

Implementation process:

First create a single document or multi-document project named PIC.

Introducing two BMP images we want to syntheses in Resources (a background diagram, another as a foreground map), named IDB_BK, IDB_FORE, respectively.

The member variables for the two cbitmap types are built to the CPICView class, named m_BMPBK, M_BmpFore, respectively. Two BMP images were loaded in the initialization function. Add the following code in the cpicview :: onInitialupdate () function:

m_BMPBK.LOADBITMAP (IDB_BK); // Use the background map to

m_BmpFore.LoadBitmap (idb_fore); // load foreground map

Newly built two CDC types of members variables in the CPICView class, named m_dcbk, m_dcfore, respectively. Add the following code in the initialization function:

CClientDC DC (this); // Get the current customer area equipment environment

M_DCBK. CreateCompaTibleDC (& DC); // Create a device compatible with the current device

M_dcFore. CreateCompatibleDC (& DC);

CBITMAP * POLDBK = m_dcbk.selectObject (m_bmpbk); // Select the background diagram

CBITMAP * POLDFORE = m_dcfore.selectObject (m_bmpfore);

Add the following code in the OnDraw (CDC * PDC) function of the CPICVIEW class:

CRECT RECT;

GetClientRect (& Rect); // Get rectangles from customer area

CDC Maskdc; // Create a device environment MASKDC

CBitmap Maskbitmap;

Maskdc.createCompaTibleDC (PDC); // Create a device compatible with the current device

Maskbitmap.createbitmap (Rect.width (), Rect.Height (), 1, 1, null; // Create a monochrome map

CBITMAP * POLDMASKDCBITMAP = Maskdc.selectObject (& Maskbitmap); // Select Monochrome Map M_DCFore.setBkcolor (RGB ()); // Set the background color of the foreground color

Maskdc.bitblt (0, 0, Rect.width (), Rect.Height (), & M_BmpFore, 0, 0, Srccopy;

// copy the foreground to Maskdc, at which time MASKDC is shown below:

m_dcfore.setbkcolor (RGB (0, 0, 0));

m_dcfore.setTextColor (RGB (255, 255, 255);

M_dcfore.bitblt (0, 0, Rect.width (), Rect.Height (), & Maskdc, 0,0, srcand;

// Forecast and Mask do 'and'

M_BMPBK.SetBkcolor (RGB (255, 255, 255));

M_BMPBK.SETTEXTCOLOR (RGB (0,0,0));

M_BmpBk.bitblt (Rect.Wid, Rect.top, Rect.width (), Rect.Height (), & Maskdc, 0,0, srcand;

// Background diagram and Mask do 'and' calculations

M_BmpBk.bitblt (Rect.Wid, Rect.top, Rect.width (), Rect.Height (), & MEMDC, 0, 0, SrcPaint);

// Background diagram and foreground map do 'or' calculation

PDC-> Bitblt (0, 0, Rect.width (), Rect.Height (), & M_BMPBK, 0, 0, SRCCopy;

// Display the synthesized image

m_BMPBK.SelectObject (Poldbk);

m_BmpFore.SelectObject (PoldFore);

转载请注明原文地址:https://www.9cbs.com/read-5173.html

New Post(0)