Cimage: Create () create a PNG Image and set black pixels

Source: Internet
Author: User

The following example uses cimage: Create () to create a PNG Image m_savepng, and copy an existing cimage m_pngdraw to it, but leave a circle of pixels around it for editing. The edit entry is black.

The created PNG can be operated like a cimage object that comes in with normal load.

When the pixel is set to black, you must set its alpha channel to 255. Otherwise, the Black is transparent and cannot be displayed.

// Cimage * m_pngdraw

// Cimage m_savepng

If (! M_savepng.isnull ())
{
M_savepng.destroy ();
}

 

// When creating a PNG image, the default value 0 is used for the last create parameter instead of createalphachannel.
M_savepng.create (m_pngdraw-> getwidth () + 2, m_pngdraw-> getheight () + 2, 32, cimage: createalphachannel );

HDC = m_savepng.getdc (); // obtain the HDC of the target drawing Area

// Draw from behind the scenes () and set aside a circle of pixels
M_pngdraw-> draw (HDC, 1, 1 );

 

// The first column in the vertical direction
For (Int J = 1; j <m_vertpointlist.getcount (); j ++)
{

// M_vertpointlist the linked list stores some cpoint
Position posh0 = m_vertpointlist.findindex (J-1 );
Position posh1 = m_vertpointlist.findindex (j );
Cpoint pth0 = m_vertpointlist.getat (posh0 );
Cpoint pth1 = m_vertpointlist.getat (posh1 );

If (J % 2 = 0) // when the even number is reached, the strip is stretched between the original vertex and the original vertex.
{
For (int K = pth0.y; k <pth1.y; ++ K)
{
Unsigned char * puccolor = reinterpret_cast <unsigned char *> (m_savepng.getpixeladdress (0, k ));


Puccolor [0] = 0;
Puccolor [1] = 0;
Puccolor [2] = 0;
Puccolor [3] = 255; // alpha channel (transparency)

}
}
}

// The first Horizontal Column

............................

M_savepng.releasedc ();

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.