|
Hey, it helps to use the right parameters!!
Note to self: do NOT call SetDIBitsToDevice() using DIB_PAL_COLORS, which is kind of what I would expect to use, nope, instead use DIB_RGB_COLORS, and everything is fine! Woot!
¡El diablo está en mis pantalones! ¡Mire, mire!
Real Mentats use only 100% pure, unfooled around with Sapho Juice(tm)!
SELECT * FROM User WHERE Clue > 0
0 rows returned
Save an Orange - Use the VCF!
|
|
|
|
|
Hi,
I'm looking for a way to convert from a unicode CString (project is in UNICODE) to a Base64 string, so I can send it via XML to a web service.
Not much luck trying to use the ATL functions... maybe someone can see what i'm doing wrong or has a sample that works ? thanks !!!
CString csTest = _T("test123");
DWORD dwLen = csTest.GetLength();
int nDestLen = Base64EncodeGetRequiredLength(dwLen);
LPSTR strEncoded = new CHAR[nDestLen];
Base64Encode((const BYTE*)csTest.AllocSysString(), csTest.GetLength(), strEncoded, &nDestLen);
//strEncoded contains: "dABlAHMAdA==ÍÍýýýýÝÝÝÝÝÝ " after conversion
LPSTR strDecoded = NULL;
int iLen = 0;
Base64Decode(strEncoded, nDestLen, NULL, &iLen);
strDecoded = new CHAR[iLen]; //iLen is 7 at this point
Base64Decode(strEncoded, nDestLen, (BYTE*)strDecoded, &iLen);
//strDecoded contains: "t" after conversion, not the original "test123"
|
|
|
|
|
Not sure what is the problem with your code but this works
CString s(_T("Hello world"));
CString sout;
int nDestLen = Base64EncodeGetRequiredLength( s.GetLength());
int outLen = s.GetLength();
LPSTR encoded = new CHAR[ nDestLen];
ZeroMemory( encoded, sizeof(CHAR) * nDestLen);
LPCSTR inPtr = s;
Base64Encode((const BYTE*)inPtr, s.GetLength(), encoded, &nDestLen);
LPSTR decoded = new CHAR[ outLen + 1];
ZeroMemory( decoded, sizeof(CHAR) * (outLen+1));
Base64Decode( encoded, nDestLen, (BYTE *)decoded, &outLen);
sout = decoded;
std::cout << (LPCTSTR)sout << std::endl;
delete [] encoded;
delete [] decoded;
"What classes are you using ? You shouldn't call stuff if you have no idea what it does" Christian Graus in the C# forum
led mike
|
|
|
|
|
Are you compiling this in a Multibyte project ? then it works.... but if I try to compile it in a UNICODE project, I get this error:
error C2440: 'initializing' : cannot convert from 'CString' to 'LPCSTR'
on the line where you set LPCSTR inPtr = s;
since s, the CString, is LPCTSTR.
I ended up using something like this, which converts the unicode to LPSTR first, but not sure if it's the best... (also on my Decode function, I needed to convert the decoded string from MultiByte back to WCHAR to get it to match the original:
//since we're unicode, first let's convert to UTF-8
int iRes = WideCharToMultiByte(CP_UTF8, NULL, csSource, csSource.GetLength()*sizeof(TCHAR), NULL, 0, NULL, NULL);
LPSTR szMultiByte = new CHAR[iRes];
iRes = WideCharToMultiByte(CP_UTF8, NULL, csSource, csSource.GetLength()*sizeof(TCHAR), szMultiByte, iRes, NULL, NULL);
//convert to b64
int iDestLen = Base64EncodeGetRequiredLength(iRes);
LPSTR szDest = new CHAR[iDestLen];
Base64Encode((BYTE*)szMultiByte, iRes, szDest, &iDestLen, NULL);
CString csDest(szDest);
delete szMultiByte;
delete szDest;
return csDest;
|
|
|
|
|
So you have a solution now or no?
"What classes are you using ? You shouldn't call stuff if you have no idea what it does" Christian Graus in the C# forum
led mike
|
|
|
|
|
Yes, it seems ok now, thanks for the feedback.
|
|
|
|
|
|
|
Sachin .S .Potdar wrote: am looking out for a code for Encryption and Decryption of data using RC4 algorithm in VC+
try HERE[^]
Sachin .S .Potdar wrote: Student persuing Masters in Computer Application.
Where?
"Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow
cheers,
Alok Gupta
VC Forum Q&A :- I/ IV
|
|
|
|
|
hi all,
I have problem in msflexgrid, its scrolls don't take the theme of xp.
please answer me..
best regards
-- modified at 13:33 Thursday 11th May, 2006
|
|
|
|
|
How do I get notification that a button is being held down.
In my app I want a single click to advance to the next record and I want a click and hold to advance records slowly.
I was going to set a Timer in the LBUTTONDOWN while tracking in the rectangle of the button but the button eats the LBUTTONDOWN notification for the dialog.
How do I get a button to pass on the LButtonDown notification to its parent dialog? (I tried setting the Notify flag but it didn't change anything)
Thanks in advance.
Dave
I'm pretty sure I would not like to live in a world in which I would never be offended.
I am absolutely certain I don't want to live in a world in which you would never be offended.
Dave
|
|
|
|
|
|
Hi All
I have a window which auto-refreshes every 5 minutes. Now I want to,
1. Once window gets auto-refreshed I need to capture the window message. How should I do that, probably by capturing WM_REFRESH in a windows service or so?
2. Once auto-refresh message has been captured, I need to check whether window contents had been changed from previous display. How can i do that?
Many thanks for your inputs
Ramesh
|
|
|
|
|
Each time the window refreshes, you have to capture it into a bitmap then compare the bitmap with the last screen capture. So to capture the screen:
HDC hMemDC;
HBITMAP hBitmap;
HBITMAP hBitmapOld;
BITMAPINFO bmi;
LPBYTE data;
int width, int height;
RECT rc;
GetWindowRect( hwnd, &rc );
width = rc.right - rc.left;
height = rc.bottom - rc.top;
hMemDC = CreateCompatibleDC( hDC );
hBitmap = CreateDIBSection( hDC, &bmi, DIB_RGB_COLORS, (void**)&data, NULL, NULL );
hBitmapOld = (HBITMAP)SelectObject( hMemDC, hBitmap );
if( hBitmap )
{
BitBlt( hMemDC, 0, 0, width, height, hDC, 0, 0, SRCCOPY );
SelectObject( hMemDC, hBitmapOld );
}
At this point your buffer given by "data" will have the pixel contents from the screen. You will need to load the previous bitmap and compare pixels. To load a previous bitmap you can use the LoadBitmap and GetBitmapBits functions.
I hope this helps.
Deus caritas est
|
|
|
|
|
if (st_x >= 0 && st_y >= 0)
if (st_x <= dForme.Width && st_y <= dForme.Height)
//change button position
button2.SetBounds(st_x, st_y, button2.Width, button2.Height);
else
{
textBox2.Text = st_x.ToString();
textBox3.Text = st_y.ToString();
}
visual c++ position of button little code That is a little code for visual c++. That code change position of button.
is that ok ?
-- modified at 11:00 Thursday 11th May, 2006
|
|
|
|
|
|
I think yes
I see Control.SetBounds Method in (.NET Framework Class Library)
|
|
|
|
|
|
I saw one question C# here i think yesterday that of course cedric answer to the qeustion
|
|
|
|
|
xcar wrote: visual c++ position of button little code That is a little code for visual c++. That code change position of button.
Uuhhh . I didn't understand anything. Could you please rephrase your sentence ?
Ans also, post a question .
|
|
|
|
|
|
|
Hi,
i get a 32 bit RGBA Image from my firewire camera...and i want to display a gray scale image to a Picture Control with MFC!
convert function:
<br />
void CImageProcView::RGBA2Gray(char *Img1, char *Img2, unsigned int ByteSize)<br />
{<br />
for(int i = 0; i<ByteSize/4; i++)<br />
{<br />
Img2[i]=((signed char)Img1[4*i]+(signed char)Img1[4*i+1]+(signed char)Img1[4*i+2])/3;<br />
}<br />
}<br />
<br />
char *CurrentImage;<br />
char *GrayMap;<br />
CStatic m_Img1;<br />
CBitmap Bitmap1;<br />
memcpy(Current,FireCapture->FlippedBuffer,FireCapture->grabBufferSize);<br />
<br />
RGBA2Gray(CurrentImage, GrayMap, FireCapture->grabBufferSize);
<br />
Bitmap1.CreateBitmap(FireCapture->pVih->bmiHeader.biWidth, FireCapture->pVih->bmiHeader.biHeight, 1, 8, GrayMap);<br />
<br />
m_Img1.SetBitmap(Bitmap1);<br />
somthing dont work with this CStatic Picture Control;/ any idea? i think the CreateBitmap dont take the cBitsPerPel;/
bye
|
|
|
|
|
Only about the algorithm:
surfman19 wrote: void CImageProcView::RGBA2Gray(char *Img1, char *Img2, unsigned int ByteSize)
{
for(int i = 0; i {
Img2[i]=((signed char)Img1[4*i]+(signed char)Img1[4*i+1]+(signed char)Img1[4*i+2])/3;
}
}
I think that this will generate some overflows, I like more this:
Img2[i]=signed char(((int)Img1[4*i]+(int)Img1[4*i+1]+(int)Img1[4*i+2])/3);
and why signed ? Is it better using unsigned char/int ?
bye
|
|
|
|
|
<br />
the output of the camera is a RGBA32 image!<br />
<br />
CStatic m_Img1;<br />
unsigned char *ActImage;<br />
unsigned char *GrayMap;<br />
<br />
ActImage = new unsigned char[FireCapture->grabBufferSize];<br />
GrayMap = new unsigned char[FireCapture->grabBufferSize];<br />
<br />
memcpy(ActImage,FireCapture->FlippedBuffer,FireCapture->grabBufferSize);<br />
RGB2Gray(ActImage, GrayMap, FireCapture->grabBufferSize);<br />
<br />
Bitmap1.CreateBitmap(FireCapture->pVih->bmiHeader.biWidth, FireCapture->pVih->bmiHeader.biHeight,<br />
1,8,GrayMap);<br />
m_Img1.SetBitmap(Bitmap1);<br />
<br />
<br />
<br />
<br />
void CImageProcView::RGB2Gray(unsigned char *Img1, unsigned char *Img2, unsigned int ByteSize)<br />
{<br />
for(int i = 0; i<ByteSize/4; i++)<br />
{<br />
Img2[i] = ((char)Img1[4*i] + (char)Img1[4*i+1] + (char)Img1[4*i+2]) / 3;<br />
}<br />
}<br />
why could the CStatic dont display the grayscale image????hm;/
cu
|
|
|
|
|