Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Graphics/Bitmap Object: Save graphic as 1bpp

Posted on 2004-08-26
8
Medium Priority
?
1,021 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
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
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 2000 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

This article will show how Aten was able to supply easy management and control for Artear's video walls and wide range display configurations of their newsroom.
If you are a mobile app developer and especially develop hybrid mobile apps then these 4 mistakes you must avoid for hybrid app development to be the more genuine app developer.
An introduction to basic programming syntax in Java by creating a simple program. Viewers can follow the tutorial as they create their first class in Java. Definitions and explanations about each element are given to help prepare viewers for future …
In this fifth video of the Xpdf series, we discuss and demonstrate the PDFdetach utility, which is able to list and, more importantly, extract attachments that are embedded in PDF files. It does this via a command line interface, making it suitable …

782 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