|
Mark Salsbery wrote: AFAIK, there's no alpha channel support in GDI.
sure there is: AlphaBlend[^]
Mark Salsbery wrote: There's no BITMAPINFO type that represents 32-bit ARGB
format.
DIBs (and HBITMAPs) can certainly handle 32-bit BGRA.
|
|
|
|
|
AlphaBlend() is for DDBs, and only DIBSections support ARGB.
That combo is indeed a solution, but why, when GDI+ provides much more support?
Cheers,
Mark
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
Mark Salsbery wrote: AlphaBlend() is for DDBs
well, sure, but it's a trivial matter to get from a DIB to an HBITMAP.
Mark Salsbery wrote: but why, when GDI+ provides much more support?
that's something only the OP can address...
|
|
|
|
|
Chris Losinger wrote: a trivial matter to get from a DIB to an HBITMAP
Ok. It's also trivial to make a GDI+ Bitmap from a DIB.
The OP has been provided two possible solutions. Both rely on getting the alpha channel data from
his source pixel data, which is the real problem. The rendering is easy, but SetDIBitsToDevice
isn't going to do it.
Mark
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
convert your DIB to an HBITMAP, then use AlphaBlend to draw the HBTIMAP
|
|
|
|
|
I tried lot of coding but could not success . can any one send me the piece of code so that I solve my problem.
Trioum
|
|
|
|
|
If I knew anything about the third party libary you use to load the image,
I could easily send you a code sample.
The library doesn't have any rendering code for ARGB images?
Mark
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
Here's an AlphaBlend() example, using what I know from your sample code.
Note this assumes the FreeImage image is 32bpp with alpha channel...
<font color="Green">
LONG lImageWidth = FreeImage_GetWidth(pFIBitmap);
LONG lImageHeight = FreeImage_GetHeight(pFIBitmap);
WORD wBitsPerPixel = 32;
LONG lBytesPerRow = (((lImageWidth * (long)wBitsPerPixel + 31L) & (~31L)) / 8L);
BITMAPINFO bmi;
memset(&bmi, 0, sizeof(BITMAPINFO));
bmi.bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
bmi.bmiHeader.biWidth = lImageWidth;
bmi.bmiHeader.biHeight = lImageHeight;
bmi.bmiHeader.biPlanes = 1;
bmi.bmiHeader.biBitCount = wBitsPerPixel;
bmi.bmiHeader.biCompression = BI_RGB;
bmi.bmiHeader.biSizeImage = lBytesPerRow * lImageHeight;
<font color="Green">
HDC hdc = ::CreateCompatibleDC(0);
BYTE* pBitmapBits;
HBITMAP hBitmap = ::CreateDIBSection(hdc, &bmi, DIB_RGB_COLORS, (void**)&pBitmapBits, NULL, 0);
if (hBitmap)
{
<font color="Green">
<font color="Green">
memcpy(pBitmapBits, FreeImage_GetBits(pFIBitmap), bmi.bmiHeader.biSizeImage);
HGDIOBJ hOldBitmap = ::SelectObject(hdc, hBitmap);
HDC hClientDC = ::GetDC(hwndWindowToDrawOn);
BLENDFUNCTION bf;
bf.BlendOp = AC_SRC_OVER;
bf.BlendFlags = 0;
bf.SourceConstantAlpha = 0xFF;
bf.AlphaFormat = AC_SRC_ALPHA;
::AlphaBlend(hClientDC, 0, 0, lImageWidth, lImageHeight,
hdc, 0, 0, lImageWidth, lImageHeight, bf);
::ReleaseDC(hwndWindowToDrawOn, hClientDC);
::SelectObject(hdc, hOldBitmap);
::DeleteObject(hBitmap);
}
::DeleteDC(hdc);
Mark
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
Thanks mark it is working with 32 bit bmp file,but it changes the
alpha value of whole pixels not alpha channel that I wants.
Trioum
|
|
|
|
|
trioum wrote: it changes the
alpha value of whole pixels not alpha channel that I wants.
Huh? What does it do and what do you want?
Mark
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
Hi
I am Using VS 6 And working in VC++
i want to disable the cancel button on clicking the ok button.....How to do it
Edit/Delete Message
AbidBhat
|
|
|
|
|
CWnd* p = GetDlgItem(IDCANCEL);
p->EnableWindow(FALSE);
Maxwell Chen
|
|
|
|
|
Thanks
But on adding these lines......it gives an error msg as
error C2501: 'CWnd' : missing storage-class or type specifiers
error C2501: 'p' : missing storage-class or type specifiers
left of '->EnableWindow' must point to class/struct/union
Error executing cl.exe.
AbidBhat
|
|
|
|
|
Your project is Win32 type, right?
HWND h = ::GetDlgItem(hYourDlgHandle, IDCANCEL);
::EnableWindow(h, FALSE);
Maxwell Chen
|
|
|
|
|
Thanks chen
yes it working fine
once again thank u
AbidBhat
|
|
|
|
|
Or if you have handle to button you dont need to use of GetDlgItem.
|
|
|
|
|
Hello everyone,
I am reviewing the exception safety of some code and met with some issues about exception safety in string, which I can not find the answer at hand. I think the 3 code segments may all throw exceptions. Because the storage of string internal character data is on heap (using allocator for char?), so when there is low memory, there will be bad_alloc exception?
1. Initialization
string str1 = "Hello";
2. Assignment
string str2 = str1;
3. Empty construction
string str;
I am not quite sure about (3).
thanks in advance,
George
|
|
|
|
|
I believe that the STL string object will not allocate storage until required or directly requested. So #3 should not be expected to throw an exception.
Note, if the string object you are using is doing something extra, such as using a private/high-performance heap, you cannot know if the heap if being initialized when the first string object is instantiated.
Also note - the exception could also be thrown for other reasons, like heap corruption or address space exhaustion, so do not presume that it can be thrown only when you are out of memory.
Peace!
-=- James Please rate this message - let me know if I helped or not!<hr></hr> If you think it costs a lot to do it right, just wait until you find out how much it costs to do it wrong! Remember that Professional Driver on Closed Course does not mean your Dumb Ass on a Public Road! See DeleteFXPFiles
|
|
|
|
|
Thanks James,
1.
James R. Twine wrote: I believe that the STL string object will not allocate storage until required or directly requested. So #3 should not be expected to throw an exception.
I am using Visual Studio. I am interested to find more information about whether in my specific version of STL implementation, for empty string, whether there will be any space allocation. But in file string, there is no constructor for basic_string. Do you know where to find it? (I believe I should look at the constructor for string, which is the same as the constructor for basic_string)
2.
James R. Twine wrote: heap corruption
Is it structured exception or C++ exception? I belive it is structured exception. But I am talking about C++ exception.
3.
James R. Twine wrote: address space exhaustion
You mean we reserved a lot of space in virtual memory, but not commit?
regards,
George
|
|
|
|
|
George_George wrote: I am using Visual Studio. I am interested to find more information about whether in my specific version of STL implementation, for empty string, whether there will be any space allocation. But in file string, there is no constructor for basic_string. Do you know where to find it? (I believe I should look at the constructor for string, which is the same as the constructor for basic_string)
I am not sure which version of VS you are talking about, but I am sure a simple find in files will locate it for you.
George_George wrote: Is it structured exception or C++ exception? I belive it is structured exception. But I am talking about C++ exception.
AFAIK, that would depend on the type of heap corruption. Your heap could br corrupted such that it thinks that there are no more free blocks avaialble (if you use a non-growable heap), or its internal structured could be fulblungered such that when the heap code tries to use/evaluate them, it causes a crash.
George_George wrote: You mean we reserved a lot of space in virtual memory, but not commit?
That is one way. Another easier way is to not clean up worker threads correctly so that their stack space is not reclaimed. Or if you have a large file mapped into memory, etc.
Peace!
-=- James Please rate this message - let me know if I helped or not!<hr></hr> If you think it costs a lot to do it right, just wait until you find out how much it costs to do it wrong! Remember that Professional Driver on Closed Course does not mean your Dumb Ass on a Public Road! See DeleteFXPFiles
|
|
|
|
|
Thanks James,
1.
James R. Twine wrote: I am not sure which version of VS you are talking about, but I am sure a simple find in files will locate it for you.
I am using Visual Studio 2008, any ideas?
2.
James R. Twine wrote: AFAIK, that would depend on the type of heap corruption. Your heap could br corrupted such that it thinks that there are no more free blocks avaialble (if you use a non-growable heap), or its internal structured could be fulblungered such that when the heap code tries to use/evaluate them, it causes a crash.
I think you mean some meta data of heap, e.g. free space size of the heap is corrupted (so that the actual free memory size is not reflected), then when we allocate later, there will be bad_alloc exception?
regards,
George
|
|
|
|
|
George_George wrote: I think you mean some meta data of heap, e.g. free space size of the heap is corrupted (so that the actual free memory size is not reflected), then when we allocate later, there will be bad_alloc exception?
I do not know of any standard heap that readily knows how much free space it has available, and even if it did, it might be useless information. For example, if a heap has 100 1MB free blocks available, but they each have a used block in-between them, then while the heap has 100MB available, only 100MB could be allocated in a contiguous block.
the heap's internal data structures could be corrupted such that it cannot find the next free block (no pointer to the next free block), which would make it think it is out of memory. Or it could point off to random memory location, which could cause a crash, or try to give you memory that was still in use. Lotsa fun things can happen with heap corruption.
Peace!
-=- James Please rate this message - let me know if I helped or not!<hr></hr> If you think it costs a lot to do it right, just wait until you find out how much it costs to do it wrong! Remember that Professional Driver on Closed Course does not mean your Dumb Ass on a Public Road! See DeleteFXPFiles
|
|
|
|
|
Thanks James,
My question is answered.
regards,
George
|
|
|
|
|
Hi all
can any one kindly tell me how to compile our vc++ program by comandline.
Thanks and Regards
#sanroop#
|
|
|
|
|
Open a Visual C++ IDE window. From Tools | Visual Studio Command Prompt to get the DOS-box.
Maxwell Chen
|
|
|
|
|