[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

microsoft.public.dotnet.framework.drawing

convert 8bpp greyscale to 32bppARGB

RB

11/18/2004 9:02:00 PM

Hi,

I'm trying to convert an 8bpp indexed greyscale image to a 32bpp ARGB image.

The steps I follow:
1. open 8bpp image using FromFile
2. create a new 32bppARGB image
3. get 32bpp Graphics using Graphics.FromImage
4. paint the 8bpp image onto the 32bpp using DrawImage.

My problem is the resulting 32bpp image appears all black. I suspect this is
a problem with pallettes, since my 8bpp pixels were 0->2^8, and now they
must correspondingly be 0->2^32.

How can I make my 32bpp image appear the same as my original 8bpp?

Thanks,
Norvin


7 Answers

Bob Powell

11/18/2004 11:05:00 PM

0

What you describe *should* work.

As it's not working, please post code.

--
Bob Powell [MVP]
Visual C#, System.Drawing

Find great Windows Forms articles in Windows Forms Tips and Tricks
http://www.bobpowell.net/tips...

Answer those GDI+ questions with the GDI+ FAQ
http://www.bobpowell.net/f...

All new articles provide code in C# and VB.NET.
Subscribe to the RSS feeds provided and never miss a new article.





"Norvin Laudon" <123@abc.com> wrote in message
news:%23DM4rHbzEHA.1292@TK2MSFTNGP10.phx.gbl...
> Hi,
>
> I'm trying to convert an 8bpp indexed greyscale image to a 32bpp ARGB
image.
>
> The steps I follow:
> 1. open 8bpp image using FromFile
> 2. create a new 32bppARGB image
> 3. get 32bpp Graphics using Graphics.FromImage
> 4. paint the 8bpp image onto the 32bpp using DrawImage.
>
> My problem is the resulting 32bpp image appears all black. I suspect this
is
> a problem with pallettes, since my 8bpp pixels were 0->2^8, and now they
> must correspondingly be 0->2^32.
>
> How can I make my 32bpp image appear the same as my original 8bpp?
>
> Thanks,
> Norvin
>
>


RB

11/18/2004 11:37:00 PM

0

Hi Bob,

Here's the code:

<code>
Bitmap tmp = Image2D.VisionImage.FromFile("visraw.img");
tmp.Save("8bppvisraw.bmp", ImageFormat.Bmp);

// the above file 8bppvisraw.bmp loaded in mspaint looks great

Bitmap topBitmap = new Bitmap(tmp.Width, tmp.Height,
PixelFormat.Format32bppRgb);
Graphics g = Graphics.FromImage(topBitmap);
g.DrawImage(topBitmap, 0, 0);
g.Dispose();

topBitmap.Save("32bppvisraw.bmp", ImageFormat.Bmp );

// the above file 32bppvisraw.bmp loaded in mspaint looks all black.
</code>

I've tried commenting out the g.Dispose() method, to no avail

Thanks,
Norvin

"Bob Powell [MVP]" <bob@_spamkiller_bobpowell.net> wrote in message
news:eBN9kMczEHA.1308@TK2MSFTNGP09.phx.gbl...
> What you describe *should* work.
>
> As it's not working, please post code.
>
> --
> Bob Powell [MVP]
> Visual C#, System.Drawing
>
> Find great Windows Forms articles in Windows Forms Tips and Tricks
> http://www.bobpowell.net/tips...
>
> Answer those GDI+ questions with the GDI+ FAQ
> http://www.bobpowell.net/f...
>
> All new articles provide code in C# and VB.NET.
> Subscribe to the RSS feeds provided and never miss a new article.
>
>
>
>
>
> "Norvin Laudon" <123@abc.com> wrote in message
> news:%23DM4rHbzEHA.1292@TK2MSFTNGP10.phx.gbl...
> > Hi,
> >
> > I'm trying to convert an 8bpp indexed greyscale image to a 32bpp ARGB
> image.
> >
> > The steps I follow:
> > 1. open 8bpp image using FromFile
> > 2. create a new 32bppARGB image
> > 3. get 32bpp Graphics using Graphics.FromImage
> > 4. paint the 8bpp image onto the 32bpp using DrawImage.
> >
> > My problem is the resulting 32bpp image appears all black. I suspect
this
> is
> > a problem with pallettes, since my 8bpp pixels were 0->2^8, and now they
> > must correspondingly be 0->2^32.
> >
> > How can I make my 32bpp image appear the same as my original 8bpp?
> >
> > Thanks,
> > Norvin
> >
> >
>
>


Bob Powell

11/18/2004 11:52:00 PM

0

Directly after the g=Graphics.FromImage(topBitmap);

put...

g.Clear(Color.White);

see what happens and let me know.


--
Bob Powell [MVP]
Visual C#, System.Drawing

Find great Windows Forms articles in Windows Forms Tips and Tricks
http://www.bobpowell.net/tips...

Answer those GDI+ questions with the GDI+ FAQ
http://www.bobpowell.net/f...

All new articles provide code in C# and VB.NET.
Subscribe to the RSS feeds provided and never miss a new article.





"Norvin Laudon" <123@abc.com> wrote in message
news:euefWeczEHA.576@TK2MSFTNGP14.phx.gbl...
> Hi Bob,
>
> Here's the code:
>
> <code>
> Bitmap tmp = Image2D.VisionImage.FromFile("visraw.img");
> tmp.Save("8bppvisraw.bmp", ImageFormat.Bmp);
>
> // the above file 8bppvisraw.bmp loaded in mspaint looks great
>
> Bitmap topBitmap = new Bitmap(tmp.Width, tmp.Height,
> PixelFormat.Format32bppRgb);
> Graphics g = Graphics.FromImage(topBitmap);
> g.DrawImage(topBitmap, 0, 0);
> g.Dispose();
>
> topBitmap.Save("32bppvisraw.bmp", ImageFormat.Bmp );
>
> // the above file 32bppvisraw.bmp loaded in mspaint looks all black.
> </code>
>
> I've tried commenting out the g.Dispose() method, to no avail
>
> Thanks,
> Norvin
>
> "Bob Powell [MVP]" <bob@_spamkiller_bobpowell.net> wrote in message
> news:eBN9kMczEHA.1308@TK2MSFTNGP09.phx.gbl...
> > What you describe *should* work.
> >
> > As it's not working, please post code.
> >
> > --
> > Bob Powell [MVP]
> > Visual C#, System.Drawing
> >
> > Find great Windows Forms articles in Windows Forms Tips and Tricks
> > http://www.bobpowell.net/tips...
> >
> > Answer those GDI+ questions with the GDI+ FAQ
> > http://www.bobpowell.net/f...
> >
> > All new articles provide code in C# and VB.NET.
> > Subscribe to the RSS feeds provided and never miss a new article.
> >
> >
> >
> >
> >
> > "Norvin Laudon" <123@abc.com> wrote in message
> > news:%23DM4rHbzEHA.1292@TK2MSFTNGP10.phx.gbl...
> > > Hi,
> > >
> > > I'm trying to convert an 8bpp indexed greyscale image to a 32bpp ARGB
> > image.
> > >
> > > The steps I follow:
> > > 1. open 8bpp image using FromFile
> > > 2. create a new 32bppARGB image
> > > 3. get 32bpp Graphics using Graphics.FromImage
> > > 4. paint the 8bpp image onto the 32bpp using DrawImage.
> > >
> > > My problem is the resulting 32bpp image appears all black. I suspect
> this
> > is
> > > a problem with pallettes, since my 8bpp pixels were 0->2^8, and now
they
> > > must correspondingly be 0->2^32.
> > >
> > > How can I make my 32bpp image appear the same as my original 8bpp?
> > >
> > > Thanks,
> > > Norvin
> > >
> > >
> >
> >
>
>


RB

11/18/2004 11:56:00 PM

0

By the way, more information, the original 8bpp greyscale image is created
by some code of mine, from raw data, as follows:

<code>
// manually create a grey palette to use when we create the bitmap
Bitmap tmp = new Bitmap(1, 1, PixelFormat.Format8bppIndexed);

ColorPalette greyPal = tmp.Palette;

for(int i = 0;i<greyPal.Entries.Length;i++)
greyPal.Entries[i] = Color.FromArgb(i,i,i);

bitmap.Palette = greyPal;

.... more code that lock's bits and marshals in raw data
</code>

Maybe my problem is in the way I'm creating that color palette?

Norvin


"Norvin Laudon" <123@abc.com> wrote in message
news:euefWeczEHA.576@TK2MSFTNGP14.phx.gbl...
> Hi Bob,
>
> Here's the code:
>
> <code>
> Bitmap tmp = Image2D.VisionImage.FromFile("visraw.img");
> tmp.Save("8bppvisraw.bmp", ImageFormat.Bmp);
>
> // the above file 8bppvisraw.bmp loaded in mspaint looks great
>
> Bitmap topBitmap = new Bitmap(tmp.Width, tmp.Height,
> PixelFormat.Format32bppRgb);
> Graphics g = Graphics.FromImage(topBitmap);
> g.DrawImage(topBitmap, 0, 0);
> g.Dispose();
>
> topBitmap.Save("32bppvisraw.bmp", ImageFormat.Bmp );
>
> // the above file 32bppvisraw.bmp loaded in mspaint looks all black.
> </code>
>
> I've tried commenting out the g.Dispose() method, to no avail
>
> Thanks,
> Norvin
>
> "Bob Powell [MVP]" <bob@_spamkiller_bobpowell.net> wrote in message
> news:eBN9kMczEHA.1308@TK2MSFTNGP09.phx.gbl...
> > What you describe *should* work.
> >
> > As it's not working, please post code.
> >
> > --
> > Bob Powell [MVP]
> > Visual C#, System.Drawing
> >
> > Find great Windows Forms articles in Windows Forms Tips and Tricks
> > http://www.bobpowell.net/tips...
> >
> > Answer those GDI+ questions with the GDI+ FAQ
> > http://www.bobpowell.net/f...
> >
> > All new articles provide code in C# and VB.NET.
> > Subscribe to the RSS feeds provided and never miss a new article.
> >
> >
> >
> >
> >
> > "Norvin Laudon" <123@abc.com> wrote in message
> > news:%23DM4rHbzEHA.1292@TK2MSFTNGP10.phx.gbl...
> > > Hi,
> > >
> > > I'm trying to convert an 8bpp indexed greyscale image to a 32bpp ARGB
> > image.
> > >
> > > The steps I follow:
> > > 1. open 8bpp image using FromFile
> > > 2. create a new 32bppARGB image
> > > 3. get 32bpp Graphics using Graphics.FromImage
> > > 4. paint the 8bpp image onto the 32bpp using DrawImage.
> > >
> > > My problem is the resulting 32bpp image appears all black. I suspect
> this
> > is
> > > a problem with pallettes, since my 8bpp pixels were 0->2^8, and now
they
> > > must correspondingly be 0->2^32.
> > >
> > > How can I make my 32bpp image appear the same as my original 8bpp?
> > >
> > > Thanks,
> > > Norvin
> > >
> > >
> >
> >
>
>


RB

11/18/2004 11:58:00 PM

0

Hi Bob,

Now the whole image is pure white, as opposed to pure black. Seems like my
drawimage just isn't working for some reason.

Did you see my other post detailing the method which creates the original
8bpp image?

Norvin


"Bob Powell [MVP]" <bob@_spamkiller_bobpowell.net> wrote in message
news:eWjvgmczEHA.2540@TK2MSFTNGP09.phx.gbl...
> Directly after the g=Graphics.FromImage(topBitmap);
>
> put...
>
> g.Clear(Color.White);
>
> see what happens and let me know.
>
>
> --
> Bob Powell [MVP]
> Visual C#, System.Drawing
>
> Find great Windows Forms articles in Windows Forms Tips and Tricks
> http://www.bobpowell.net/tips...
>
> Answer those GDI+ questions with the GDI+ FAQ
> http://www.bobpowell.net/f...
>
> All new articles provide code in C# and VB.NET.
> Subscribe to the RSS feeds provided and never miss a new article.
>
>
>
>
>
> "Norvin Laudon" <123@abc.com> wrote in message
> news:euefWeczEHA.576@TK2MSFTNGP14.phx.gbl...
> > Hi Bob,
> >
> > Here's the code:
> >
> > <code>
> > Bitmap tmp = Image2D.VisionImage.FromFile("visraw.img");
> > tmp.Save("8bppvisraw.bmp", ImageFormat.Bmp);
> >
> > // the above file 8bppvisraw.bmp loaded in mspaint looks great
> >
> > Bitmap topBitmap = new Bitmap(tmp.Width, tmp.Height,
> > PixelFormat.Format32bppRgb);
> > Graphics g = Graphics.FromImage(topBitmap);
> > g.DrawImage(topBitmap, 0, 0);
> > g.Dispose();
> >
> > topBitmap.Save("32bppvisraw.bmp", ImageFormat.Bmp );
> >
> > // the above file 32bppvisraw.bmp loaded in mspaint looks all black.
> > </code>
> >
> > I've tried commenting out the g.Dispose() method, to no avail
> >
> > Thanks,
> > Norvin
> >
> > "Bob Powell [MVP]" <bob@_spamkiller_bobpowell.net> wrote in message
> > news:eBN9kMczEHA.1308@TK2MSFTNGP09.phx.gbl...
> > > What you describe *should* work.
> > >
> > > As it's not working, please post code.
> > >
> > > --
> > > Bob Powell [MVP]
> > > Visual C#, System.Drawing
> > >
> > > Find great Windows Forms articles in Windows Forms Tips and Tricks
> > > http://www.bobpowell.net/tips...
> > >
> > > Answer those GDI+ questions with the GDI+ FAQ
> > > http://www.bobpowell.net/f...
> > >
> > > All new articles provide code in C# and VB.NET.
> > > Subscribe to the RSS feeds provided and never miss a new article.
> > >
> > >
> > >
> > >
> > >
> > > "Norvin Laudon" <123@abc.com> wrote in message
> > > news:%23DM4rHbzEHA.1292@TK2MSFTNGP10.phx.gbl...
> > > > Hi,
> > > >
> > > > I'm trying to convert an 8bpp indexed greyscale image to a 32bpp
ARGB
> > > image.
> > > >
> > > > The steps I follow:
> > > > 1. open 8bpp image using FromFile
> > > > 2. create a new 32bppARGB image
> > > > 3. get 32bpp Graphics using Graphics.FromImage
> > > > 4. paint the 8bpp image onto the 32bpp using DrawImage.
> > > >
> > > > My problem is the resulting 32bpp image appears all black. I suspect
> > this
> > > is
> > > > a problem with pallettes, since my 8bpp pixels were 0->2^8, and now
> they
> > > > must correspondingly be 0->2^32.
> > > >
> > > > How can I make my 32bpp image appear the same as my original 8bpp?
> > > >
> > > > Thanks,
> > > > Norvin
> > > >
> > > >
> > >
> > >
> >
> >
>
>


Bob Powell

11/19/2004 9:30:00 AM

0

I just noticed that you are trying to draw the image topBitmap onto itself!
you should be drawing "tmp" instead...

g.DrawImage(tmp,0,0);



--
Bob Powell [MVP]
Visual C#, System.Drawing

Find great Windows Forms articles in Windows Forms Tips and Tricks
http://www.bobpowell.net/tips...

Answer those GDI+ questions with the GDI+ FAQ
http://www.bobpowell.net/f...

All new articles provide code in C# and VB.NET.
Subscribe to the RSS feeds provided and never miss a new article.





"Bob Powell [MVP]" <bob@_spamkiller_bobpowell.net> wrote in message
news:eWjvgmczEHA.2540@TK2MSFTNGP09.phx.gbl...
> Directly after the g=Graphics.FromImage(topBitmap);
>
> put...
>
> g.Clear(Color.White);
>
> see what happens and let me know.
>
>
> --
> Bob Powell [MVP]
> Visual C#, System.Drawing
>
> Find great Windows Forms articles in Windows Forms Tips and Tricks
> http://www.bobpowell.net/tips...
>
> Answer those GDI+ questions with the GDI+ FAQ
> http://www.bobpowell.net/f...
>
> All new articles provide code in C# and VB.NET.
> Subscribe to the RSS feeds provided and never miss a new article.
>
>
>
>
>
> "Norvin Laudon" <123@abc.com> wrote in message
> news:euefWeczEHA.576@TK2MSFTNGP14.phx.gbl...
> > Hi Bob,
> >
> > Here's the code:
> >
> > <code>
> > Bitmap tmp = Image2D.VisionImage.FromFile("visraw.img");
> > tmp.Save("8bppvisraw.bmp", ImageFormat.Bmp);
> >
> > // the above file 8bppvisraw.bmp loaded in mspaint looks great
> >
> > Bitmap topBitmap = new Bitmap(tmp.Width, tmp.Height,
> > PixelFormat.Format32bppRgb);
> > Graphics g = Graphics.FromImage(topBitmap);
> > g.DrawImage(topBitmap, 0, 0);
> > g.Dispose();
> >
> > topBitmap.Save("32bppvisraw.bmp", ImageFormat.Bmp );
> >
> > // the above file 32bppvisraw.bmp loaded in mspaint looks all black.
> > </code>
> >
> > I've tried commenting out the g.Dispose() method, to no avail
> >
> > Thanks,
> > Norvin
> >
> > "Bob Powell [MVP]" <bob@_spamkiller_bobpowell.net> wrote in message
> > news:eBN9kMczEHA.1308@TK2MSFTNGP09.phx.gbl...
> > > What you describe *should* work.
> > >
> > > As it's not working, please post code.
> > >
> > > --
> > > Bob Powell [MVP]
> > > Visual C#, System.Drawing
> > >
> > > Find great Windows Forms articles in Windows Forms Tips and Tricks
> > > http://www.bobpowell.net/tips...
> > >
> > > Answer those GDI+ questions with the GDI+ FAQ
> > > http://www.bobpowell.net/f...
> > >
> > > All new articles provide code in C# and VB.NET.
> > > Subscribe to the RSS feeds provided and never miss a new article.
> > >
> > >
> > >
> > >
> > >
> > > "Norvin Laudon" <123@abc.com> wrote in message
> > > news:%23DM4rHbzEHA.1292@TK2MSFTNGP10.phx.gbl...
> > > > Hi,
> > > >
> > > > I'm trying to convert an 8bpp indexed greyscale image to a 32bpp
ARGB
> > > image.
> > > >
> > > > The steps I follow:
> > > > 1. open 8bpp image using FromFile
> > > > 2. create a new 32bppARGB image
> > > > 3. get 32bpp Graphics using Graphics.FromImage
> > > > 4. paint the 8bpp image onto the 32bpp using DrawImage.
> > > >
> > > > My problem is the resulting 32bpp image appears all black. I suspect
> > this
> > > is
> > > > a problem with pallettes, since my 8bpp pixels were 0->2^8, and now
> they
> > > > must correspondingly be 0->2^32.
> > > >
> > > > How can I make my 32bpp image appear the same as my original 8bpp?
> > > >
> > > > Thanks,
> > > > Norvin
> > > >
> > > >
> > >
> > >
> >
> >
>
>


RB

11/19/2004 4:04:00 PM

0

"Bob Powell [MVP]" <bob@_spamkiller_bobpowell.net> wrote in message
news:evQeCphzEHA.2040@tk2msftngp13.phx.gbl...
> I just noticed that you are trying to draw the image topBitmap onto
itself!
> you should be drawing "tmp" instead...
>
> g.DrawImage(tmp,0,0);

$#%$!!! Blasted typos!

Sorry for wasting your time, Bob...

Norvin





>
>
> --
> Bob Powell [MVP]
> Visual C#, System.Drawing
>
> Find great Windows Forms articles in Windows Forms Tips and Tricks
> http://www.bobpowell.net/tips...
>
> Answer those GDI+ questions with the GDI+ FAQ
> http://www.bobpowell.net/f...
>
> All new articles provide code in C# and VB.NET.
> Subscribe to the RSS feeds provided and never miss a new article.
>
>
>
>
>
> "Bob Powell [MVP]" <bob@_spamkiller_bobpowell.net> wrote in message
> news:eWjvgmczEHA.2540@TK2MSFTNGP09.phx.gbl...
> > Directly after the g=Graphics.FromImage(topBitmap);
> >
> > put...
> >
> > g.Clear(Color.White);
> >
> > see what happens and let me know.
> >
> >
> > --
> > Bob Powell [MVP]
> > Visual C#, System.Drawing
> >
> > Find great Windows Forms articles in Windows Forms Tips and Tricks
> > http://www.bobpowell.net/tips...
> >
> > Answer those GDI+ questions with the GDI+ FAQ
> > http://www.bobpowell.net/f...
> >
> > All new articles provide code in C# and VB.NET.
> > Subscribe to the RSS feeds provided and never miss a new article.
> >
> >
> >
> >
> >
> > "Norvin Laudon" <123@abc.com> wrote in message
> > news:euefWeczEHA.576@TK2MSFTNGP14.phx.gbl...
> > > Hi Bob,
> > >
> > > Here's the code:
> > >
> > > <code>
> > > Bitmap tmp = Image2D.VisionImage.FromFile("visraw.img");
> > > tmp.Save("8bppvisraw.bmp", ImageFormat.Bmp);
> > >
> > > // the above file 8bppvisraw.bmp loaded in mspaint looks great
> > >
> > > Bitmap topBitmap = new Bitmap(tmp.Width, tmp.Height,
> > > PixelFormat.Format32bppRgb);
> > > Graphics g = Graphics.FromImage(topBitmap);
> > > g.DrawImage(topBitmap, 0, 0);
> > > g.Dispose();
> > >
> > > topBitmap.Save("32bppvisraw.bmp", ImageFormat.Bmp );
> > >
> > > // the above file 32bppvisraw.bmp loaded in mspaint looks all black.
> > > </code>
> > >
> > > I've tried commenting out the g.Dispose() method, to no avail
> > >
> > > Thanks,
> > > Norvin
> > >
> > > "Bob Powell [MVP]" <bob@_spamkiller_bobpowell.net> wrote in message
> > > news:eBN9kMczEHA.1308@TK2MSFTNGP09.phx.gbl...
> > > > What you describe *should* work.
> > > >
> > > > As it's not working, please post code.
> > > >
> > > > --
> > > > Bob Powell [MVP]
> > > > Visual C#, System.Drawing
> > > >
> > > > Find great Windows Forms articles in Windows Forms Tips and Tricks
> > > > http://www.bobpowell.net/tips...
> > > >
> > > > Answer those GDI+ questions with the GDI+ FAQ
> > > > http://www.bobpowell.net/f...
> > > >
> > > > All new articles provide code in C# and VB.NET.
> > > > Subscribe to the RSS feeds provided and never miss a new article.
> > > >
> > > >
> > > >
> > > >
> > > >
> > > > "Norvin Laudon" <123@abc.com> wrote in message
> > > > news:%23DM4rHbzEHA.1292@TK2MSFTNGP10.phx.gbl...
> > > > > Hi,
> > > > >
> > > > > I'm trying to convert an 8bpp indexed greyscale image to a 32bpp
> ARGB
> > > > image.
> > > > >
> > > > > The steps I follow:
> > > > > 1. open 8bpp image using FromFile
> > > > > 2. create a new 32bppARGB image
> > > > > 3. get 32bpp Graphics using Graphics.FromImage
> > > > > 4. paint the 8bpp image onto the 32bpp using DrawImage.
> > > > >
> > > > > My problem is the resulting 32bpp image appears all black. I
suspect
> > > this
> > > > is
> > > > > a problem with pallettes, since my 8bpp pixels were 0->2^8, and
now
> > they
> > > > > must correspondingly be 0->2^32.
> > > > >
> > > > > How can I make my 32bpp image appear the same as my original 8bpp?
> > > > >
> > > > > Thanks,
> > > > > Norvin
> > > > >
> > > > >
> > > >
> > > >
> > >
> > >
> >
> >
>
>