Bitmap Image to Binary Image (Black & White) [modified]
-
Hello, I need to get each pixel (as 1's and 0's) and package them as bytes. For example, I have a bitmap with a resolution of 64x64 pixels and convert it into an array of 512 bytes. Sorry for the bad english EDIT: I did forgot something. The solution for my problem was in this article[^].
modified on Saturday, April 24, 2010 10:12 AM
-
Hello, I need to get each pixel (as 1's and 0's) and package them as bytes. For example, I have a bitmap with a resolution of 64x64 pixels and convert it into an array of 512 bytes. Sorry for the bad english EDIT: I did forgot something. The solution for my problem was in this article[^].
modified on Saturday, April 24, 2010 10:12 AM
If it is that small, then why not just use Bitmap.GetPixel? If you are doing a lot of them, or they are bigger you may have to directly access the bitmap bytes to save processing time.
You should never use standby on an elephant. It always crashes when you lift the ears. - Mark Wallace C/C++ (I dont see a huge difference between them, and the 'benefits' of C++ are questionable, who needs inheritance when you have copy and paste) - fat_boy
-
If it is that small, then why not just use Bitmap.GetPixel? If you are doing a lot of them, or they are bigger you may have to directly access the bitmap bytes to save processing time.
You should never use standby on an elephant. It always crashes when you lift the ears. - Mark Wallace C/C++ (I dont see a huge difference between them, and the 'benefits' of C++ are questionable, who needs inheritance when you have copy and paste) - fat_boy
How to access directly to the bytes of the bitmap? Through the Bitmap.LockBits() method? The purpose of this conversion is to create binary images for use in programs for the Casio fx-9860G (graphic calculator)
-
How to access directly to the bytes of the bitmap? Through the Bitmap.LockBits() method? The purpose of this conversion is to create binary images for use in programs for the Casio fx-9860G (graphic calculator)
Yes. If they are black and white, then specify the System.Drawing.Imaging.PixelFormat.Format1bppIndexed mode.
You should never use standby on an elephant. It always crashes when you lift the ears. - Mark Wallace C/C++ (I dont see a huge difference between them, and the 'benefits' of C++ are questionable, who needs inheritance when you have copy and paste) - fat_boy
-
Hello, I need to get each pixel (as 1's and 0's) and package them as bytes. For example, I have a bitmap with a resolution of 64x64 pixels and convert it into an array of 512 bytes. Sorry for the bad english EDIT: I did forgot something. The solution for my problem was in this article[^].
modified on Saturday, April 24, 2010 10:12 AM
I recall that someone has an article somewhere that has instructions that can do this very quickly. But I can't seem to recollect who that was. Painless yet unsafe grayscale conversion in C#[^] BTW, your English is fine.
Need custom software developed? I do custom programming based primarily on MS tools with an emphasis on C# development and consulting. A man said to the universe: "Sir I exist!" "However," replied the universe, "The fact has not created in me A sense of obligation." --Stephen Crane
-
I recall that someone has an article somewhere that has instructions that can do this very quickly. But I can't seem to recollect who that was. Painless yet unsafe grayscale conversion in C#[^] BTW, your English is fine.
Need custom software developed? I do custom programming based primarily on MS tools with an emphasis on C# development and consulting. A man said to the universe: "Sir I exist!" "However," replied the universe, "The fact has not created in me A sense of obligation." --Stephen Crane
Your memory is completely fading now, he wants binary, not grayscale. :-D
Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles]
I only read code that is properly formatted, adding PRE tags is the easiest way to obtain that.
-
Your memory is completely fading now, he wants binary, not grayscale. :-D
Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles]
I only read code that is properly formatted, adding PRE tags is the easiest way to obtain that.
My memory may be failing but last time I checked that article provided a fast way to get all pixel information as well as write out said pixel information. The actual grayscale conversion is trivial when compared to the rest of the code. And if I recall the question, it was how can I quickly ... which the article addresses. As for binary image that is an exercise left to the reader. But then again, if you keep the gray scale logic you can then apply your threshold statement and get the binary result as well.
Need custom software developed? I do custom programming based primarily on MS tools with an emphasis on C# development and consulting. A man said to the universe: "Sir I exist!" "However," replied the universe, "The fact has not created in me A sense of obligation." --Stephen Crane
-
My memory may be failing but last time I checked that article provided a fast way to get all pixel information as well as write out said pixel information. The actual grayscale conversion is trivial when compared to the rest of the code. And if I recall the question, it was how can I quickly ... which the article addresses. As for binary image that is an exercise left to the reader. But then again, if you keep the gray scale logic you can then apply your threshold statement and get the binary result as well.
Need custom software developed? I do custom programming based primarily on MS tools with an emphasis on C# development and consulting. A man said to the universe: "Sir I exist!" "However," replied the universe, "The fact has not created in me A sense of obligation." --Stephen Crane
Of course. BTW: he may be needing a dynamic threshold to get acceptable results on more difficult images, e.g. when luminance is varrying wildly. :)
Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles]
I only read code that is properly formatted, adding PRE tags is the easiest way to obtain that.
-
Yes. If they are black and white, then specify the System.Drawing.Imaging.PixelFormat.Format1bppIndexed mode.
You should never use standby on an elephant. It always crashes when you lift the ears. - Mark Wallace C/C++ (I dont see a huge difference between them, and the 'benefits' of C++ are questionable, who needs inheritance when you have copy and paste) - fat_boy
See the link below. It is a test image which I want to convert to binary image I forgot to mention something. The binary image is to be used in C++ source files. http://img176.imageshack.us/img176/744/boxm.png[^] Here is the expected result:
unsigned char box[27] = {
0xf8,0xff,0x3,
0x6,0x0,0xc,
0x1,0x0,0x10,
0x1,0x0,0x10,
0x1,0x0,0x10,
0x1,0x0,0x10,
0x1,0x0,0x10,
0x1,0x0,0x10,
0x1,0x0,0x10 }; -
See the link below. It is a test image which I want to convert to binary image I forgot to mention something. The binary image is to be used in C++ source files. http://img176.imageshack.us/img176/744/boxm.png[^] Here is the expected result:
unsigned char box[27] = {
0xf8,0xff,0x3,
0x6,0x0,0xc,
0x1,0x0,0x10,
0x1,0x0,0x10,
0x1,0x0,0x10,
0x1,0x0,0x10,
0x1,0x0,0x10,
0x1,0x0,0x10,
0x1,0x0,0x10 };ant-damage wrote:
The binary image is to be used in C++ source files.
Does this mean that you want to use this as an image in your application - for a button or other control? Because if so, you don't have to convert it to binary.
You should never use standby on an elephant. It always crashes when you lift the ears. - Mark Wallace C/C++ (I dont see a huge difference between them, and the 'benefits' of C++ are questionable, who needs inheritance when you have copy and paste) - fat_boy
-
ant-damage wrote:
The binary image is to be used in C++ source files.
Does this mean that you want to use this as an image in your application - for a button or other control? Because if so, you don't have to convert it to binary.
You should never use standby on an elephant. It always crashes when you lift the ears. - Mark Wallace C/C++ (I dont see a huge difference between them, and the 'benefits' of C++ are questionable, who needs inheritance when you have copy and paste) - fat_boy
I want to use it as a sprite for my CASIO fx-9860G calculator. It is to be used in add-ins.
-
I want to use it as a sprite for my CASIO fx-9860G calculator. It is to be used in add-ins.
I've now created a class that can convert bitmaps (*.bmp; *.png) to binary images (0xFF 0x89 0x78 0x65), but now my problem is that some bitmaps have grey, and to display it on a B&W LCD I need to emulate the grey effect by using double-buffering (I've mastered the double-buffering issue). Both buffers are displayed to the screen with an especial delay, to created the grey effect.