Solved

Graphics/Bitmap Object: Save graphic as 1bpp

Posted on 2004-08-26
8
987 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
  • 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
Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

 
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

ScreenConnect 6.0 Free Trial

Discover new time-saving features in one game-changing release, ScreenConnect 6.0, based on partner feedback. New features include a redesigned UI, app configurations and chat acknowledgement to improve customer engagement!

Question has a verified solution.

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

Suggested Solutions

This article is meant to give a basic understanding of how to use R Sweave as a way to merge LaTeX and R code seamlessly into one presentable document.
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
With the power of JIRA, there's an unlimited number of ways you can customize it, use it and benefit from it. With that in mind, there's bound to be things that I wasn't able to cover in this course. With this summary we'll look at some places to go…
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…

803 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