473,595 Members | 2,468 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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(m s, System.Drawing. Imaging.ImageFo rmat.Gif);

byte[] printChart = ms.GetBuffer();

TcpClient client = new TcpClient("10.0 .0.18", 9100);

NetworkStream printStream = client.GetStrea m();

printStream.Wri te(printChart, 0, printChart.Leng th);

printStream.Flu sh();

printStream.Clo se();
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 4733
mo********@hotm ail.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(m s, System.Drawing. Imaging.ImageFo rmat.Gif);
byte[] printChart = ms.GetBuffer();
TcpClient client = new TcpClient("10.0 .0.18", 9100);
NetworkStream printStream = client.GetStrea m();
printStream.Wri te(printChart, 0, printChart.Leng th);
printStream.Flu sh();
printStream.Clo se();

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********@hot mail.com> wrote in message
news:11******** *************@g 43g2000cwa.goog legroups.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(m s, System.Drawing. Imaging.ImageFo rmat.Gif);
|
| byte[] printChart = ms.GetBuffer();
|
| TcpClient client = new TcpClient("10.0 .0.18", 9100);
|
| NetworkStream printStream = client.GetStrea m();
|
| printStream.Wri te(printChart, 0, printChart.Leng th);
|
| printStream.Flu sh();
|
| printStream.Clo se();
|
|
| 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
2733
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 Character mode. Its running well before but for last few days its starting to print in Bitmap. I have tried to reinstall drivers but problem still exist. I have checked character mode printing from Foxpro for DOS in Win NT but it print well. The...
4
2284
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 when I try to print it (or open it), it's completely black. I know Image is the correct picture because when I immediately print it, it works. What am I doing wrong? Thanks! Melanie
5
27143
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 e.Graphics.DrawString(Line1.Text, FontLine1, TheBrush, Thelocation1, 390 + yPos, AStringFormat) e.Graphics.DrawString(Line2.Text, FontLine2, TheBrush, Thelocation2, TheHeight1 + (390 + yPos))
0
927
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 do is to scale this bit map to fit on the printed page (in either Landscape or Portrait orientation). So the question is, given a bitmap image (not in a picture box) how to scale it based on the printer settings? Any help is appreciated. TIA,
14
11881
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 doing something was really inefficient and could reduce 10 lines of code with 2, etc. For reading, I am using a TcpClient and I call NetworkStream ns = client.GetStream(); to get a stream stream.Read(buffer, 0, buffer.Length);
1
3481
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 class OnPagePrint method which only provides me an e.Graphic (see code sample below). The FCL doesn't seem to natively support Graphic =(Image)Bitmap. I have tried BitBlt workaround in the source code to copy printer e.Graphic into the bmp...
4
12062
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 associate an event when a capture is done, then every frame of the webcam should be sent to the client. but I cannot find a way to send bitmap throught network, of course I found many method from internet, some doen't work, some work but it's never...
7
4261
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 results to clients. The code below makes the client application not to respond. Client can send data but is stuck in the process of waiting information back from the server. Any ideas?
7
8192
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 Printer in this equation as I am not sure I am getting the correct "raw" image from the file. However, when I print what I think is the raw data, I get the image size, but the information within the image looks nothing like it should be, and...
0
8261
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8379
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8019
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
6674
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5418
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
3873
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
3911
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1490
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
1223
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.