LEADTOOLS Support
Imaging
Imaging SDK Questions
Converting color image to grayscale image.
This topic and its replies were posted before the current version of LEADTOOLS was released and may no longer be applicable.
#1
Posted
:
Friday, May 4, 2012 6:57:10 PM(UTC)
Groups: Registered
Posts: 71
Hi,
I want to convert the color image to grayscale image in VC++, Leadtools v17. Is there any demo example or some sample code to do this? Can we use grayscale command to do this? If then how in VC++?
Thanks...
#2
Posted
:
Saturday, May 5, 2012 11:44:31 PM(UTC)
Groups: Registered, Tech Support
Posts: 1,326
Was thanked: 1 time(s) in 1 post(s)
Since you are using VC++, you can use LEADTOOLS C DLL programming interface to convert your images to grayscale. You can do this by using the L_GrayScaleBitmap function. Please check the following code from our C DLL documentation:
+------------------+
L_INT nRet;
BITMAPHANDLE LeadBitmap; /* Bitmap handle to hold the loaded image. */
/* Load the bitmap, keeping the bits per pixel of the file */
nRet = L_LoadBitmap ("c:\\IMAGE1.CMP", &LeadBitmap, sizeof(BITMAPHANDLE), 0, ORDER_BGR, NULL, NULL);
if(nRet != SUCCESS)
return nRet;
/* Change the bitmap to grayscale */
nRet = L_GrayScaleBitmap(&LeadBitmap, 8 );
if(nRet != SUCCESS)
return nRet;
nRet = L_SaveBitmap("c:\\Result.BMP", &LeadBitmap, FILE_BMP, 24, 0, NULL);
if(nRet != SUCCESS)
return nRet;
L_FreeBitmap(&LeadBitmap);
return SUCCESS;
+------------------+
Thanks,
Maen Badwan
LEADTOOLS Technical Support
#3
Posted
:
Wednesday, May 30, 2012 2:17:41 AM(UTC)
Groups: Registered
Posts: 71
Hi,
Can you please provide a sample application for the above code?
One more thing ,is it possible to read the color data from the buffer and then convert that data to grayscale Bmp image?
Thanks...
#4
Posted
:
Wednesday, May 30, 2012 5:26:16 AM(UTC)
Groups: Registered, Tech Support
Posts: 1,326
Was thanked: 1 time(s) in 1 post(s)
I am attaching a small C DLL Win32 2008 project that shows how you can convert colored image to grayscale.
About loading the image data from buffer, you can use the L_LoadBitmapMemory() to load the image file from memory. For more information, please see the "L_LoadBitmapMemory" help topic in the LEADTOOLS Raster Imaging C DLL help file.
Thanks,
Maen Badwan
LEADTOOLS Technical Support
#5
Posted
:
Wednesday, May 30, 2012 7:56:07 PM(UTC)
Groups: Registered
Posts: 71
Thanks a lot for the reply.... it is very helpful.
I tried to implement this code in MFC application on a button click. But it is returning nRet value=-789 when i call the function L_LoadBitmap.
Can you please tell me why is it returning -ve value?
or If I want to create a MFC application same as the above zipped Win32 application, what i have to do or can you provide the same in MFC.
Thanks..
#6
Posted
:
Thursday, May 31, 2012 5:19:27 AM(UTC)
Groups: Registered, Tech Support
Posts: 1,326
Was thanked: 1 time(s) in 1 post(s)
If you check our help file and headers, you will find that all LEADTOOLS error codes are negative.
This one in particular means Invalid Structure Size. It usually happens in 2 cases:
1. You did not initialize a structure or it members, especially the uStructSize member.
2. Or you are using a version of LEADTOOLS headers with a different version of our DLLs, which you must NEVER do.
Thanks,
Maen Badwan
LEADTOOLS Technical Support
#7
Posted
:
Friday, June 1, 2012 12:36:09 AM(UTC)
Groups: Registered
Posts: 71
LEADTOOLS Support
Imaging
Imaging SDK Questions
Converting color image to grayscale image.
You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.