Discussion:
Changing PixelFormat in GDI+
(too old to reply)
kkirtac
2005-12-15 18:24:03 UTC
Permalink
Is there a way to change the PixelFormat of the image? i get the picture into
the PictureBox and its PixelFormat is Format24bppRgb, and i want to change it
to Format16bppGrayScale ; i need it with grayscale format..any help is
appreciated, thanks.
Michael Phillips, Jr.
2005-12-15 19:06:11 UTC
Permalink
Format16bppGrayScale is not supported!
Post by kkirtac
Is there a way to change the PixelFormat of the image? i get the picture into
the PictureBox and its PixelFormat is Format24bppRgb, and i want to change it
to Format16bppGrayScale ; i need it with grayscale format..any help is
appreciated, thanks.
kkirtac
2005-12-15 19:36:03 UTC
Permalink
So, no way to change an image to gray level? do i have a chance to retrieve a
specific pixel's A, R, G, B values so that i can make an arithmetic operation
to construct a new image, i ll add those values and will divide the result by
4 and that value will be my new value of that pixel, only 1 value for a
pixel, thanks for help
Post by Michael Phillips, Jr.
Format16bppGrayScale is not supported!
Post by kkirtac
Is there a way to change the PixelFormat of the image? i get the picture into
the PictureBox and its PixelFormat is Format24bppRgb, and i want to change it
to Format16bppGrayScale ; i need it with grayscale format..any help is
appreciated, thanks.
Michael Phillips, Jr.
2005-12-15 20:35:44 UTC
Permalink
Use a color matrix to grayscale. See below:
... code snippet...
Gdiplus::ImageAttributes imAtt;
Gdiplus::ColorMatrix gscale = {
0.30f, 0.30f, 0.30f, 0.00f, 0.00f,
0.59f, 0.59f, 0.59f, 0.00f, 0.00f,
0.11f, 0.11f, 0.11f, 0.00f, 0.00f,
0.00f, 0.00f, 0.00f, 1.00f, 0.00f,
0.00f, 0.00f, 0.00f, 0.00f, 1.00f };
imAtt.SetColorMatrix( &gscale, Gdiplus::ColorMatrixFlagsDefault,
Gdiplus::ColorAdjustTypeBitmap );

g->DrawImage( pImg,
Gdiplus::Rect( 0, 0, dwWidth, dwHeight), // dest rect
0, 0, pImg->GetWidth(), pImg->GetHeight(), // source rect
Gdiplus::UnitPixel,
&imAtt);
...
When you are done, you may create a PixelFormat16bppRGB555 image and then
use
DrawImage to convert from PixelFormat24bppRGB to PixelFormat16bppRGB555.
Post by kkirtac
So, no way to change an image to gray level? do i have a chance to retrieve a
specific pixel's A, R, G, B values so that i can make an arithmetic operation
to construct a new image, i ll add those values and will divide the result by
4 and that value will be my new value of that pixel, only 1 value for a
pixel, thanks for help
Post by Michael Phillips, Jr.
Format16bppGrayScale is not supported!
Post by kkirtac
Is there a way to change the PixelFormat of the image? i get the
picture
into
the PictureBox and its PixelFormat is Format24bppRgb, and i want to
change
it
to Format16bppGrayScale ; i need it with grayscale format..any help is
appreciated, thanks.
kkirtac
2005-12-16 09:38:01 UTC
Permalink
sir Philips, thanks for help, another question is can i reach the A,R,G,B
value of a specific pixel and then make operations on them?
.... code snippet...
Gdiplus::ImageAttributes imAtt;
Gdiplus::ColorMatrix gscale = {
0.30f, 0.30f, 0.30f, 0.00f, 0.00f,
0.59f, 0.59f, 0.59f, 0.00f, 0.00f,
0.11f, 0.11f, 0.11f, 0.00f, 0.00f,
0.00f, 0.00f, 0.00f, 1.00f, 0.00f,
0.00f, 0.00f, 0.00f, 0.00f, 1.00f };
imAtt.SetColorMatrix( &gscale, Gdiplus::ColorMatrixFlagsDefault,
Gdiplus::ColorAdjustTypeBitmap );
g->DrawImage( pImg,
Gdiplus::Rect( 0, 0, dwWidth, dwHeight), // dest rect
0, 0, pImg->GetWidth(), pImg->GetHeight(), // source rect
Gdiplus::UnitPixel,
&imAtt);
....
When you are done, you may create a PixelFormat16bppRGB555 image and then
use
DrawImage to convert from PixelFormat24bppRGB to PixelFormat16bppRGB555.
Post by kkirtac
So, no way to change an image to gray level? do i have a chance to retrieve a
specific pixel's A, R, G, B values so that i can make an arithmetic operation
to construct a new image, i ll add those values and will divide the result by
4 and that value will be my new value of that pixel, only 1 value for a
pixel, thanks for help
Post by Michael Phillips, Jr.
Format16bppGrayScale is not supported!
Post by kkirtac
Is there a way to change the PixelFormat of the image? i get the
picture
into
the PictureBox and its PixelFormat is Format24bppRgb, and i want to
change
it
to Format16bppGrayScale ; i need it with grayscale format..any help is
appreciated, thanks.
Michael Phillips, Jr.
2005-12-16 13:58:18 UTC
Permalink
Use LockBits to obtain access to the image's bits.

Use the Color class to access the A,R,G,B values from the
individual pixels pointed to by the Scan0 member of the
BitmapData structure.
Post by kkirtac
sir Philips, thanks for help, another question is can i reach the A,R,G,B
value of a specific pixel and then make operations on them?
.... code snippet...
Gdiplus::ImageAttributes imAtt;
Gdiplus::ColorMatrix gscale = {
0.30f, 0.30f, 0.30f, 0.00f, 0.00f,
0.59f, 0.59f, 0.59f, 0.00f, 0.00f,
0.11f, 0.11f, 0.11f, 0.00f, 0.00f,
0.00f, 0.00f, 0.00f, 1.00f, 0.00f,
0.00f, 0.00f, 0.00f, 0.00f, 1.00f };
imAtt.SetColorMatrix( &gscale, Gdiplus::ColorMatrixFlagsDefault,
Gdiplus::ColorAdjustTypeBitmap );
g->DrawImage( pImg,
Gdiplus::Rect( 0, 0, dwWidth, dwHeight), // dest rect
0, 0, pImg->GetWidth(), pImg->GetHeight(), // source rect
Gdiplus::UnitPixel,
&imAtt);
....
When you are done, you may create a PixelFormat16bppRGB555 image and then
use
DrawImage to convert from PixelFormat24bppRGB to PixelFormat16bppRGB555.
Post by kkirtac
So, no way to change an image to gray level? do i have a chance to retrieve a
specific pixel's A, R, G, B values so that i can make an arithmetic operation
to construct a new image, i ll add those values and will divide the
result
by
4 and that value will be my new value of that pixel, only 1 value for a
pixel, thanks for help
Post by Michael Phillips, Jr.
Format16bppGrayScale is not supported!
Post by kkirtac
Is there a way to change the PixelFormat of the image? i get the
picture
into
the PictureBox and its PixelFormat is Format24bppRgb, and i want to
change
it
to Format16bppGrayScale ; i need it with grayscale format..any help is
appreciated, thanks.
kkirtac
2005-12-16 17:21:02 UTC
Permalink
sir, i sent you an e-mail..i dont know if i sent correctly...your e-mail ends
with juno.com or jun0.com ?
Post by Michael Phillips, Jr.
Use LockBits to obtain access to the image's bits.
Use the Color class to access the A,R,G,B values from the
individual pixels pointed to by the Scan0 member of the
BitmapData structure.
Post by kkirtac
sir Philips, thanks for help, another question is can i reach the A,R,G,B
value of a specific pixel and then make operations on them?
.... code snippet...
Gdiplus::ImageAttributes imAtt;
Gdiplus::ColorMatrix gscale = {
0.30f, 0.30f, 0.30f, 0.00f, 0.00f,
0.59f, 0.59f, 0.59f, 0.00f, 0.00f,
0.11f, 0.11f, 0.11f, 0.00f, 0.00f,
0.00f, 0.00f, 0.00f, 1.00f, 0.00f,
0.00f, 0.00f, 0.00f, 0.00f, 1.00f };
imAtt.SetColorMatrix( &gscale, Gdiplus::ColorMatrixFlagsDefault,
Gdiplus::ColorAdjustTypeBitmap );
g->DrawImage( pImg,
Gdiplus::Rect( 0, 0, dwWidth, dwHeight), // dest rect
0, 0, pImg->GetWidth(), pImg->GetHeight(), // source rect
Gdiplus::UnitPixel,
&imAtt);
....
When you are done, you may create a PixelFormat16bppRGB555 image and then
use
DrawImage to convert from PixelFormat24bppRGB to PixelFormat16bppRGB555.
Post by kkirtac
So, no way to change an image to gray level? do i have a chance to retrieve a
specific pixel's A, R, G, B values so that i can make an arithmetic operation
to construct a new image, i ll add those values and will divide the
result
by
4 and that value will be my new value of that pixel, only 1 value for a
pixel, thanks for help
Post by Michael Phillips, Jr.
Format16bppGrayScale is not supported!
Post by kkirtac
Is there a way to change the PixelFormat of the image? i get the
picture
into
the PictureBox and its PixelFormat is Format24bppRgb, and i want to
change
it
to Format16bppGrayScale ; i need it with grayscale format..any help is
appreciated, thanks.
Michael Phillips, Jr.
2005-12-16 17:55:53 UTC
Permalink
I did not receive your email.

Please post you question here. Others may benefit
from a solution to your problem.
Post by kkirtac
sir, i sent you an e-mail..i dont know if i sent correctly...your e-mail ends
with juno.com or jun0.com ?
Post by Michael Phillips, Jr.
Use LockBits to obtain access to the image's bits.
Use the Color class to access the A,R,G,B values from the
individual pixels pointed to by the Scan0 member of the
BitmapData structure.
Post by kkirtac
sir Philips, thanks for help, another question is can i reach the A,R,G,B
value of a specific pixel and then make operations on them?
.... code snippet...
Gdiplus::ImageAttributes imAtt;
Gdiplus::ColorMatrix gscale = {
0.30f, 0.30f, 0.30f, 0.00f, 0.00f,
0.59f, 0.59f, 0.59f, 0.00f, 0.00f,
0.11f, 0.11f, 0.11f, 0.00f, 0.00f,
0.00f, 0.00f, 0.00f, 1.00f, 0.00f,
0.00f, 0.00f, 0.00f, 0.00f, 1.00f };
imAtt.SetColorMatrix( &gscale, Gdiplus::ColorMatrixFlagsDefault,
Gdiplus::ColorAdjustTypeBitmap );
g->DrawImage( pImg,
Gdiplus::Rect( 0, 0, dwWidth, dwHeight), // dest rect
0, 0, pImg->GetWidth(), pImg->GetHeight(), // source rect
Gdiplus::UnitPixel,
&imAtt);
....
When you are done, you may create a PixelFormat16bppRGB555 image and then
use
DrawImage to convert from PixelFormat24bppRGB to
PixelFormat16bppRGB555.
Post by kkirtac
So, no way to change an image to gray level? do i have a chance to retrieve a
specific pixel's A, R, G, B values so that i can make an arithmetic operation
to construct a new image, i ll add those values and will divide the
result
by
4 and that value will be my new value of that pixel, only 1 value for a
pixel, thanks for help
Post by Michael Phillips, Jr.
Format16bppGrayScale is not supported!
Post by kkirtac
Is there a way to change the PixelFormat of the image? i get the
picture
into
the PictureBox and its PixelFormat is Format24bppRgb, and i want to
change
it
to Format16bppGrayScale ; i need it with grayscale format..any
help
is
appreciated, thanks.
kkirtac
2005-12-16 18:56:03 UTC
Permalink
sir, the problem is i m lost with all these..can you suggest me an algorithm
or a solution to convert an image to gray level..i tried to do the things
that you posted before but couldnt succeed..i m new to those image
manipulation things and new to gdi..so can you suggest a way for me..what
controls or methods to use maybe..thanks for everything
Post by Michael Phillips, Jr.
I did not receive your email.
Please post you question here. Others may benefit
from a solution to your problem.
Post by kkirtac
sir, i sent you an e-mail..i dont know if i sent correctly...your e-mail ends
with juno.com or jun0.com ?
Post by Michael Phillips, Jr.
Use LockBits to obtain access to the image's bits.
Use the Color class to access the A,R,G,B values from the
individual pixels pointed to by the Scan0 member of the
BitmapData structure.
Post by kkirtac
sir Philips, thanks for help, another question is can i reach the A,R,G,B
value of a specific pixel and then make operations on them?
.... code snippet...
Gdiplus::ImageAttributes imAtt;
Gdiplus::ColorMatrix gscale = {
0.30f, 0.30f, 0.30f, 0.00f, 0.00f,
0.59f, 0.59f, 0.59f, 0.00f, 0.00f,
0.11f, 0.11f, 0.11f, 0.00f, 0.00f,
0.00f, 0.00f, 0.00f, 1.00f, 0.00f,
0.00f, 0.00f, 0.00f, 0.00f, 1.00f };
imAtt.SetColorMatrix( &gscale, Gdiplus::ColorMatrixFlagsDefault,
Gdiplus::ColorAdjustTypeBitmap );
g->DrawImage( pImg,
Gdiplus::Rect( 0, 0, dwWidth, dwHeight), // dest rect
0, 0, pImg->GetWidth(), pImg->GetHeight(), // source rect
Gdiplus::UnitPixel,
&imAtt);
....
When you are done, you may create a PixelFormat16bppRGB555 image and then
use
DrawImage to convert from PixelFormat24bppRGB to
PixelFormat16bppRGB555.
Post by kkirtac
So, no way to change an image to gray level? do i have a chance to
retrieve a
specific pixel's A, R, G, B values so that i can make an arithmetic
operation
to construct a new image, i ll add those values and will divide the
result
by
4 and that value will be my new value of that pixel, only 1 value for a
pixel, thanks for help
Post by Michael Phillips, Jr.
Format16bppGrayScale is not supported!
Post by kkirtac
Is there a way to change the PixelFormat of the image? i get the
picture
into
the PictureBox and its PixelFormat is Format24bppRgb, and i want to
change
it
to Format16bppGrayScale ; i need it with grayscale format..any
help
is
appreciated, thanks.
Michael Phillips, Jr.
2005-12-16 19:01:59 UTC
Permalink
Try this site:
http://www.bobpowell.net/grayscale.htm
Post by kkirtac
sir, the problem is i m lost with all these..can you suggest me an algorithm
or a solution to convert an image to gray level..i tried to do the things
that you posted before but couldnt succeed..i m new to those image
manipulation things and new to gdi..so can you suggest a way for me..what
controls or methods to use maybe..thanks for everything
Post by Michael Phillips, Jr.
I did not receive your email.
Please post you question here. Others may benefit
from a solution to your problem.
Post by kkirtac
sir, i sent you an e-mail..i dont know if i sent correctly...your
e-mail
ends
with juno.com or jun0.com ?
Post by Michael Phillips, Jr.
Use LockBits to obtain access to the image's bits.
Use the Color class to access the A,R,G,B values from the
individual pixels pointed to by the Scan0 member of the
BitmapData structure.
Post by kkirtac
sir Philips, thanks for help, another question is can i reach the A,R,G,B
value of a specific pixel and then make operations on them?
.... code snippet...
Gdiplus::ImageAttributes imAtt;
Gdiplus::ColorMatrix gscale = {
0.30f, 0.30f, 0.30f, 0.00f, 0.00f,
0.59f, 0.59f, 0.59f, 0.00f, 0.00f,
0.11f, 0.11f, 0.11f, 0.00f, 0.00f,
0.00f, 0.00f, 0.00f, 1.00f, 0.00f,
0.00f, 0.00f, 0.00f, 0.00f, 1.00f };
imAtt.SetColorMatrix( &gscale,
Gdiplus::ColorMatrixFlagsDefault,
Gdiplus::ColorAdjustTypeBitmap );
g->DrawImage( pImg,
Gdiplus::Rect( 0, 0, dwWidth, dwHeight), // dest rect
0, 0, pImg->GetWidth(), pImg->GetHeight(), // source rect
Gdiplus::UnitPixel,
&imAtt);
....
When you are done, you may create a PixelFormat16bppRGB555 image
and
then
use
DrawImage to convert from PixelFormat24bppRGB to
PixelFormat16bppRGB555.
Post by kkirtac
So, no way to change an image to gray level? do i have a chance to
retrieve a
specific pixel's A, R, G, B values so that i can make an arithmetic
operation
to construct a new image, i ll add those values and will divide the
result
by
4 and that value will be my new value of that pixel, only 1 value for a
pixel, thanks for help
Post by Michael Phillips, Jr.
Format16bppGrayScale is not supported!
Post by kkirtac
Is there a way to change the PixelFormat of the image? i get the
picture
into
the PictureBox and its PixelFormat is Format24bppRgb, and i
want
to
change
it
to Format16bppGrayScale ; i need it with grayscale format..any
help
is
appreciated, thanks.
A Hicklin
2005-12-20 17:07:06 UTC
Permalink
On a related issue: when I have a BMP created or opened in VB.NET as
Imaging.PixelFormat.Format8bppIndexed, but pass it to an unmanaged C++ DLL,
the resulting image data is always 32bpp.

_________________________
In other words, if (in VB.NET)
_________________________
Declare Function BitmapDebugData Lib "foo.dll" Alias "***@4"
(ByVal hbmp As IntPtr) As Integer
[...]
' watch verifies that bmpTemp.PixelFormat is Format8bppIndexed here
Dim hbmp As IntPtr = bmpTemp.GetHbitmap()
BitmapDebugData(hbmp)

_________________________
But then in the C++ DLL:
_________________________
int CALLINGCONV BitmapDebugData(HBITMAP hbmp) {
BITMAP thisbmp;

if (!GetObject(hbmp, sizeof(BITMAP), (LPSTR)&thisbmp)) return {error}
//thisbmp.bmBitsPixel now is 32

_________________________

What's going on? I wonder if in VB.NET the Format8bppIndexed is really 8
bits, or is really 32 bits under the hood.

I have a large C library of functions that basically do array manipulation
at 8bpp, and I'd really rather avoid it.

Suggestions?

-Austin
Michael Phillips, Jr.
2005-12-20 17:23:27 UTC
Permalink
Post by A Hicklin
Dim hbmp As IntPtr = bmpTemp.GetHbitmap()
GetHbitmap() always returns a 32bpp bitmap.

For performance, gdiplus unpacks Indexed pixel formats
to 32bpp internally!

If you want an 8bpp bitmap handle instead of a 32bpp bitmap handle,
you must create a 8bpp DIB with CreateDIBSection and Marshal
the gdiplus Format8bppIndexed bitmap's bits to the new 8bpp DIB
using LockBits.
Post by A Hicklin
On a related issue: when I have a BMP created or opened in VB.NET as
Imaging.PixelFormat.Format8bppIndexed, but pass it to an unmanaged C++ DLL,
the resulting image data is always 32bpp.
_________________________
In other words, if (in VB.NET)
_________________________
(ByVal hbmp As IntPtr) As Integer
[...]
' watch verifies that bmpTemp.PixelFormat is Format8bppIndexed here
Dim hbmp As IntPtr = bmpTemp.GetHbitmap()
BitmapDebugData(hbmp)
_________________________
_________________________
int CALLINGCONV BitmapDebugData(HBITMAP hbmp) {
BITMAP thisbmp;
if (!GetObject(hbmp, sizeof(BITMAP), (LPSTR)&thisbmp)) return {error}
//thisbmp.bmBitsPixel now is 32
_________________________
What's going on? I wonder if in VB.NET the Format8bppIndexed is really 8
bits, or is really 32 bits under the hood.
I have a large C library of functions that basically do array manipulation
at 8bpp, and I'd really rather avoid it.
Suggestions?
-Austin
unknown
2005-12-20 17:52:03 UTC
Permalink
Michael - thanks! Just to be clear - there is no way of passing an 8bpp
handle from VB.NET, and I don't have an alternative to GetHbitmap(), so I
have to convert once I get in the C++ DLL. Correct?

On a side note: in the 32bpp quad, what does the 4th octet do? In a std
VB.NET picture box, there is no effect when I change those values in an
image.

-austin
Post by Michael Phillips, Jr.
Post by A Hicklin
Dim hbmp As IntPtr = bmpTemp.GetHbitmap()
GetHbitmap() always returns a 32bpp bitmap.
For performance, gdiplus unpacks Indexed pixel formats
to 32bpp internally!
If you want an 8bpp bitmap handle instead of a 32bpp bitmap handle,
you must create a 8bpp DIB with CreateDIBSection and Marshal
the gdiplus Format8bppIndexed bitmap's bits to the new 8bpp DIB
using LockBits.
Michael Phillips, Jr.
2005-12-20 18:33:51 UTC
Permalink
You may pass an HBITMAP or a packed DIB between any application
regardless of NET!

GetHbitmap() produces a 32bpp HBITMAP by design!

Using P-INVOKE you may create a 8bpp DIB with CreateDIBSection
and pass that handle.

You may also use the clipboard to pass bitmap handles. Use CF_BITMAP,
CF_DIB
or CF_DIBV5 clipboard formats. For a 8bpp CF_BITMAP HBITMAP, you must pass
the HBITMAP
handle and the HPALETTE handle for the colors.

For a CF_DIB, you pass a handle to global memory that represents the 8bpp
bitmap
as a packed DIB.

You can take that 8bpp vb net bitmap and create a packed DIB and pass that
handle to the clipboard and retrieve it with you c++ application.

A packed DIB is a memory DIB that looks like the following:
BITMAPINFOHEADER
Color Table(Palette)
Bitmap bits
Post by unknown
On a side note: in the 32bpp quad, what does the 4th octet do? In a std
VB.NET picture box, there is no effect when I change those values in an
image.
A 32bpp bitmap is represented as 0xAARRGGBB. The highest byte
represents an alpha channel. It may only be used by an application that
knows the alpha channel is present. For Window's GDI, the alpha
channel must be premultiplied before it can be used with the GDI
AlphaBlend function. By default, 32bpp GDI Bitmaps created with
BI_RGB compression do not use the high order byte. It is ignored.

Gdiplus will premultiply internally when used with DrawImage and other
gdiplus API's.
Post by unknown
Michael - thanks! Just to be clear - there is no way of passing an 8bpp
handle from VB.NET, and I don't have an alternative to GetHbitmap(), so I
have to convert once I get in the C++ DLL. Correct?
On a side note: in the 32bpp quad, what does the 4th octet do? In a std
VB.NET picture box, there is no effect when I change those values in an
image.
-austin
Post by Michael Phillips, Jr.
Post by A Hicklin
Dim hbmp As IntPtr = bmpTemp.GetHbitmap()
GetHbitmap() always returns a 32bpp bitmap.
For performance, gdiplus unpacks Indexed pixel formats
to 32bpp internally!
If you want an 8bpp bitmap handle instead of a 32bpp bitmap handle,
you must create a 8bpp DIB with CreateDIBSection and Marshal
the gdiplus Format8bppIndexed bitmap's bits to the new 8bpp DIB
using LockBits.
kkirtac
2005-12-16 20:10:02 UTC
Permalink
thanks i looked at there, then i did those :
Bitmap* bm = new Bitmap(source->Width, source->Height);
Color* cl;
double s;
for(int i=0;i<(source->get_Height());i++)
for(int j=0;j<(source->get_Width());j++){
*cl = source->GetPixel(i, j);
s = (cl->get_R)*0.3 + (cl->get_G)*0.59 + (cl->get_B)*0.11 ;
bm->SetPixel(j, i, Color::FromArgb( (int)s,(int)s,(int)s ) );
}

i get errors like that :
error C2475: 'Color::get_R' : forming a pointer-to-member requires explicit
use of the adress-of operator ('&') and a qualified name
error C2296: '*' : illegal, left operand has type 'unsigned char(__clrcall
Color::*)(void)'
error C2146: syntax error : missing ';' before identifier 'GraphicsState'
..but this last error is from GdiPlusEnums.h and i dont know what to do..
error C2501: 'GraphicsState' : missing storage-class or type specifiers
error C2146: syntax error : missing ';' before identifier 'ObjectTypeIsValid'
error C2433: 'BOOL' : 'inline' not permitted on data declerations
..all of these last 4 errors are from GdiPlusEnums.h... i included that
header file and compiled again but gave me same errrors..
i got stuck with those..
Post by kkirtac
Is there a way to change the PixelFormat of the image? i get the picture into
the PictureBox and its PixelFormat is Format24bppRgb, and i want to change it
to Format16bppGrayScale ; i need it with grayscale format..any help is
appreciated, thanks.
Michael Phillips, Jr.
2005-12-16 20:45:12 UTC
Permalink
Post by kkirtac
Color* cl;
Change the above to: Color cl;

Additionally, you may use fixpoint arithmetic instead of floating point:
byte gray = ( 19595 *cl.get_R() + 38470 * cl.get_G() + 7471 * cl.get_B() )
Post by kkirtac
Post by kkirtac
16;
...
bm->SetPixel(j, i, Color::FromArgb( 0xFF, gray, gray, gray ) );

...
The fastest method is to use LockBits or a ColorMatrix as I described
previously.
Post by kkirtac
Bitmap* bm = new Bitmap(source->Width, source->Height);
Color* cl;
double s;
for(int i=0;i<(source->get_Height());i++)
for(int j=0;j<(source->get_Width());j++){
*cl = source->GetPixel(i, j);
s = (cl->get_R)*0.3 + (cl->get_G)*0.59 + (cl->get_B)*0.11 ;
bm->SetPixel(j, i, Color::FromArgb( (int)s,(int)s,(int)s ) );
}
error C2475: 'Color::get_R' : forming a pointer-to-member requires explicit
use of the adress-of operator ('&') and a qualified name
error C2296: '*' : illegal, left operand has type 'unsigned char(__clrcall
Color::*)(void)'
error C2146: syntax error : missing ';' before identifier 'GraphicsState'
..but this last error is from GdiPlusEnums.h and i dont know what to do..
error C2501: 'GraphicsState' : missing storage-class or type specifiers
error C2146: syntax error : missing ';' before identifier
'ObjectTypeIsValid'
error C2433: 'BOOL' : 'inline' not permitted on data declerations
..all of these last 4 errors are from GdiPlusEnums.h... i included that
header file and compiled again but gave me same errrors..
i got stuck with those..
Post by kkirtac
Is there a way to change the PixelFormat of the image? i get the picture into
the PictureBox and its PixelFormat is Format24bppRgb, and i want to change it
to Format16bppGrayScale ; i need it with grayscale format..any help is
appreciated, thanks.
kkirtac
2005-12-16 21:09:03 UTC
Permalink
sir it seems ok now; but those weird errors about GdiPlusEnums.h still
remains..those last 4 errors in my previous post..thanks for all
Post by Michael Phillips, Jr.
Post by kkirtac
Color* cl;
Change the above to: Color cl;
byte gray = ( 19595 *cl.get_R() + 38470 * cl.get_G() + 7471 * cl.get_B() )
Post by kkirtac
Post by kkirtac
16;
....
bm->SetPixel(j, i, Color::FromArgb( 0xFF, gray, gray, gray ) );
....
The fastest method is to use LockBits or a ColorMatrix as I described
previously.
Post by kkirtac
Bitmap* bm = new Bitmap(source->Width, source->Height);
Color* cl;
double s;
for(int i=0;i<(source->get_Height());i++)
for(int j=0;j<(source->get_Width());j++){
*cl = source->GetPixel(i, j);
s = (cl->get_R)*0.3 + (cl->get_G)*0.59 + (cl->get_B)*0.11 ;
bm->SetPixel(j, i, Color::FromArgb( (int)s,(int)s,(int)s ) );
}
error C2475: 'Color::get_R' : forming a pointer-to-member requires explicit
use of the adress-of operator ('&') and a qualified name
error C2296: '*' : illegal, left operand has type 'unsigned char(__clrcall
Color::*)(void)'
error C2146: syntax error : missing ';' before identifier 'GraphicsState'
..but this last error is from GdiPlusEnums.h and i dont know what to do..
error C2501: 'GraphicsState' : missing storage-class or type specifiers
error C2146: syntax error : missing ';' before identifier
'ObjectTypeIsValid'
error C2433: 'BOOL' : 'inline' not permitted on data declerations
..all of these last 4 errors are from GdiPlusEnums.h... i included that
header file and compiled again but gave me same errrors..
i got stuck with those..
Post by kkirtac
Is there a way to change the PixelFormat of the image? i get the picture into
the PictureBox and its PixelFormat is Format24bppRgb, and i want to change it
to Format16bppGrayScale ; i need it with grayscale format..any help is
appreciated, thanks.
Michael Phillips, Jr.
2005-12-16 21:18:01 UTC
Permalink
error C2146: syntax error : missing ';' before identifier 'GraphicsState'

Either declare the namespace that you are using
as in --> using namespace Gdiplus;

or fully qualify your classes with Gdiplus::
such as --> Gdiplus::GraphicsState
Post by kkirtac
sir it seems ok now; but those weird errors about GdiPlusEnums.h still
remains..those last 4 errors in my previous post..thanks for all
Post by Michael Phillips, Jr.
Post by kkirtac
Color* cl;
Change the above to: Color cl;
byte gray = ( 19595 *cl.get_R() + 38470 * cl.get_G() + 7471 *
l.get_B() )
Post by kkirtac
Post by kkirtac
16;
....
bm->SetPixel(j, i, Color::FromArgb( 0xFF, gray, gray, gray ) );
....
The fastest method is to use LockBits or a ColorMatrix as I described
previously.
Post by kkirtac
Bitmap* bm = new Bitmap(source->Width, source->Height);
Color* cl;
double s;
for(int i=0;i<(source->get_Height());i++)
for(int j=0;j<(source->get_Width());j++){
*cl = source->GetPixel(i, j);
s = (cl->get_R)*0.3 + (cl->get_G)*0.59 + (cl->get_B)*0.11 ;
bm->SetPixel(j, i, Color::FromArgb( (int)s,(int)s,(int)s ) );
}
error C2475: 'Color::get_R' : forming a pointer-to-member requires explicit
use of the adress-of operator ('&') and a qualified name
error C2296: '*' : illegal, left operand has type 'unsigned
char(__clrcall
Color::*)(void)'
error C2146: syntax error : missing ';' before identifier
'GraphicsState'
..but this last error is from GdiPlusEnums.h and i dont know what to do..
error C2501: 'GraphicsState' : missing storage-class or type specifiers
error C2146: syntax error : missing ';' before identifier
'ObjectTypeIsValid'
error C2433: 'BOOL' : 'inline' not permitted on data declerations
..all of these last 4 errors are from GdiPlusEnums.h... i included that
header file and compiled again but gave me same errrors..
i got stuck with those..
Post by kkirtac
Is there a way to change the PixelFormat of the image? i get the
picture
into
the PictureBox and its PixelFormat is Format24bppRgb, and i want to change it
to Format16bppGrayScale ; i need it with grayscale format..any help is
appreciated, thanks.
kkirtac
2005-12-16 21:43:02 UTC
Permalink
when i try to use Gdiplus:: ... or trying to write "using namespace Gdiplus"
it gives the error :
error C2653: 'Gdiplus' : is not a class or namespace name

...but i ve included Gdiplus.h and GdiplusEnums.h , i wonder what i ve done
missing or done smthg. wrong...
Post by kkirtac
error C2146: syntax error : missing ';' before identifier 'GraphicsState'
Either declare the namespace that you are using
as in --> using namespace Gdiplus;
such as --> Gdiplus::GraphicsState
Post by kkirtac
sir it seems ok now; but those weird errors about GdiPlusEnums.h still
remains..those last 4 errors in my previous post..thanks for all
Post by Michael Phillips, Jr.
Post by kkirtac
Color* cl;
Change the above to: Color cl;
byte gray = ( 19595 *cl.get_R() + 38470 * cl.get_G() + 7471 *
l.get_B() )
Post by kkirtac
Post by kkirtac
16;
....
bm->SetPixel(j, i, Color::FromArgb( 0xFF, gray, gray, gray ) );
....
The fastest method is to use LockBits or a ColorMatrix as I described
previously.
Post by kkirtac
Bitmap* bm = new Bitmap(source->Width, source->Height);
Color* cl;
double s;
for(int i=0;i<(source->get_Height());i++)
for(int j=0;j<(source->get_Width());j++){
*cl = source->GetPixel(i, j);
s = (cl->get_R)*0.3 + (cl->get_G)*0.59 + (cl->get_B)*0.11 ;
bm->SetPixel(j, i, Color::FromArgb( (int)s,(int)s,(int)s ) );
}
error C2475: 'Color::get_R' : forming a pointer-to-member requires explicit
use of the adress-of operator ('&') and a qualified name
error C2296: '*' : illegal, left operand has type 'unsigned char(__clrcall
Color::*)(void)'
error C2146: syntax error : missing ';' before identifier
'GraphicsState'
..but this last error is from GdiPlusEnums.h and i dont know what to do..
error C2501: 'GraphicsState' : missing storage-class or type specifiers
error C2146: syntax error : missing ';' before identifier
'ObjectTypeIsValid'
error C2433: 'BOOL' : 'inline' not permitted on data declerations
..all of these last 4 errors are from GdiPlusEnums.h... i included that
header file and compiled again but gave me same errrors..
i got stuck with those..
Post by kkirtac
Is there a way to change the PixelFormat of the image? i get the
picture
into
the PictureBox and its PixelFormat is Format24bppRgb, and i want to change it
to Format16bppGrayScale ; i need it with grayscale format..any help is
appreciated, thanks.
Michael Phillips, Jr.
2005-12-16 22:08:50 UTC
Permalink
You usually declare it as follows:

#include <gdiplus.h>
using namespace Gdiplus;

Once you include gdiplus.h, it includes every other
header in the Gdiplus namespace!

The above is for c++ only. If you are using managed c++,
you must declare the gdiplus namespace as follows:
using namespace System::Drawing;
using namespace System::Drawing::Drawing2D;
...
etc.
Post by kkirtac
when i try to use Gdiplus:: ... or trying to write "using namespace Gdiplus"
error C2653: 'Gdiplus' : is not a class or namespace name
...but i ve included Gdiplus.h and GdiplusEnums.h , i wonder what i ve done
missing or done smthg. wrong...
Post by kkirtac
error C2146: syntax error : missing ';' before identifier 'GraphicsState'
Either declare the namespace that you are using
as in --> using namespace Gdiplus;
such as --> Gdiplus::GraphicsState
Post by kkirtac
sir it seems ok now; but those weird errors about GdiPlusEnums.h still
remains..those last 4 errors in my previous post..thanks for all
Post by Michael Phillips, Jr.
Post by kkirtac
Color* cl;
Change the above to: Color cl;
byte gray = ( 19595 *cl.get_R() + 38470 * cl.get_G() + 7471 *
l.get_B() )
Post by kkirtac
Post by kkirtac
16;
....
bm->SetPixel(j, i, Color::FromArgb( 0xFF, gray, gray, gray ) );
....
The fastest method is to use LockBits or a ColorMatrix as I described
previously.
Post by kkirtac
Bitmap* bm = new Bitmap(source->Width, source->Height);
Color* cl;
double s;
for(int i=0;i<(source->get_Height());i++)
for(int j=0;j<(source->get_Width());j++){
*cl = source->GetPixel(i, j);
s = (cl->get_R)*0.3 + (cl->get_G)*0.59 + (cl->get_B)*0.11 ;
bm->SetPixel(j, i, Color::FromArgb( (int)s,(int)s,(int)s ) );
}
error C2475: 'Color::get_R' : forming a pointer-to-member requires explicit
use of the adress-of operator ('&') and a qualified name
error C2296: '*' : illegal, left operand has type 'unsigned char(__clrcall
Color::*)(void)'
error C2146: syntax error : missing ';' before identifier 'GraphicsState'
..but this last error is from GdiPlusEnums.h and i dont know what
to
do..
error C2501: 'GraphicsState' : missing storage-class or type specifiers
error C2146: syntax error : missing ';' before identifier 'ObjectTypeIsValid'
error C2433: 'BOOL' : 'inline' not permitted on data declerations
..all of these last 4 errors are from GdiPlusEnums.h... i included that
header file and compiled again but gave me same errrors..
i got stuck with those..
Post by kkirtac
Is there a way to change the PixelFormat of the image? i get the
picture
into
the PictureBox and its PixelFormat is Format24bppRgb, and i want to change it
to Format16bppGrayScale ; i need it with grayscale format..any help is
appreciated, thanks.
kkirtac
2005-12-16 22:17:25 UTC
Permalink
yes, using managed c++ and already included namespace Drawing and
Drawing2D,but something still must be wrong that i still receive those erros
about GdiplusEnums.h
Post by Michael Phillips, Jr.
#include <gdiplus.h>
using namespace Gdiplus;
Once you include gdiplus.h, it includes every other
header in the Gdiplus namespace!
The above is for c++ only. If you are using managed c++,
using namespace System::Drawing;
using namespace System::Drawing::Drawing2D;
....
etc.
Post by kkirtac
when i try to use Gdiplus:: ... or trying to write "using namespace Gdiplus"
error C2653: 'Gdiplus' : is not a class or namespace name
...but i ve included Gdiplus.h and GdiplusEnums.h , i wonder what i ve done
missing or done smthg. wrong...
Post by kkirtac
error C2146: syntax error : missing ';' before identifier 'GraphicsState'
Either declare the namespace that you are using
as in --> using namespace Gdiplus;
such as --> Gdiplus::GraphicsState
Post by kkirtac
sir it seems ok now; but those weird errors about GdiPlusEnums.h still
remains..those last 4 errors in my previous post..thanks for all
Post by Michael Phillips, Jr.
Post by kkirtac
Color* cl;
Change the above to: Color cl;
byte gray = ( 19595 *cl.get_R() + 38470 * cl.get_G() + 7471 *
l.get_B() )
Post by kkirtac
Post by kkirtac
16;
....
bm->SetPixel(j, i, Color::FromArgb( 0xFF, gray, gray, gray ) );
....
The fastest method is to use LockBits or a ColorMatrix as I described
previously.
Post by kkirtac
Bitmap* bm = new Bitmap(source->Width, source->Height);
Color* cl;
double s;
for(int i=0;i<(source->get_Height());i++)
for(int j=0;j<(source->get_Width());j++){
*cl = source->GetPixel(i, j);
s = (cl->get_R)*0.3 + (cl->get_G)*0.59 + (cl->get_B)*0.11 ;
bm->SetPixel(j, i, Color::FromArgb( (int)s,(int)s,(int)s ) );
}
error C2475: 'Color::get_R' : forming a pointer-to-member requires explicit
use of the adress-of operator ('&') and a qualified name
error C2296: '*' : illegal, left operand has type 'unsigned char(__clrcall
Color::*)(void)'
error C2146: syntax error : missing ';' before identifier 'GraphicsState'
..but this last error is from GdiPlusEnums.h and i dont know what
to
do..
error C2501: 'GraphicsState' : missing storage-class or type specifiers
error C2146: syntax error : missing ';' before identifier
'ObjectTypeIsValid'
error C2433: 'BOOL' : 'inline' not permitted on data declerations
..all of these last 4 errors are from GdiPlusEnums.h... i included that
header file and compiled again but gave me same errrors..
i got stuck with those..
Post by kkirtac
Is there a way to change the PixelFormat of the image? i get the
picture
into
the PictureBox and its PixelFormat is Format24bppRgb, and i want to
change it
to Format16bppGrayScale ; i need it with grayscale format..any help is
appreciated, thanks.
Michael Phillips, Jr.
2005-12-16 22:32:34 UTC
Permalink
I did not see any reference to GraphicsState in your code.

You should not include any gdiplus headers while using managed c++!

Just declare the namespace that is required for those classes that you use.
Post by kkirtac
yes, using managed c++ and already included namespace Drawing and
Drawing2D,but something still must be wrong that i still receive those erros
about GdiplusEnums.h
Post by Michael Phillips, Jr.
#include <gdiplus.h>
using namespace Gdiplus;
Once you include gdiplus.h, it includes every other
header in the Gdiplus namespace!
The above is for c++ only. If you are using managed c++,
using namespace System::Drawing;
using namespace System::Drawing::Drawing2D;
....
etc.
Post by kkirtac
when i try to use Gdiplus:: ... or trying to write "using namespace Gdiplus"
error C2653: 'Gdiplus' : is not a class or namespace name
...but i ve included Gdiplus.h and GdiplusEnums.h , i wonder what i ve done
missing or done smthg. wrong...
Post by kkirtac
error C2146: syntax error : missing ';' before identifier
'GraphicsState'
Either declare the namespace that you are using
as in --> using namespace Gdiplus;
such as --> Gdiplus::GraphicsState
Post by kkirtac
sir it seems ok now; but those weird errors about GdiPlusEnums.h
still
remains..those last 4 errors in my previous post..thanks for all
Post by Michael Phillips, Jr.
Post by kkirtac
Color* cl;
Change the above to: Color cl;
byte gray = ( 19595 *cl.get_R() + 38470 * cl.get_G() + 7471 *
l.get_B() )
Post by kkirtac
Post by kkirtac
16;
....
bm->SetPixel(j, i, Color::FromArgb( 0xFF, gray, gray, gray ) );
....
The fastest method is to use LockBits or a ColorMatrix as I described
previously.
Post by kkirtac
Bitmap* bm = new Bitmap(source->Width, source->Height);
Color* cl;
double s;
for(int i=0;i<(source->get_Height());i++)
for(int j=0;j<(source->get_Width());j++){
*cl = source->GetPixel(i, j);
s = (cl->get_R)*0.3 + (cl->get_G)*0.59 + (cl->get_B)*0.11 ;
bm->SetPixel(j, i, Color::FromArgb(
(int)s,(int)s,(int)s ) );
}
error C2475: 'Color::get_R' : forming a pointer-to-member
requires
explicit
use of the adress-of operator ('&') and a qualified name
error C2296: '*' : illegal, left operand has type 'unsigned
char(__clrcall
Color::*)(void)'
error C2146: syntax error : missing ';' before identifier 'GraphicsState'
..but this last error is from GdiPlusEnums.h and i dont know what
to
do..
error C2501: 'GraphicsState' : missing storage-class or type specifiers
error C2146: syntax error : missing ';' before identifier
'ObjectTypeIsValid'
error C2433: 'BOOL' : 'inline' not permitted on data declerations
..all of these last 4 errors are from GdiPlusEnums.h... i
included
that
header file and compiled again but gave me same errrors..
i got stuck with those..
Post by kkirtac
Is there a way to change the PixelFormat of the image? i get the
picture
into
the PictureBox and its PixelFormat is Format24bppRgb, and i want to
change it
to Format16bppGrayScale ; i need it with grayscale format..any
help
is
appreciated, thanks.
kkirtac
2005-12-17 01:47:19 UTC
Permalink
its ok, thanks for everything, code is working now, i ll go on studying
tomorrow, thank you very much for all
Post by Michael Phillips, Jr.
I did not see any reference to GraphicsState in your code.
You should not include any gdiplus headers while using managed c++!
Just declare the namespace that is required for those classes that you use.
Post by kkirtac
yes, using managed c++ and already included namespace Drawing and
Drawing2D,but something still must be wrong that i still receive those erros
about GdiplusEnums.h
Post by Michael Phillips, Jr.
#include <gdiplus.h>
using namespace Gdiplus;
Once you include gdiplus.h, it includes every other
header in the Gdiplus namespace!
The above is for c++ only. If you are using managed c++,
using namespace System::Drawing;
using namespace System::Drawing::Drawing2D;
....
etc.
Post by kkirtac
when i try to use Gdiplus:: ... or trying to write "using namespace Gdiplus"
error C2653: 'Gdiplus' : is not a class or namespace name
...but i ve included Gdiplus.h and GdiplusEnums.h , i wonder what i ve done
missing or done smthg. wrong...
Post by kkirtac
error C2146: syntax error : missing ';' before identifier 'GraphicsState'
Either declare the namespace that you are using
as in --> using namespace Gdiplus;
such as --> Gdiplus::GraphicsState
Post by kkirtac
sir it seems ok now; but those weird errors about GdiPlusEnums.h
still
remains..those last 4 errors in my previous post..thanks for all
Post by Michael Phillips, Jr.
Post by kkirtac
Color* cl;
Change the above to: Color cl;
byte gray = ( 19595 *cl.get_R() + 38470 * cl.get_G() + 7471 *
l.get_B() )
Post by kkirtac
Post by kkirtac
16;
....
bm->SetPixel(j, i, Color::FromArgb( 0xFF, gray, gray, gray ) );
....
The fastest method is to use LockBits or a ColorMatrix as I described
previously.
Post by kkirtac
Bitmap* bm = new Bitmap(source->Width, source->Height);
Color* cl;
double s;
for(int i=0;i<(source->get_Height());i++)
for(int j=0;j<(source->get_Width());j++){
*cl = source->GetPixel(i, j);
s = (cl->get_R)*0.3 + (cl->get_G)*0.59 + (cl->get_B)*0.11 ;
bm->SetPixel(j, i, Color::FromArgb(
(int)s,(int)s,(int)s ) );
}
error C2475: 'Color::get_R' : forming a pointer-to-member
requires
explicit
use of the adress-of operator ('&') and a qualified name
error C2296: '*' : illegal, left operand has type 'unsigned
char(__clrcall
Color::*)(void)'
error C2146: syntax error : missing ';' before identifier
'GraphicsState'
..but this last error is from GdiPlusEnums.h and i dont know what
to
do..
error C2501: 'GraphicsState' : missing storage-class or type
specifiers
error C2146: syntax error : missing ';' before identifier
'ObjectTypeIsValid'
error C2433: 'BOOL' : 'inline' not permitted on data declerations
..all of these last 4 errors are from GdiPlusEnums.h... i
included
that
header file and compiled again but gave me same errrors..
i got stuck with those..
Post by kkirtac
Is there a way to change the PixelFormat of the image? i get the
picture
into
the PictureBox and its PixelFormat is Format24bppRgb, and i want to
change it
to Format16bppGrayScale ; i need it with grayscale format..any
help
is
appreciated, thanks.
kkirtac
2005-12-18 12:44:01 UTC
Permalink
FromArgb methog threw exception when i tried to debug, didnt receive error in
build time though..method does not take Byte parameters, they must be int
though..but when i try cl->get_A or cl.get_A to use the previous method and
ints as parameters, i still receive errors..
Post by Michael Phillips, Jr.
Post by kkirtac
Color* cl;
Change the above to: Color cl;
byte gray = ( 19595 *cl.get_R() + 38470 * cl.get_G() + 7471 * cl.get_B() )
Post by kkirtac
Post by kkirtac
16;
....
bm->SetPixel(j, i, Color::FromArgb( 0xFF, gray, gray, gray ) );
....
The fastest method is to use LockBits or a ColorMatrix as I described
previously.
Post by kkirtac
Bitmap* bm = new Bitmap(source->Width, source->Height);
Color* cl;
double s;
for(int i=0;i<(source->get_Height());i++)
for(int j=0;j<(source->get_Width());j++){
*cl = source->GetPixel(i, j);
s = (cl->get_R)*0.3 + (cl->get_G)*0.59 + (cl->get_B)*0.11 ;
bm->SetPixel(j, i, Color::FromArgb( (int)s,(int)s,(int)s ) );
}
error C2475: 'Color::get_R' : forming a pointer-to-member requires explicit
use of the adress-of operator ('&') and a qualified name
error C2296: '*' : illegal, left operand has type 'unsigned char(__clrcall
Color::*)(void)'
error C2146: syntax error : missing ';' before identifier 'GraphicsState'
..but this last error is from GdiPlusEnums.h and i dont know what to do..
error C2501: 'GraphicsState' : missing storage-class or type specifiers
error C2146: syntax error : missing ';' before identifier
'ObjectTypeIsValid'
error C2433: 'BOOL' : 'inline' not permitted on data declerations
..all of these last 4 errors are from GdiPlusEnums.h... i included that
header file and compiled again but gave me same errrors..
i got stuck with those..
Post by kkirtac
Is there a way to change the PixelFormat of the image? i get the picture into
the PictureBox and its PixelFormat is Format24bppRgb, and i want to change it
to Format16bppGrayScale ; i need it with grayscale format..any help is
appreciated, thanks.
Michael Phillips, Jr.
2005-12-18 15:23:37 UTC
Permalink
Post by kkirtac
cl.get_A
You can't use cl.get_A()! 24bpp and 16bpp images
don't have an alpha channel! PixelFormat16bppRGB1555
is not supported!

Additionally, cl.get_R(), etc, return a byte and
Color::FromArgb is typed for int. However,
the documentation clearly states that the value
is limited to 8bits! A byte is promoted to an int
implicitly when you use Color::FromArgb!
Post by kkirtac
FromArgb methog threw exception when i tried to debug, didnt receive error in
build time though..method does not take Byte parameters, they must be int
though..but when i try cl->get_A or cl.get_A to use the previous method and
ints as parameters, i still receive errors..
Post by Michael Phillips, Jr.
Post by kkirtac
Color* cl;
Change the above to: Color cl;
byte gray = ( 19595 *cl.get_R() + 38470 * cl.get_G() + 7471 *
l.get_B() )
Post by kkirtac
Post by kkirtac
16;
....
bm->SetPixel(j, i, Color::FromArgb( 0xFF, gray, gray, gray ) );
....
The fastest method is to use LockBits or a ColorMatrix as I described
previously.
Post by kkirtac
Bitmap* bm = new Bitmap(source->Width, source->Height);
Color* cl;
double s;
for(int i=0;i<(source->get_Height());i++)
for(int j=0;j<(source->get_Width());j++){
*cl = source->GetPixel(i, j);
s = (cl->get_R)*0.3 + (cl->get_G)*0.59 + (cl->get_B)*0.11 ;
bm->SetPixel(j, i, Color::FromArgb( (int)s,(int)s,(int)s ) );
}
error C2475: 'Color::get_R' : forming a pointer-to-member requires explicit
use of the adress-of operator ('&') and a qualified name
error C2296: '*' : illegal, left operand has type 'unsigned
char(__clrcall
Color::*)(void)'
error C2146: syntax error : missing ';' before identifier
'GraphicsState'
..but this last error is from GdiPlusEnums.h and i dont know what to do..
error C2501: 'GraphicsState' : missing storage-class or type specifiers
error C2146: syntax error : missing ';' before identifier
'ObjectTypeIsValid'
error C2433: 'BOOL' : 'inline' not permitted on data declerations
..all of these last 4 errors are from GdiPlusEnums.h... i included that
header file and compiled again but gave me same errrors..
i got stuck with those..
Post by kkirtac
Is there a way to change the PixelFormat of the image? i get the
picture
into
the PictureBox and its PixelFormat is Format24bppRgb, and i want to change it
to Format16bppGrayScale ; i need it with grayscale format..any help is
appreciated, thanks.
kkirtac
2005-12-18 16:54:02 UTC
Permalink
i dont use Alpha value, i use R,G,B, its ok in build time ; but i get
exception error in runtime, i mean when i
debug.."System.NullReferenceException occured"
Additional information : Object reference not set to an instance of an object
Post by Michael Phillips, Jr.
Post by kkirtac
cl.get_A
You can't use cl.get_A()! 24bpp and 16bpp images
don't have an alpha channel! PixelFormat16bppRGB1555
is not supported!
Additionally, cl.get_R(), etc, return a byte and
Color::FromArgb is typed for int. However,
the documentation clearly states that the value
is limited to 8bits! A byte is promoted to an int
implicitly when you use Color::FromArgb!
Post by kkirtac
FromArgb methog threw exception when i tried to debug, didnt receive error in
build time though..method does not take Byte parameters, they must be int
though..but when i try cl->get_A or cl.get_A to use the previous method and
ints as parameters, i still receive errors..
Post by Michael Phillips, Jr.
Post by kkirtac
Color* cl;
Change the above to: Color cl;
byte gray = ( 19595 *cl.get_R() + 38470 * cl.get_G() + 7471 *
l.get_B() )
Post by kkirtac
Post by kkirtac
16;
....
bm->SetPixel(j, i, Color::FromArgb( 0xFF, gray, gray, gray ) );
....
The fastest method is to use LockBits or a ColorMatrix as I described
previously.
Post by kkirtac
Bitmap* bm = new Bitmap(source->Width, source->Height);
Color* cl;
double s;
for(int i=0;i<(source->get_Height());i++)
for(int j=0;j<(source->get_Width());j++){
*cl = source->GetPixel(i, j);
s = (cl->get_R)*0.3 + (cl->get_G)*0.59 + (cl->get_B)*0.11 ;
bm->SetPixel(j, i, Color::FromArgb( (int)s,(int)s,(int)s ) );
}
error C2475: 'Color::get_R' : forming a pointer-to-member requires explicit
use of the adress-of operator ('&') and a qualified name
error C2296: '*' : illegal, left operand has type 'unsigned char(__clrcall
Color::*)(void)'
error C2146: syntax error : missing ';' before identifier
'GraphicsState'
..but this last error is from GdiPlusEnums.h and i dont know what to do..
error C2501: 'GraphicsState' : missing storage-class or type specifiers
error C2146: syntax error : missing ';' before identifier
'ObjectTypeIsValid'
error C2433: 'BOOL' : 'inline' not permitted on data declerations
..all of these last 4 errors are from GdiPlusEnums.h... i included that
header file and compiled again but gave me same errrors..
i got stuck with those..
Post by kkirtac
Is there a way to change the PixelFormat of the image? i get the
picture
into
the PictureBox and its PixelFormat is Format24bppRgb, and i want to change it
to Format16bppGrayScale ; i need it with grayscale format..any help is
appreciated, thanks.
kkirtac
2005-12-18 18:35:02 UTC
Permalink
sir, seems ok now, thanks
Post by kkirtac
i dont use Alpha value, i use R,G,B, its ok in build time ; but i get
exception error in runtime, i mean when i
debug.."System.NullReferenceException occured"
Additional information : Object reference not set to an instance of an object
Post by Michael Phillips, Jr.
Post by kkirtac
cl.get_A
You can't use cl.get_A()! 24bpp and 16bpp images
don't have an alpha channel! PixelFormat16bppRGB1555
is not supported!
Additionally, cl.get_R(), etc, return a byte and
Color::FromArgb is typed for int. However,
the documentation clearly states that the value
is limited to 8bits! A byte is promoted to an int
implicitly when you use Color::FromArgb!
Post by kkirtac
FromArgb methog threw exception when i tried to debug, didnt receive error in
build time though..method does not take Byte parameters, they must be int
though..but when i try cl->get_A or cl.get_A to use the previous method and
ints as parameters, i still receive errors..
Post by Michael Phillips, Jr.
Post by kkirtac
Color* cl;
Change the above to: Color cl;
byte gray = ( 19595 *cl.get_R() + 38470 * cl.get_G() + 7471 *
l.get_B() )
Post by kkirtac
Post by kkirtac
16;
....
bm->SetPixel(j, i, Color::FromArgb( 0xFF, gray, gray, gray ) );
....
The fastest method is to use LockBits or a ColorMatrix as I described
previously.
Post by kkirtac
Bitmap* bm = new Bitmap(source->Width, source->Height);
Color* cl;
double s;
for(int i=0;i<(source->get_Height());i++)
for(int j=0;j<(source->get_Width());j++){
*cl = source->GetPixel(i, j);
s = (cl->get_R)*0.3 + (cl->get_G)*0.59 + (cl->get_B)*0.11 ;
bm->SetPixel(j, i, Color::FromArgb( (int)s,(int)s,(int)s ) );
}
error C2475: 'Color::get_R' : forming a pointer-to-member requires explicit
use of the adress-of operator ('&') and a qualified name
error C2296: '*' : illegal, left operand has type 'unsigned char(__clrcall
Color::*)(void)'
error C2146: syntax error : missing ';' before identifier 'GraphicsState'
..but this last error is from GdiPlusEnums.h and i dont know what to do..
error C2501: 'GraphicsState' : missing storage-class or type specifiers
error C2146: syntax error : missing ';' before identifier 'ObjectTypeIsValid'
error C2433: 'BOOL' : 'inline' not permitted on data declerations
..all of these last 4 errors are from GdiPlusEnums.h... i included that
header file and compiled again but gave me same errrors..
i got stuck with those..
Post by kkirtac
Is there a way to change the PixelFormat of the image? i get the
picture
into
the PictureBox and its PixelFormat is Format24bppRgb, and i want to
change it
to Format16bppGrayScale ; i need it with grayscale format..any help is
appreciated, thanks.
kkirtac
2005-12-19 11:39:03 UTC
Permalink
Mr. Philips, how can i display the grayscale image that i have now? i have a
picturebox in Form1 ; when i try to load the gray image into that picturebox
i get error, maybe because it already has the coloured image on it, so can
you give me a little code snippet that i can use to see that grayscaled
image? thanks
Post by kkirtac
sir, seems ok now, thanks
Post by kkirtac
i dont use Alpha value, i use R,G,B, its ok in build time ; but i get
exception error in runtime, i mean when i
debug.."System.NullReferenceException occured"
Additional information : Object reference not set to an instance of an object
Post by Michael Phillips, Jr.
Post by kkirtac
cl.get_A
You can't use cl.get_A()! 24bpp and 16bpp images
don't have an alpha channel! PixelFormat16bppRGB1555
is not supported!
Additionally, cl.get_R(), etc, return a byte and
Color::FromArgb is typed for int. However,
the documentation clearly states that the value
is limited to 8bits! A byte is promoted to an int
implicitly when you use Color::FromArgb!
Post by kkirtac
FromArgb methog threw exception when i tried to debug, didnt receive error in
build time though..method does not take Byte parameters, they must be int
though..but when i try cl->get_A or cl.get_A to use the previous method and
ints as parameters, i still receive errors..
Post by Michael Phillips, Jr.
Post by kkirtac
Color* cl;
Change the above to: Color cl;
byte gray = ( 19595 *cl.get_R() + 38470 * cl.get_G() + 7471 *
l.get_B() )
Post by kkirtac
Post by kkirtac
16;
....
bm->SetPixel(j, i, Color::FromArgb( 0xFF, gray, gray, gray ) );
....
The fastest method is to use LockBits or a ColorMatrix as I described
previously.
Post by kkirtac
Bitmap* bm = new Bitmap(source->Width, source->Height);
Color* cl;
double s;
for(int i=0;i<(source->get_Height());i++)
for(int j=0;j<(source->get_Width());j++){
*cl = source->GetPixel(i, j);
s = (cl->get_R)*0.3 + (cl->get_G)*0.59 + (cl->get_B)*0.11 ;
bm->SetPixel(j, i, Color::FromArgb( (int)s,(int)s,(int)s ) );
}
error C2475: 'Color::get_R' : forming a pointer-to-member requires
explicit
use of the adress-of operator ('&') and a qualified name
error C2296: '*' : illegal, left operand has type 'unsigned
char(__clrcall
Color::*)(void)'
error C2146: syntax error : missing ';' before identifier 'GraphicsState'
..but this last error is from GdiPlusEnums.h and i dont know what to
do..
error C2501: 'GraphicsState' : missing storage-class or type specifiers
error C2146: syntax error : missing ';' before identifier
'ObjectTypeIsValid'
error C2433: 'BOOL' : 'inline' not permitted on data declerations
..all of these last 4 errors are from GdiPlusEnums.h... i included that
header file and compiled again but gave me same errrors..
i got stuck with those..
Post by kkirtac
Is there a way to change the PixelFormat of the image? i get the
picture
into
the PictureBox and its PixelFormat is Format24bppRgb, and i want to
change it
to Format16bppGrayScale ; i need it with grayscale format..any help is
appreciated, thanks.
Michael Phillips, Jr.
2005-12-19 20:13:54 UTC
Permalink
Why don't you post the code that you are using to display
your grayscaled image!

What is the error that you receive?
Post by kkirtac
Mr. Philips, how can i display the grayscale image that i have now? i have a
picturebox in Form1 ; when i try to load the gray image into that picturebox
i get error, maybe because it already has the coloured image on it, so can
you give me a little code snippet that i can use to see that grayscaled
image? thanks
Post by kkirtac
sir, seems ok now, thanks
Post by kkirtac
i dont use Alpha value, i use R,G,B, its ok in build time ; but i get
exception error in runtime, i mean when i
debug.."System.NullReferenceException occured"
Additional information : Object reference not set to an instance of an object
Post by Michael Phillips, Jr.
Post by kkirtac
cl.get_A
You can't use cl.get_A()! 24bpp and 16bpp images
don't have an alpha channel! PixelFormat16bppRGB1555
is not supported!
Additionally, cl.get_R(), etc, return a byte and
Color::FromArgb is typed for int. However,
the documentation clearly states that the value
is limited to 8bits! A byte is promoted to an int
implicitly when you use Color::FromArgb!
Post by kkirtac
FromArgb methog threw exception when i tried to debug, didnt
receive error
in
build time though..method does not take Byte parameters, they must be int
though..but when i try cl->get_A or cl.get_A to use the previous
method
and
ints as parameters, i still receive errors..
Post by Michael Phillips, Jr.
Post by kkirtac
Color* cl;
Change the above to: Color cl;
byte gray = ( 19595 *cl.get_R() + 38470 * cl.get_G() + 7471 *
l.get_B() )
Post by kkirtac
Post by kkirtac
16;
....
bm->SetPixel(j, i, Color::FromArgb( 0xFF, gray, gray, gray ) );
....
The fastest method is to use LockBits or a ColorMatrix as I described
previously.
Post by kkirtac
Bitmap* bm = new Bitmap(source->Width, source->Height);
Color* cl;
double s;
for(int i=0;i<(source->get_Height());i++)
for(int j=0;j<(source->get_Width());j++){
*cl = source->GetPixel(i, j);
s = (cl->get_R)*0.3 + (cl->get_G)*0.59 + (cl->get_B)*0.11 ;
bm->SetPixel(j, i, Color::FromArgb(
(int)s,(int)s,(int)s ) );
}
error C2475: 'Color::get_R' : forming a pointer-to-member requires
explicit
use of the adress-of operator ('&') and a qualified name
error C2296: '*' : illegal, left operand has type 'unsigned
char(__clrcall
Color::*)(void)'
error C2146: syntax error : missing ';' before identifier
'GraphicsState'
..but this last error is from GdiPlusEnums.h and i dont know what to
do..
error C2501: 'GraphicsState' : missing storage-class or type specifiers
error C2146: syntax error : missing ';' before identifier
'ObjectTypeIsValid'
error C2433: 'BOOL' : 'inline' not permitted on data
declerations
..all of these last 4 errors are from GdiPlusEnums.h... i included that
header file and compiled again but gave me same errrors..
i got stuck with those..
Post by kkirtac
Is there a way to change the PixelFormat of the image? i get the
picture
into
the PictureBox and its PixelFormat is Format24bppRgb, and i want to
change it
to Format16bppGrayScale ; i need it with grayscale format..any
help is
appreciated, thanks.
kkirtac
2005-12-20 19:02:04 UTC
Permalink
sir its ok, it worked when i tried it in constructor of Form1 class
Post by Michael Phillips, Jr.
Why don't you post the code that you are using to display
your grayscaled image!
What is the error that you receive?
Post by kkirtac
Mr. Philips, how can i display the grayscale image that i have now? i have a
picturebox in Form1 ; when i try to load the gray image into that picturebox
i get error, maybe because it already has the coloured image on it, so can
you give me a little code snippet that i can use to see that grayscaled
image? thanks
Post by kkirtac
sir, seems ok now, thanks
Post by kkirtac
i dont use Alpha value, i use R,G,B, its ok in build time ; but i get
exception error in runtime, i mean when i
debug.."System.NullReferenceException occured"
Additional information : Object reference not set to an instance of an object
Post by Michael Phillips, Jr.
Post by kkirtac
cl.get_A
You can't use cl.get_A()! 24bpp and 16bpp images
don't have an alpha channel! PixelFormat16bppRGB1555
is not supported!
Additionally, cl.get_R(), etc, return a byte and
Color::FromArgb is typed for int. However,
the documentation clearly states that the value
is limited to 8bits! A byte is promoted to an int
implicitly when you use Color::FromArgb!
Post by kkirtac
FromArgb methog threw exception when i tried to debug, didnt
receive error
in
build time though..method does not take Byte parameters, they must be int
though..but when i try cl->get_A or cl.get_A to use the previous
method
and
ints as parameters, i still receive errors..
Post by Michael Phillips, Jr.
Post by kkirtac
Color* cl;
Change the above to: Color cl;
Additionally, you may use fixpoint arithmetic instead of floating
byte gray = ( 19595 *cl.get_R() + 38470 * cl.get_G() + 7471 *
l.get_B() )
Post by kkirtac
Post by kkirtac
16;
....
bm->SetPixel(j, i, Color::FromArgb( 0xFF, gray, gray, gray ) );
....
The fastest method is to use LockBits or a ColorMatrix as I described
previously.
Post by kkirtac
Bitmap* bm = new Bitmap(source->Width, source->Height);
Color* cl;
double s;
for(int i=0;i<(source->get_Height());i++)
for(int j=0;j<(source->get_Width());j++){
*cl = source->GetPixel(i, j);
s = (cl->get_R)*0.3 + (cl->get_G)*0.59 + (cl->get_B)*0.11 ;
bm->SetPixel(j, i, Color::FromArgb(
(int)s,(int)s,(int)s ) );
}
error C2475: 'Color::get_R' : forming a pointer-to-member requires
explicit
use of the adress-of operator ('&') and a qualified name
error C2296: '*' : illegal, left operand has type 'unsigned
char(__clrcall
Color::*)(void)'
error C2146: syntax error : missing ';' before identifier
'GraphicsState'
..but this last error is from GdiPlusEnums.h and i dont know
what to
do..
error C2501: 'GraphicsState' : missing storage-class or type
specifiers
error C2146: syntax error : missing ';' before identifier
'ObjectTypeIsValid'
error C2433: 'BOOL' : 'inline' not permitted on data declerations
..all of these last 4 errors are from GdiPlusEnums.h... i
included that
header file and compiled again but gave me same errrors..
i got stuck with those..
Post by kkirtac
Is there a way to change the PixelFormat of the image? i get the
picture
into
the PictureBox and its PixelFormat is Format24bppRgb, and i
want to
change it
to Format16bppGrayScale ; i need it with grayscale format..any
help is
appreciated, thanks.
Loading...