Home > Software engineering >  Transparent PNG images with CImage class error
Transparent PNG images with CImage class error

Time:09-17

I want to put it on a button, but an error, is a question of image path?
My small white one, CImage class is not very good, hope to have a big show a

The code
Void CzdljDlg: : OnBnClickedButton2 ()
{
CImage img.
Cstrings ipath=_T (" C: \ Users MAC \ \ Desktop \ shortest path - copy \ ZDLJ/res/t1 1 -- 2. PNG ");
If (IsIconic ())
{
CPaintDC dc (this);//for drawing device context

The SendMessage (WM_ICONERASEBKGND, reinterpret_cast & lt; WPARAM> (dc) GetSafeHdc ()), 0);

//make the icon is centered within the workspace rectangular
Int cxIcon=GetSystemMetrics (SM_CXICON);
Int cyIcon=GetSystemMetrics (SM_CYICON);
CRect the rect.
GetClientRect (& amp; The rect);
Int x=(the rect. Width () - cxIcon + 1)/2;
Int y=(the rect. Height () - cyIcon + 1)/2;


//draw the icon
Dc. DrawIcon (x, y, m_hIcon);
}
The else
{
CPaintDC dc (this);
if(! Img. The IsNull ()) img. Destroy ();
Img. Load (ipath);//the load load, otherwise don't show
TransparentPNG (& amp; Img);//transparent processing function called
if(! Img img. IsNull ()). The Draw (dc m_hDC, 15, 14);

CDialogEx: : OnPaint ();
}

}


Void CzdljDlg: : TransparentPNG (CImage * PNG)
{
for(int i=0; I & lt; PNG - & gt; GetWidth (); I++)//traverse pixel processing
{
for(int j=0; J & lt; PNG - & gt; GetHeight (). J++)
{
Unsigned char * pucColor=reinterpret_cast & lt; Unsigned char * & gt; (PNG - & gt; GetPixelAddress (I, j));
PucColor [0]=pucColor pucColor [0] * [3]/255;
PucColor [1]=pucColor pucColor [1] * [3]/255;
PucColor [2]=pucColor * pucColor [2] [3]/255;
}
}
}


CodePudding user response:

A single '\' is the escape character, path with '\ \'
Cstrings ipath=_T (" C: \ \ Users \ \ MAC \ \ Desktop \ \ shortest path - copy \ \ ZDLJ \ \ res \ \ t1 1 -- 2. PNG ");

CodePudding user response:

Compile, all, pass the
Warning C4129: 'U' : unrecognized character escape sequence
Warning C4129: 'M: unrecognized character escape sequence
Warning C4129: 'D' : unrecognized character escape sequence

CodePudding user response:

reference 1st floor zgl7903 response:
single '\' is the escape character, path with '\ \'
Cstrings ipath=_T (" C: \ \ Users \ \ MAC \ \ Desktop \ \ shortest path - copy \ \ ZDLJ \ \ res \ \ t1 1 -- 2. PNG ");

Or an error?? , I put it on the onpaint function

CodePudding user response:

refer to the second floor schlafenhamster response:
compilation, all, pass the
Warning C4129: 'U' : unrecognized character escape sequence
Warning C4129: 'M: unrecognized character escape sequence
Warning C4129: 'D' : unrecognized character escape sequence

I am using vs2010, compiler is passed

CodePudding user response:

M_hBitmap picture==0 means no load success

if(! Img. The IsNull ())
{
TransparentPNG (& amp; Img);
Img. The Draw (dc) m_hDC, 15, 14);
}

CodePudding user response:

There is no error, but also have no reaction??

CodePudding user response:

reference 5 floor zgl7903 reply:
m_hBitmap==0 means image no load success

if(! Img. The IsNull ())
{
TransparentPNG (& amp; Img);
Img. The Draw (dc) m_hDC, 15, 14);
}


That m_hBitmap to defined in header files, or show it to an undefined identifiers

CodePudding user response:

M_hBitmap==0 this sentence just analysis the cause of the error, do not need to appear in the code

CodePudding user response:

M_hBitmap!=0; Seems to be already associated, before now?

CodePudding user response:

Your path is too complicated?

CodePudding user response:

refer to 6th floor to educate son reply:
no error, but also have no reaction?

Code deleted this sentence: CDialogEx: : OnPaint ();
  • Related