471,336 Members | 1,294 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

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

Bitmap printing through a NetworkStream

I have a bitmap I want to print on a network printer using a network
stream.
This is the code I'm currently using:

chartBmp.Save(ms, System.Drawing.Imaging.ImageFormat.Gif);

byte[] printChart = ms.GetBuffer();

TcpClient client = new TcpClient("10.0.0.18", 9100);

NetworkStream printStream = client.GetStream();

printStream.Write(printChart, 0, printChart.Length);

printStream.Flush();

printStream.Close();
This method is working fine when I use text, but printing a bitmap will
give me one line with all kinds of characters.
I read about having to use special characters to let the printer know
it has to print a bitmap. Is that something I have to set in here, or
am I missing something else?

Feb 3 '06 #1
2 4534
mo********@hotmail.com wrote:
I have a bitmap I want to print on a network printer using a network
stream.
This is the code I'm currently using:

chartBmp.Save(ms, System.Drawing.Imaging.ImageFormat.Gif);
byte[] printChart = ms.GetBuffer();
TcpClient client = new TcpClient("10.0.0.18", 9100);
NetworkStream printStream = client.GetStream();
printStream.Write(printChart, 0, printChart.Length);
printStream.Flush();
printStream.Close();

This method is working fine when I use text, but printing a bitmap will
give me one line with all kinds of characters.
I read about having to use special characters to let the printer know
it has to print a bitmap. Is that something I have to set in here, or
am I missing something else?


That will depend on the printer, unfortunately. You should probably use
the normal .NET printing services.

Note, however, that your use of MemoryStream is incorrect. Calling
GetBuffer() will give you "spare" bytes at the end. You should either
use ToArray(), or use GetBuffer() in conjunction with the Length
property to work out how much to actually use.

Jon

Feb 3 '06 #2

<mo********@hotmail.com> wrote in message
news:11*********************@g43g2000cwa.googlegro ups.com...
|I have a bitmap I want to print on a network printer using a network
| stream.
| This is the code I'm currently using:
|
| chartBmp.Save(ms, System.Drawing.Imaging.ImageFormat.Gif);
|
| byte[] printChart = ms.GetBuffer();
|
| TcpClient client = new TcpClient("10.0.0.18", 9100);
|
| NetworkStream printStream = client.GetStream();
|
| printStream.Write(printChart, 0, printChart.Length);
|
| printStream.Flush();
|
| printStream.Close();
|
|
| This method is working fine when I use text, but printing a bitmap will
| give me one line with all kinds of characters.
| I read about having to use special characters to let the printer know
| it has to print a bitmap. Is that something I have to set in here, or
| am I missing something else?
|

That's the task of the printer driver for that kind of printer. Why are you
passing data directly to a printer server without using the drive anyway.
Maybe that it works for simple ASCII streams but anything else will fail to
print.

Willy.

Feb 3 '06 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

reply views Thread by Asif Abbas | last post: by
4 posts views Thread by melanieab | last post: by
5 posts views Thread by Charles A. Lackman | last post: by
1 post views Thread by icepick72 | last post: by
4 posts views Thread by david | last post: by
7 posts views Thread by RB0135 | last post: by

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.