Solved

Graphics/Bitmap Object: Save grayscale bitmap as 1-bit black and white

Posted on 2004-08-26
3
471 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
  • 2
3 Comments
 
LVL 8

Expert Comment

by:wguerram
ID: 11915376
Can you send me your image to wguerram@hotmail.com?
0
 
LVL 8

Accepted Solution

by:
wguerram earned 500 total points
ID: 11915685
Check this
http://www.experts-exchange.com/Programming/Programming_Languages/Dot_Net/Q_21096692.html



http://www.visualbasicforum.com/attachment.php?attachmentid=11547

I made changes in order to slice the image after open it, using your function.

And also in the QuantizeImage method i commented the condition which compares the image format with A 24 bits in order to process any image format, i just tried it with your image sample.

i tried and it worked fine.
0
 
LVL 1

Author Comment

by:carlajasminelewis
ID: 11919233
This program has a lot of stuff that I wouldn't need, but I am able to see what parts I can use.  I modified it to save as a one bit, and it works just fine.  Thank you.
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Creating an analog clock UserControl seems fairly straight forward.  It is, after all, essentially just a circle with several lines in it!  Two common approaches for rendering an analog clock typically involve either manually calculating points with…
Parsing a CSV file is a task that we are confronted with regularly, and although there are a vast number of means to do this, as a newbie, the field can be confusing and the tools can seem complex. A simple solution to parsing a customized CSV fi…
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
Hi friends,  in this video  I'll show you how new windows 10 user can learn the using of windows 10. Thank you.

911 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

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now