|
There is no direct formula for converting.
Look at the GDI references for bitmaps on MSDN. The BITMAPINFO contains a BITMAPINFO header which details the bitmap, and an array of RGBQUAD structures which is the colors used in the pallette. To convert using a DIB, first create that array of RGBQUAD structures, and use it to create a pallette ( The colors you use depend on you).
Then for each RGB pixel value in the 24-bit bitmap call GetNearestPaletteIndex(), this will give you the index of the color in the pallette you just created. Use this index as the pixel value in your new 8-bit bitmap. Ultimatly you want to build a new array of pixel values.
To save, all you need to do is create a new BITMAPINFO and BITMAPINFOHEADER for the new image, using the new array of RGBQUAD's and the new array of pixel values.
To get you started, look at Chris Maunders DIB wrapper here[^].
If you let the OS do the convertion for you, it will use the standard color pallette. In most case this is not a problem, but the standard pallette contains a range of all the colors from white to black. If your bitmap contains mostly the color green for example, you will lose a lot of colors since the pallette has colors you don't want to use.
Most paint programs will scan the image before doing a bitdepth conversion, and create a pallette that contains only the colors in the bitmap. You will still lose a lot of colors but not as many as with using a standard pallette.
|
|
|
|
|
Thank you very much for your help BOSS.
|
|
|
|
|
|
why do you want to do this ? Do you want it to be smaller, or is there another reason ?
I'm asking because if the reason is for a toolbar or similar, you can use 24 bit images, if you set it up right
Christian Graus - C++ MVP
'Why don't we jump on a fad that hasn't already been widely discredited ?' - Dilbert
|
|
|
|
|
Hi Christian,
No i want to convert to PRN format , which i have done for 8 bit.
|
|
|
|
|
OK, then just let BltBlt convert it for you
Christian Graus - C++ MVP
'Why don't we jump on a fad that hasn't already been widely discredited ?' - Dilbert
|
|
|
|
|
Also, if mapping to the system palette doesn't give you the quality you want then try a halftone
palette. Even better, there's the Gervautz-Purgathofer octree color quanitization algorithm.
Check out this MSJ article: Wicked Code [^]
|
|
|
|
|
Hi!
I would like to know whether the value of dmPaperSize in DEVMODE structure for custom papersize varies with the printer used. How is it possible to know the dmPaperSize for custom paper size for a particular printer.
Thanks
|
|
|
|
|
vcpgmr wrote: is it possible to know the dmPaperSize for custom paper size for a particular printer
Hi,
Did you try like this?
pDevModeOutput->dmFormName = NewFormName;
pDevModeOutput->dmPaperSize = DMPAPER_USER;
pDevModeOutput->dmPaperLength = CustomLength;
pDevModeOutput->dmPaperWidth = CustomWidth;
Krishnakumar
|
|
|
|
|
Hi!,
Thank you for the reply.
Yes I had tried the way you said, but its not working. Are there any other variables/properties which we need to set before setting value to DocumentProperties
Thank you
|
|
|
|
|
|
how to write and read into files using vc++ for smartphones
i am able to write into file.
i am not able to read and append the file.
after reading how do i print that data on smartphones?
please send me the sample code.
|
|
|
|
|
Can you show us the code that you have tried that does not work?
|
|
|
|
|
Hi
All
I create one DLL with unicode support and i want to use this DLL in my other non unicode application in MFC/VC++, but while using this i get error message of "Application.exe error memory can not read" so anybody have solution to this plz send me.
Thanks
Atool
Atool
|
|
|
|
|
M. Atul wrote: so anybody have solution to this plz send me.
create both dll with unciode support.
I doubt the error comes when u try to call a function of the dll having some TCHAR as parameter..
nave
|
|
|
|
|
I am not using two DLL, i am using one unicode dll and i want to call it in other non unicode client application. In client application i call one fun from DLL which takes DWORD parameter and return CString values.But when i run client application there is error as " Application.exe error memory could not read"
When i debug client application i got error in messagebox where i display CString values which is return from DLL function.
Thanks
Atool
Atool
|
|
|
|
|
M. Atul wrote: I am not using two DLL
M. Atul wrote: and return CString values
here is the pblm. CString internally keeps a pointer of type LPTSTR.
in a unciode define dll it becomes LPTSTR = whcar_t*
in a non unciode application it become LPTSTR - char*
In your case a wchar_t pointer is interpreted as char* pointer after u have got the retun value from the function.
solution:
Change the return type from CString to wchar_t*.
// in dll
wchar_t* fun( DWORD dw )
{
return somepointer;
}
// in client application
CString cs = fun( 2 );
-- modified at 1:49 Friday 2nd February, 2007
nave
|
|
|
|
|
Thanks Naveen R for help
I change in code as u said , though i have problem when i run client application there is message that memory could not read. Is there any need for project setting to run unicode dll in Non unicode client application.
Regards
Atool
Atool
|
|
|
|
|
no. Only thing is that u should not use TCHAR, LPTSTR etc which have different meaning in unicode and non unicode application.
Can u show me the code in that function of dll and how is it called from the client?
nave
|
|
|
|
|
This is code in DLL
wchar_t* CEngDLL::GetStringResourceID(DWORD dwResID) // This function return resource string
{
// CString str;
wchar_t myString[300];
HINSTANCE hInstance = AfxGetResourceHandle();
AfxSetResourceHandle(::GetModuleHandle(L"NSEngDLL.dll"));
LoadStringW(hInstance,dwResID,myString,300) ;
return &myString[0];
}
Following code in client application
BOOL CEngTestDlg::OnInitDialog()
{
CString msg;
CDialog::OnInitDialog();
msg = obj.GetStringResourceID(10);
m_lblExample.SetWindowText(msg); // for loading string from DLL
//other code
}
void CEngTestDlg::OnOK()
{
UpdateData(true);
CString resStr;
//wchar_t* resStr;
resStr = obj.GetStringResourceID(100);
MessageBox(resStr);
// TODO: Add extra validation here
//CDialog::OnOK();
}
when i debug DLL it run fine but when i run client application there is error msg as "Application.exe reference memory x0000000.. could not read memory" so plz guide about this error.
Thanks
Atool
Atool
|
|
|
|
|
M. Atul wrote: return &myString[0];
u r returning an address of locally define object. this is a wrong implementation. Cause the
wchar_t myString[300]; will get destroyed as soon as u return from the function GetStringResourceID.
u should allocate it in heap.
wchar_t* CEngDLL::GetStringResourceID(DWORD dwResID) // This function return resource string
{
// CString str;
wchar_t* pmyString = new wchar_t[300];
HINSTANCE hInstance = AfxGetResourceHandle();
AfxSetResourceHandle(::GetModuleHandle(L"NSEngDLL.dll"));
LoadStringW(hInstance,dwResID,pmyString,300) ;
return pmyString;
}
dont forget to delete the pointer in the client app.
nave
|
|
|
|
|
I need to print from a C++ application using the custom form. It is possible to set user defined paper length and paper width to this custom form. Addition of custom form from the application using AddForm function worked fine. But it was not possible to change the printer settings (paper size) using this custom form. Is there any method by which this can be achieved. I tried with ::DocumentProperties function to get the printer properties.
The reference link to microsoft knowledge base is http://support.microsoft.com/kb/282474
How can we change the printer settings using custom form settings. Please help.
Thankyou
|
|
|
|
|
Do you want to set size of paper for printer A3,A4,.. if yes see DEVMODE structure
|
|
|
|
|
Hi!
Thank you for ur reply.
Yes, I want to set paper size to custom value. But from the form properties. I had set the custom paper size to FORM_INFO_1 structure and added this form to printer server propeerties. But couldn't set the printer properties using this form. Can somebody please help me on this.
thankyou
|
|
|
|
|