Showing a Picture

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I am trying to show a picture in a form but using visual studios C# I am getting a error everytime I want to deploy my program. I cannot find the reason

Assembly assembly = Assembly.GetExecutingAssembly()
Image image = Image.FromStream(assembly.GetManifestResourceStream("picture.jpg"))

the debugger holds on the second line and tells me that he has no valid value for the stream. So my understanding is that he cannot find the file picture.jpg.
I have been trying all kinds of different things to get the file picture.jpg embedded in the programma but I have no luck.
Can someone be so kind to help me out with this

Thanks Bardo
 
If you are using VS then the picture.jpg needs to be part of the project. It
should appear in the project as an embedded resource. If it is in a
sub-directory, then sub-directories act as namespaces for embedded resources and
so your stream might be named incorrectly in the assembly manifest. A quick
ILDasm of your assembly and looking at the manifest portion will show all of
your embedded resources.

If you are trying to include the item in a normal csc command line compilation
then look at the /resource: option.


--
Justin Rogers
DigiTec Web Consultants, LLC.
Blog: http://weblogs.asp.net/justin_rogers

Bardo said:
I am trying to show a picture in a form but using visual studios C# I am
getting a error everytime I want to deploy my program. I cannot find the reason.
Assembly assembly = Assembly.GetExecutingAssembly();
Image image = Image.FromStream(assembly.GetManifestResourceStream("picture.jpg"));

the debugger holds on the second line and tells me that he has no valid value
for the stream. So my understanding is that he cannot find the file picture.jpg.
I have been trying all kinds of different things to get the file picture.jpg
embedded in the programma but I have no luck.
 
Hi Justin

I am new to C# and I am still trying to learn the language. So I am sorry to say I am not able to follow you fully (yet
I listed my program below so you can see what I am missing. I have tried different approaches. 1) I added a jpg image thru right click on my project and then add existing item. No luck. I made a resource file using the resource file maker (the one that is in the samples directory in the Framework SDK, also no luck. The debugger keeps stopping at the line I marked with ==>. No matter what I try it just doesnt seem to work. Very frustrating

I hope you can help me out here

Bard


using System
using System.Drawing
using System.Collections
using System.ComponentModel
using System.Windows.Forms
using System.Data
using System.Reflection

public class Programma: System.Windows.Forms.Form

private System.Drawing.Image buffer

private System.Drawing.Graphics display

public Programma()
InitializeComponent()


private void InitializeComponent()
SetStyle(System.Windows.Forms.ControlStyles.UserPaint, true)
SetStyle(System.Windows.Forms.ControlStyles.AllPaintingInWmPaint, true)
SetStyle(System.Windows.Forms.ControlStyles.DoubleBuffer, true)
ClientSize = new Size(392, 60)
buffer = new System.Drawing.Bitmap(392, 60)
display = System.Drawing.Graphics.FromImage(buffer)
new System.Threading.Thread(ne
System.Threading.ThreadStart(Animation_Start)).Start()


private void Animation_Start()
Assembly assembly = Assembly.GetExecutingAssembly()
==> Image image = Image.FromStream(assembly.GetManifestResourceStream("Picture.gif"))
Bitmap bitmap = new Bitmap(56, 60)
Graphics graphics = Graphics.FromImage(bitmap)
graphics.DrawImage(image, -168, 0)
display.DrawImage(bitmap, 0, 0)
Refresh()


protected override void OnPaint(System.Windows.Forms.PaintEventArgs e)
System.Drawing.Graphics g = e.Graphics
g.DrawImage(buffer, 0, 0)
base.OnPaint(e)


public static void Main()
System.Windows.Forms.Application.Run(new Programma())
System.Environment.Exit(0)
 
Back
Top