Solved

Graphics/Bitmap Object: Save graphic as 1bpp

Posted on 2004-08-26
8
998 Views
Last Modified: 2013-12-03
My application creates a dynamic graphic (some numbers superimposed on an existing bitmap) and saves the merged result to a bitmap file.  I developed this using a laser printer.  However, my customer will be using it on a thermal receipt printer.  It, unfortunately, will only acept a 1 bit bitmap.

My delima:
My base graphic, is saved as a grayscale file.  I do my text/graphic merge thingy and save it back as a file, but the receipt printer won't print it because it is not 1 bit black and white graphic.

So  I changed the base graphic to a 1 bit bitmap.  When I run my app, an exception get thrown, "A Graphics object cannot be created from an image that has an indexed pixel format..." in other words something les than 16bpp.

Here's the offending code:
               'Build dynamic graphic here
                Const X = 160, Y = 160

                'Graphics Class
                Dim objBitmap = Bitmap.FromFile(regKey.GetValue("backgroundBloominBuck"))
                Dim objGraphics As Graphics = Graphics.FromImage(objBitmap)

                'Text
                Dim moneyFont As New Font("Verdana", 36, FontStyle.Bold)
                Dim drawBrush As New SolidBrush(Color.Black)
                Dim drawFormat As New StringFormat

                drawFormat.FormatFlags = StringFormatFlags.NoWrap
                objGraphics.DrawString(strMoney, moneyFont, drawBrush, 66, 66, drawFormat)
                objBitmap.Save(regKey.GetValue("dynamicBloominBuck"), ImageFormat.Bmp)

If I could leave my orginal graphic as a grayscale, but somehow programmatically convert the resulting output file to a 1 bpp bitmap, then I would be happy.  I would also be just as happy, if I could use Graphics.FromImage using a 1 bpp file. I wish I had run into this problem sooner, because this has to go live Saturday morning.

Someone please have pity on me and enlighten me with thine grand wisdom from I am but a worm.
0
Comment
Question by:carlajasminelewis
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 3
8 Comments
 
LVL 2

Expert Comment

by:dimitry_dimitry
ID: 11910446
Use pixelfomat property.
Bitmap.PixelFormat=PixelFormat.Format1bppIndexed
0
 
LVL 1

Author Comment

by:carlajasminelewis
ID: 11911689
>>Use pixelfomat property.
>>Bitmap.PixelFormat=PixelFormat.Format1bppIndexed

That is a read-only property.
0
 
LVL 5

Expert Comment

by:rsriprac
ID: 11918764
USe the following function:

Bitmap.Clone Method (RectangleF, PixelFormat)

and clone into a new object and then use that object.

-Ram
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 1

Author Comment

by:carlajasminelewis
ID: 11919157
>USe the following function:
>Bitmap.Clone Method (RectangleF, PixelFormat)
>and clone into a new object and then use that object.

Had already tried that too.  As long as the PixelFormat is above 8bpp it will work, but for 8bpp, 4bpp, and 1bpp it throws an "Out of memory" exception.
0
 
LVL 5

Accepted Solution

by:
rsriprac earned 500 total points
ID: 11919199
0
 
LVL 1

Author Comment

by:carlajasminelewis
ID: 11919230
I know I posted this in a general forum, and I'm not that familiar with C#.  I am able determine what the guy is doing here, and I think it may be the shortest, quickest solution that has I have come across.  I'm sure I can make it work just fine.
0
 
LVL 5

Expert Comment

by:rsriprac
ID: 11919308
I'm sure you know this, but for .NET you could cross-compile languages.  Then again if C# isn't you thing, then I guess it worth re-doing it in VB. At the end tho, VB should have most of its equvelents of C#.  (=

-Ram
0
 
LVL 5

Expert Comment

by:rsriprac
ID: 11919312
Good luck with that too.

-Ram
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Entering a date in Microsoft Access can be tricky. A typo can cause month and day to be shuffled, entering the day only causes an error, as does entering, say, day 31 in June. This article shows how an inputmask supported by code can help the user a…
A short article about problems I had with the new location API and permissions in Marshmallow
In this fourth video of the Xpdf series, we discuss and demonstrate the PDFinfo utility, which retrieves the contents of a PDF's Info Dictionary, as well as some other information, including the page count. We show how to isolate the page count in a…

734 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question