在webservice的.cs中:
[WebMethod]
public Byte[] getIamge(string filname)
{
System.IO.MemoryStream stream=new System.IO.MemoryStream();
System.Drawing.Bitmap myBitmap;
try
{
myBitmap= new System.Drawing.Bitmap(filname);
myBitmap.Save(stream,System.Drawing.Imaging.ImageFormat.Gif );
return stream.ToArray();
}
catch
{
return null;
}
}
在winform的.cs中:
private void button1_Click(object sender, System.EventArgs e)
{
localhost.Service1 service=new localhost.Service1();
Byte[] bytes;
System.IO .MemoryStream stream;
Bitmap image;
service=new localhost.Service1();
//bytes=service.getIamge(@"E:\"+textBox1.Text);
// textBox1.Text=@"E:\"+textBox1.Text;
string filename;
bytes=service.getIamge(filename);
//注意图象文件的路径、及完整的文件名
if(bytes!=null)
{
stream=new System.IO.MemoryStream(bytes);
image=new Bitmap(stream);
pictureBox1.Image=image; //SizeMode设置为StretchImage
}
else MessageBox.Show ("NO image return");
}
[WebMethod]
public Byte[] getIamge(string filname)
{
System.IO.MemoryStream stream=new System.IO.MemoryStream();
System.Drawing.Bitmap myBitmap;
try
{
myBitmap= new System.Drawing.Bitmap(filname);
myBitmap.Save(stream,System.Drawing.Imaging.ImageFormat.Gif );
return stream.ToArray();
}
catch
{
return null;
}
}
在winform的.cs中:
private void button1_Click(object sender, System.EventArgs e)
{
localhost.Service1 service=new localhost.Service1();
Byte[] bytes;
System.IO .MemoryStream stream;
Bitmap image;
service=new localhost.Service1();
//bytes=service.getIamge(@"E:\"+textBox1.Text);
// textBox1.Text=@"E:\"+textBox1.Text;
string filename;
bytes=service.getIamge(filename);
//注意图象文件的路径、及完整的文件名
if(bytes!=null)
{
stream=new System.IO.MemoryStream(bytes);
image=new Bitmap(stream);
pictureBox1.Image=image; //SizeMode设置为StretchImage
}
else MessageBox.Show ("NO image return");
}