473,387 Members | 1,529 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.

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 4708
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Asif Abbas | last post by:
Hello to all, I've oracle developer 6. My all reports are in character mode and its also print well in Windows 98. But when I print it from Windows NT, its print in bitmap mode instead of...
4
by: melanieab | last post by:
Hi, I'm trying to save a bitmap file so I can print it later. I have Image.Save("sImage.bmp",System.Drawing.Imaging.ImageFormat.Bmp); The file sImage.bmp shows up in the bin\debug folder but...
5
by: Charles A. Lackman | last post by:
Hello, I have created a complete PrintDocument and need to create an image from it. How is this done? e.Graphics.SmoothingMode = Drawing2D.SmoothingMode.HighQuality...
0
by: J L | last post by:
The VBHelper website has very good code for printing an image of the current form. Part of this code is a routine called GetFormImage which returns a bitmap of the form. What I do not know how to...
14
by: eliss.carmine | last post by:
I'm using TCP/IP to send a Bitmap object over Sockets. This is my first time using C# at all so I don't know if this is the "right" way to do it. I've already found out several times the way I was...
1
by: icepick72 | last post by:
On an academic note, I want to copy a Graphic to an Image (Bitmap). I have the Graphic object but not the origin image from which it originates; this is because I'm overriding the PrintDocument...
4
by: david | last post by:
hello, I have a client/server application. the server capture picture from webcam and send it to every client connected to it.the network part works good and the capture from webcam too. I...
7
by: littleIO | last post by:
Hi, I'm stuck on a very simple problem and just cant seem to get around it, little help would be much appreciated. I have a server which listens, receives calls, processes them and sends back the...
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:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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
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,...

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.