473,387 Members | 1,497 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

C# Bitmap to ByteArray representation

1
Hi there,

I wanted to change the monochrome bitmap to byte array and send the pixel data to the serial thermal printer.

When i convert the bitmap to byte array, the first two byte i get is 13780 instead of 19778 (representation of BM as per bitmap specs). I used the following code as reference:
ImageData = ConvertImageToByteArray(bmp,System.Drawing.Imaging .ImageFormat.Png);

private static byte[] ConvertImageToByteArray(System.Drawing.Image imageToConvert,ImageFormat formatOfImage)
{
byte[] Ret;
using (MemoryStream ms = new MemoryStream())
{
imageToConvert.Save(ms,formatOfImage);
Ret = ms.ToArray();
}
return Ret;
}


if i call the above function as below
ImageData = ConvertImageToByteArray(bmp,System.Drawing.Imaging .ImageFormat.<b>Bmp</b>);
then all the byteArray is filled with 0;

What am i doing wrong? Or is there any other approach for doing this? Any solution and suggestion will be appreciated.
Nov 27 '06 #1
0 5844

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: Swarup | last post by:
I am reading a file (txt, xml, gif, ico, bmp etc) byte by byte and filling it into a byte arry. Now i have to convert it into a string to store it in the database. I use...
4
by: Unknown | last post by:
Does anyone know how I would change the Hue of a bitmap I have? I tried looking for a class that would help me, but all I can find is methods that retrieve Hue values and not change them..
4
by: vbdotnetmania | last post by:
I have the following snippet of code with bm being a succesfully stored bitmap (not including all the code just the relevant bits) Dim g As Graphics Dim g2 As Graphics Dim bm As Bitmap Dim bm2...
1
by: vbdotnetmania | last post by:
I have a memorystream of a bitmap, I want to send this over the network to a client app so it can receive the bitmap, I am dabbling with sockets and tcpclient's and ahve got a connection going but...
6
by: rlcavebmg | last post by:
I am new to Web Services and .NET development, and I have a question. I am writing a service that will create a bitmap image and return it to the client. First, I wrote a method that looked like...
1
by: gijamie911 | last post by:
int nBytes = 256; byte ByteArray = new byte; int nBytesRead = inputStream.Read(ByteArray, 0 , nBytes); recorderID = ""; for (int i...
8
by: Frank | last post by:
Given a bitmap I want to write a Icon file using it. I believe I can do it except for writing the bits of the image. Can you tell me how to get the bits into a ByteArray Thanks
11
by: Icemokka | last post by:
Hi, I'm need to upload a big file ( 600Mb+ ) to a BLOB field in MSSQL 2005. My code looks like this : fs = New FileStream(sFilePath, FileMode.Open) Dim ByteArray(fs.Length) As Byte...
7
by: RB0135 | last post by:
Hi All, I have some Windows BMP, 1BPP, monochrome files that I need to get the raw data from to load a graphics buffer on a Roll Printer (which I know can be done). Lets forget about the Roll...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.