473,320 Members | 1,724 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,320 software developers and data experts.

Problems printing text on top of img

Hi,

I'm desperately trying to print a string on top of an image, but for
whatever reason the images allways stays on top of my canvas! Is there
some trick how to implement things?

I call

ev.graphics.drawimage(img, rect);
ev.graphics.drawstring("mystring", ..., rect, ...);

I can't really deal with this behavoir....
Martin
Nov 16 '05 #1
6 2726
APG
Hi Martin,

The code snipped you refered in your post should work fine. Just that we
need to ensure the printing happens in the right order, like the image
first and the text next in our case.

Try the following code in a sample form button click event, with a valid
image bitmap. The text should appear on top of the image.

private void button1_Click(object sender, System.EventArgs e)
{
Graphics g = CreateGraphics();
Rectangle rect = new Rectangle(10, 10, 100, 100);
Bitmap b= new Bitmap(@"SampleImage.jpg");
g.DrawImage(b, rect);
g.DrawString("TEXT", new Font("Impact", 20), new SolidBrush(Color.Red),
new Point(10, 10));
}

I doubt if some other event causes invalidation of the canvas and the
text is printed before the image, just a thought. Have a relook at the
paint event of the canvas.

HTH,
APG.

mphanke wrote:
Hi,

I'm desperately trying to print a string on top of an image, but for
whatever reason the images allways stays on top of my canvas! Is there
some trick how to implement things?

I call

ev.graphics.drawimage(img, rect);
ev.graphics.drawstring("mystring", ..., rect, ...);

I can't really deal with this behavoir....
Martin

Nov 16 '05 #2
Hi,

this is exactly what I do! Just one thing is different:

Rectangle rect = new Rectangle(10, 10, 100, 100);
Rectangle rectText = new Rectangle(40, 40, 300, 10);
StringFormat sf = new Stringformat();
Bitmap b= new Bitmap(@"SampleImage.jpg");
g.DrawImage(b, rect);
g.DrawString("TEXT", new Font("Impact", 20), new SolidBrush(Color.Red),
rectText, sf);

This really confuses me! I just don't get the point what happens there.
It is the same with your code....

Could that be some type of a driver problem??
Using latest HP driver for 5100 series, but the same thing happens on
our Lexmark ColorLaser. So I excluded this posibility!

Regards,

Martin

APG wrote:
Hi Martin,

The code snipped you refered in your post should work fine. Just that we
need to ensure the printing happens in the right order, like the image
first and the text next in our case.

Try the following code in a sample form button click event, with a valid
image bitmap. The text should appear on top of the image.

private void button1_Click(object sender, System.EventArgs e)
{
Graphics g = CreateGraphics();
Rectangle rect = new Rectangle(10, 10, 100, 100);
Bitmap b= new Bitmap(@"SampleImage.jpg");
g.DrawImage(b, rect);
g.DrawString("TEXT", new Font("Impact", 20), new
SolidBrush(Color.Red), new Point(10, 10));
}

I doubt if some other event causes invalidation of the canvas and the
text is printed before the image, just a thought. Have a relook at the
paint event of the canvas.

HTH,
APG.

mphanke wrote:
Hi,

I'm desperately trying to print a string on top of an image, but for
whatever reason the images allways stays on top of my canvas! Is there
some trick how to implement things?

I call

ev.graphics.drawimage(img, rect);
ev.graphics.drawstring("mystring", ..., rect, ...);

I can't really deal with this behavoir....
Martin

Nov 16 '05 #3
Hi Martin,

Based on my understanding, you want to use GDI+ to draw image, then print
them out.

I have tried your code, I think there is not much problem about it. Only
that I think the height you set for your rectText is too small, you'd
better set it to 100, not 10.(Or you can only display part of the text)

How do you print your drawing picture? I think you may use PrintDocument
class. On machine, I have used PrintDocument with your code snippet to
print out the image, the text really on top of the picture. So I do not
know why your problem arise.

I think you may first try to use PrintPreviewDialog to preview the
pre-print document, if the print preview works well, I think the problem
should be your printer. The code snippet like this:

PrintDocument pd=null;
private void button1_Click(object sender, System.EventArgs e)
{
try
{

Font printFont = new Font("Arial", 10);
pd = new PrintDocument();
pd.PrintPage += new PrintPageEventHandler(this.pd_PrintPage);
}
catch(Exception ex)
{
MessageBox.Show(ex.Message);
}
}

private void pd_PrintPage(object sender, PrintPageEventArgs ev)
{
Rectangle rect = new Rectangle(10, 10, 100, 100);
Rectangle rectText = new Rectangle(40, 40, 300, 100);
StringFormat sf = new StringFormat();
Bitmap b= new Bitmap("D:\\1_p1.JPG");
ev.Graphics.DrawImage(b, rect);
ev.Graphics.DrawString("TEXT", new Font("Impact", 20), new
SolidBrush(Color.Red), rectText, sf);
}

private void button2_Click(object sender, System.EventArgs e)
{
PrintPreviewDialog dlg = new PrintPreviewDialog() ;
dlg.Document=pd;
dlg.Show();
}

Thank you for your patience and cooperation. If you have any questions or
concerns, please feel free to post it in the group. I am standing by to be
of assistance.

Best regards,
Jeffrey Tan
Microsoft Online Partner Support
Get Secure! - www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.

Nov 16 '05 #4
Hi Jeffrey,

this is what bothers me, I don't get the point! In the preview the image
is above the text and it stays there. I guess I have to check my
calculations somewhat more close...

BTW.:The text I use is Arial 5 pt, so 10 is enough for displaying it.

Thanks for your help so far,

Martin
Nov 16 '05 #5
Hi Martin,

Oh, I also think it is strange. I suggest you save your drawed memory
bitmap to the disk to see if the problem also existed.

If you still can not figure out the problem, can you find a way to
reproduce this problem? Thanks

Best regards,
Jeffrey Tan
Microsoft Online Partner Support
Get Secure! - www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.

Nov 16 '05 #6
Hi Martin,

Is your problem resolved? Do you still have concern on this issue?

Please feel free to feedback. Thanks

Best regards,
Jeffrey Tan
Microsoft Online Partner Support
Get Secure! - www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.

Nov 16 '05 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: x | last post by:
Hi, I have a plain (Html)text page, but whenever I print out the html page the text doesn't wrap on the printed copy. It just runs off the page... Anybody have an idea as to what I could do...
0
by: David Lindgren | last post by:
Hello! I am using a thirdparty gridcontrol which has a bug in it. It consists of that when setting a column to be right aligned it doesn't work as it should. The column gets rightaligned, but...
0
by: Nigel | last post by:
I successfully create a .NET Component (Visual Basic .NET) that would print, unfortunately when used within a web browser it appears that .NET security doesn't allow you to run code that interacts...
4
by: Tracey | last post by:
Hey folks, I have an ASP.NET web app that's working just fine, but a small percentage have two printing problems that don't happen to the vast majority of users. These problems are listed below...
1
by: Chad Dittmer via .NET 247 | last post by:
I'm having problems inserting into Sql 2000 using SqlHelper.ExecuteScalar. When it inserts, it only takes the first character from the string?? Any help would be appreciated. Here is the code and...
3
by: Alejandra Parra | last post by:
In my code, I print a dataSet ' get grid's PrintDocument object Dim pd As System.Drawing.Printing.PrintDocument pd = flexgrid.PrintParameters.PrintDocument() ' set up the page (landscape, 1.5"...
1
by: hamil | last post by:
I am trying to print a graphic file (tif) and also use the PrintPreview control, the PageSetup control, and the Print dialog control. The code attached is a concatination of two examples taken out...
2
by: Teemu | last post by:
I have an application created with VB6 and now I'm converting it to VB 2005. Conversion is not so simple because printing is so much different. In my app I have Timer-component, which is creates...
1
by: William Cruz | last post by:
This piece of code prints out a image that I have placed on a picturebox. It currently prints it @ the top left hand side of the page. I want to know how I can control where in the page this image...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

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.