Click here to Skip to main content
15,881,882 members
Please Sign up or sign in to vote.
1.80/5 (2 votes)
See more:
I was using a code, to draw the image on the screen. But I am not able to figure out why it is not being drawn on the screen. I am using the following code,

C#
Bitmap bmp = new Bitmap("10630606_727195303982470_1655175415434850365_o.jpg");
Graphics gr = Graphics.FromImage(bmp);
gr.DrawImage(bmp, 60, 30);


..if I add a new line at the end of the code, as

C#
bmp.Save("<location>");


..then I can still find out the file created at that location. Which means that the code was working find and the image was loaded. But the graphics aren't drawn on the screen. I am having a WPF application of 900x700 size but the image or any thing is not found anywhere on the screen in that application.

Any help will be appreciated.
Posted
Comments
Sergey Alexandrovich Kryukov 22-Sep-14 12:42pm    
Afzaal,

In the code you show, you don't do any attempt to show anything on screen. Besides, it does not look like WPF code. Yes, you can use System.Drawing.Graphics with WPF, but this is irrelevant to your question. Even if you tried to draw some image on screen, we cannot see this code; so how anyone can help you based on your information?

—SA
Afzaal Ahmad Zeeshan 22-Sep-14 14:20pm    
Yes Sergey, you're right. This is a part of Windows Forms and from System.Drawing.dll. I am sorry, I forgot to mention that part. However, the code that I am using is from the MSDN documentation, http://msdn.microsoft.com/en-us/library/42807xh1(v=vs.110).aspx you can see that they're having a commentary label "// Draw image to screen." So, I thought this might be a draw image on screen and show in the application type of thing. I guess, I am wrong?
Sergey Alexandrovich Kryukov 22-Sep-14 14:25pm    
Thank you. You still just need to prepare some code sample, as small as possible but comprehensive, with the steps to reproduce the problem.
—SA
ZurdoDev 22-Sep-14 14:17pm    
You need to reply to comment so that the user is notified.
Afzaal Ahmad Zeeshan 22-Sep-14 14:21pm    
Oh yeah, I forgot that. Thanks brother.

1 solution

Please see my comments to the question. I did not see your code; there can be too many ways to screw up things. You did not show any code where you tried to draw anything on screen; and drawing on a bitmap you show is pretty much irrelevant.

However, first check the problems which looked similar and my past answers:
What kind of playful method is Paint? (DataGridViewImageCell.Paint(...))[^],
capture the drawing on a panel[^],
Drawing Lines between mdi child forms[^],
How to speed up my vb.net application?[^],
Zoom image in C# .net mouse wheel[^].

Chances are, you can get a clue from those answers.

—SA
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900