|
richardye wrote: Since point heap points to the object 'local'...
It would if you had done:
Point *heap = &local; richardye wrote: ...there is no need to new the point 'local'
And if you tried to, the compiler would complain because local is not a pointer.
"Normal is getting dressed in clothes that you buy for work and driving through traffic in a car that you are still paying for, in order to get to the job you need to pay for the clothes and the car and the house you leave vacant all day so you can afford to live in it." - Ellen Goodman
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
|
|
|
|
|
Hi,
I want to extract images from a CImageList and save them as transparent GIF files. I'm using the following GDI+ code and the transparent area comes out black.
<code>
const HICON hIcon = myImageList.ExtractIcon( nImage );
Bitmap* gdiBMP = Bitmap::FromHICON( hIcon );
CLSID encoderClsid;
GetEncoderClsid( T2W( "image/gif" ), &encoderClsid );
Status stat = gdiBMP->Save( L"myfilename.gif", &encoderClsid, NULL );
delete gdiBMP;
</code>
Have Google'd and searched CP to no avail. Any/all suggestions most welcome.
|
|
|
|
|
Does something like this work?
IMAGEINFO imageinfo;
myImageList.GetImageInfo(nImage, &imageinfo);
int width = imageinfo.rcImage.right - imageinfo.rcImage.left;
int height = imageinfo.rcImage.bottom - imageinfo.rcImage.top;
Bitmap TransparentBitmap(width, height, PixelFormat32bppARGB);
Graphics *pBitmapGraphics = Graphics::FromImage(&TransparentBitmap);
pBitmapGraphics->SetCompositingMode(CompositingModeSourceCopy);
SolidBrush TransparentBrush(Gdiplus::Color::Transparent);
pBitmapGraphics->FillRectangle(&TransparentBrush, 0, 0, width, height);
HDC hdc = pBitmapGraphics->GetHDC();
ImageList_Draw(myImageList, nImage, hdc, 0, 0, ILD_TRANSPARENT);
pBitmapGraphics->ReleaseHDC(hdc);
delete pBitmapGraphics;
CLSID encoderClsid;
GetEncoderClsid( T2W( "image/gif" ), &encoderClsid );
Status stat = TransparentBitmap.Save( L"myfilename.gif", &encoderClsid, NULL ); Mark
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
Hi Mark,
Thanks for the reply. I've got a feeling your code isn't the answer, but I'll give it a try.
|
|
|
|
|
Good luck
There's a little trial and error involved in figuring out which combination of
GDI and GDI+ calls preserve alpha and transparency data.
It may look ridiculously complicated for a seemingly simple operation, but with GDI
especially, alpha and transparency data is pretty much ignored except with DIBSections.
Please let me know what works for you!
Mark
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
BTW, try just drawing the icon anywhere on a window or the screen
right after the ExtractIcon call. Does it still have transparency?
If not - that's where you're losing the "background".
If so, then you're losing transparency when crossing the GDI-GDI+
line when you call FromHICON().
Cheers,
Mark
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
Mark Salsbery wrote: BTW, try just drawing the icon anywhere on a window or the screen
right after the ExtractIcon call. Does it still have transparency?
Good question. I suspect it doesn't have transparency at this point. Comments in articles on CP refer to "black" pixels where the transparent pixels should be.
I think I need to convert the C# code at http://www.bobpowell.net/giftransparency.htm[^] into C++, but I'm not a C# guy.
I've started converting them by hand as quick stop-gap measure.
|
|
|
|
|
Neville Franks wrote: I suspect it doesn't have transparency at this point
Well, I tested it. Both of our versions of code keep the transparency fine.
Of course, yours was much simpler
The GDI+ Save code, however, ignores it. Same with PNG.
Find a solution yet (beyond that link)?
Mark
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
|
I'm going to take a look at making a C++ version today.
The selection of the transparent color should be automatic.
FWIW, saving the icon as a TIFF preserves the transparency
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
Mark Salsbery wrote: I'm going to take a look at making a C++ version today.
Sounds great. Look forward to seeing how you go.
|
|
|
|
|
Hi Mark,
Did you ever get this written and working?
|
|
|
|
|
OMG I never even looked at it again!
Wow, that was really a year ago? Man, did I get sidetracked
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
I'm doing binary file input and I want to read 4 32-bit values in binary from a file with the read() command as elegantly as possible. Read gives me back a pointer to a char array of 16 chars (16 bytes of binary data representing the 4 32-bit values, called headerValPtr)
So I have a simple struct:
myStruct
{
int
int
float
float
}
My data types in the struct are 32-bit unsigned integers and floating point vals. So I create a pointer to myStruct and allocate memory for it, call it sillyStruct. Will it work to then say sillyStruct = (myStruct*)headerValPtr? I just want to typecast the binary data into the 4 values in the struct.
I don't have a good textbook handy to see how struct allocates memory. If the struct pointer simply points to a set of consecutive memory locations that hold all of the data, then I'm good. But I'm not 100% sure that is the case.
If you want real code snippets I can throw something together, but this is more of a theoretical question so maybe you can live without?
Thanks,
--Seth
|
|
|
|
|
|
It's like trying to herd a pack of fish!
|
|
|
|
|
Maybe we need a purse seine[^]
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
No problem! A structure is basically a record of a specific size, and therefore you can save an exact copy in binary form and read it back (using sizeof(struct what_ever)). You must ensure that the program writing it and the program reading it is using the same byte alignment or the reader will be reading the wrong number of bytes. That is all there is to it, unless the structure contains a pointer to other data, in which case life get much more complicated.
Note that the above applies mainly to the C language, because C++ can be bit trickery. If you are only using a structure in the manner of your example, then no problem.
INTP
"Program testing can be used to show the presence of bugs, but never to show their absence."Edsger Dijkstra
|
|
|
|
|
search for structure packing, pack your structure for 1 byte.
then
any way you have all the data in an char array,
so try this,
struct MyStruct
{
char a;//1 byte
int b;//4 byte
int c;//4 byte
};
int main()
{
MyStruct MyObj;
MyStruct* l_Stemp = &MyObj;
//You have an array of 9 bytes
//let's say as l_Carr[9];
char* l_cPtr = reinterprete_cast<char*>(l_Stemp);
//Here address of l_Stemp and l_cPtr is same so u can write values to l_cPtr using and read it from l_Stemp
for(int i=0;i<9;i++)
{
*l_cPtr++=l_Carr[i];
}
//Here u'd get ur struct back in the form of l_Stemp pointer, While using this u have to be very careful because,
// pointer is poweful but power comes with responsibility
return 0;
}
}
// I did not compile this program if any compilation error is thr pls let me know
|
|
|
|
|
abhijit bhopale wrote: search for structure packing
You may want to do that yourself
By default....
struct MyStruct
{
char a;//1 byte
int b;//4 byte
int c;//4 byte
};
...is not a 9 byte structure. It's more like
struct MyStruct
{
char a;//1 byte + 3 bytes padding
int b;//4 byte
int c;//4 byte
};
Size is 12 bytes.
Mark
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
Hi.
whenever you right a line of code which ask for an input you make sure that if the input doesn't match the variable's type the program prompt user ( " please enter a digit,..... " or ....) .
so righting 1000 lines of code asking for an input and writing 2000 controll functions to make the program stay running is not a shortcut if there is any.
So , is there any shortcut. for instance, can vi write a line of code in the beginning of program and make sure thatthe program prompt oss whenever the input's not matching?
Thanks
int life()
{
in a land with no bird, no spring. My first journey was a
return 0;
}
|
|
|
|
|
You don't have to duplicate the validation code everywhere you use it.
You can write a function which is called to verify input. Or several functions to validate
different types of input (numeric, alpha-numeric, etc.)
With Windows edit controls, you can subclass the control and perform
validation as characters are entered by the user.
With console input, you can write function(s) which read characters and
perform validation as they're entered by the user.
etc...
Mark
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
Thanks.
I have a long way to go
int life()
{
in a land with no bird, no spring. My first journey was a
return 0;
}
|
|
|
|
|
Yes! But you are asking the right questions, so you are well on your way. Any time you have to write the same piece of code 2 or more times, you must consider making it a separate method/function call. There are other things you will figure out over time, and I have no doubt that you will.
INTP
"Program testing can be used to show the presence of bugs, but never to show their absence."Edsger Dijkstra
|
|
|
|
|
I am building an application that uses external DLL files.
I got unexpected error.
Windows has triggered a breakpoint in abc.exe
This may be due to a corruption of the heap, and indicates a bug in abc.exe or any of the DLLs it has loaded.
The output window may have more diagnostic information.
This runtime doesnot occur always. Only Sometimes it comes but most of time the program works fine.
I couldnot find out what the problem is. If there was a problem in program the error should always occur.
can you please help me
saroj sigdel
-- modified at 14:23 Thursday 8th November, 2007
|
|
|
|