|
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
|
|
|
|
|
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
|
|
|
|
|
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
|
|
|
|
|
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.
|
|
|
|
|
|
Your memory is completely fading now, he wants binary, not grayscale.
|
|
|
|
|
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.
|
|
|
|
|
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.
|
|
|
|
|
Hi all,
Is it feasible to have a single DLL project which targets both .NET desktop and .NET CF through different configurations?
TIA!
|
|
|
|
|
I've never done it, but I can see problems with doing so. Since .NET CF is a subset of the full version of the framework, your .DLL would be limited to code, classes, and methods that only work and exist in the CF version of the framework. You'd be using the exact same .DLL for both devices.
So, just as a result from a thought experiment, I'd say no, you can't.
|
|
|
|
|
From Google and experiment, you can, because you can add a reference to a CF DLL to a full .NET project, so it is possible provided you only need to reference stuff from the CF.
|
|
|
|
|
Plan your project with CF only. It will automatically work with full .net.
|
|
|
|
|
That's what I said.
Yeah, you can make a .DLL that will work on both, PROVIDED you don't use anything that won't work in CF. In that case, what's the point? All you're doing is writing code for the least functional framework. You're not actually targeting different frameworks. You're targeting the CF only, and the resulting .DLL just happens to work on the full .NET CLR.
|
|
|
|
|
Dave Kreskowiak wrote: what's the point?
Well, code re-use, ease of maintenance, etc etc etc. If you don't need anything that isn't in the CF then I would say there's a LOT of point, especially if like me you have classes and data structures that you need to use on both.
|
|
|
|
|
If only it was that easy. There's a LOT more to it than just adding a reference and making sure you don't call a method in the class that isn't supported on CF.
I'll leave it up to you to try a quick test and find out. It shouldn't take you but more than 20 minutes to put together a class in the full .NET class library project, then try it in a CF app.
|
|
|
|
|
Is it possible to create a graphics object in the constructor of a normal calss in order to measure a string? Not using a form or control?
Graphics g = ?
m_nodeSize = g.MeasureString(m_name, nodeFont);
Thanx George
|
|
|
|
|
Graphics g = Graphics.FromImage(new Bitmap(80, 80));
Give that a shot.
|
|
|
|
|
Thank you Kevinnicol
That worked great, i was looking for something like that.
public static SizeF MeasureString(string s, Font font)
{
SizeF result;
using (var image = new Bitmap(0, 0))
{
using (var g = Graphics.FromImage(image))
{
result = g.MeasureString(s, font);
}
}
return result;
}
Did see this example but preffer the below:
Graphics g = Graphics.FromImage(new Bitmap(80, 80));
m_nodeSize = g.MeasureString(m_name, nodeFont);
Thanx George
|
|
|
|
|
gwithey wrote: Graphics g = Graphics.FromImage(new Bitmap(80, 80)); m_nodeSize = g.MeasureString(m_name, nodeFont);
Sorry, did you mean to say that you prefer this version? If so, please don't - use the version above it instead as that disposes of managed resources instead."WPF has many lovers. It's a veritable porn star!" - Josh Smith As Braveheart once said, "You can take our freedom but you'll never take our Hobnobs!" - Martin Hughes.
My blog | My articles | MoXAML PowerToys | Onyx
|
|
|
|
|
Message Closed
modified 23-Nov-14 6:41am.
|
|
|
|
|
Thank you stancrm
I saw this however couldnt find a solution as:
Graphics g;
g = this.CreateGraphics();
Only works in a control or on a form. Not in a normal C# class
Thanx George
|
|
|
|