c#使用Web服务返回图片数据的方法
来源:互联网 发布:java项目流程图工具 编辑:程序博客网 时间:2024/06/05 09:48
c#使用Web服务返回图片数据的方法
----------------------------------------------------------------------------------------------------------------------
在Webservice服务端 使用内存流对象保存图片的字节流数据, 返回byte[]
----------------------------------------------------------------------------------------------------------------------
http://hi.baidu.com/jordan51341/item/b0f6c10b85fd57c12f4c6ba3
在Webservice服务端 使用内存流对象保存图片的字节流数据, 返回byte[]
----------------------------------------------------------------------------------------------------------------------
http://hi.baidu.com/jordan51341/item/b0f6c10b85fd57c12f4c6ba3
using System;
using System.Web;
using System.Web.Services;
using System.Web.Services.Protocols;
[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
public class Service : System.Web.Services.WebService
{
public Service () {
//如果使用设计的组件,请取消注释以下行
//InitializeComponent();
}
[WebMethod]
public byte[] GetPicture()
{
System.IO.MemoryStream m=new System.IO.MemoryStream ();
System.Drawing.Bitmap bp = new System.Drawing.Bitmap(@"d:\1.gif");
bp.Save(m, System.Drawing.Imaging.ImageFormat.Gif);
return m.GetBuffer ();
}
}
------------------------------------------------------------------------------------------------------------------------
在客户端将图片的byte[]类型数据转换为bitmap 再显示出来
首先添加webservice的web引用
使用picturebox显示从web服务返回的图片数据
------------------------------------------------------------------------------------------------------------------------
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
namespace test
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
testweb.Service s = new test.testweb.Service();
byte[] buf = s.GetPicture();
System.IO.MemoryStream m = new System.IO.MemoryStream(buf);
Bitmap b = new Bitmap(m);
pictureBox1.Image = b;
}
}
}
using System.Web;
using System.Web.Services;
using System.Web.Services.Protocols;
[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
public class Service : System.Web.Services.WebService
{
public Service () {
//如果使用设计的组件,请取消注释以下行
//InitializeComponent();
}
[WebMethod]
public byte[] GetPicture()
{
System.IO.MemoryStream m=new System.IO.MemoryStream ();
System.Drawing.Bitmap bp = new System.Drawing.Bitmap(@"d:\1.gif");
bp.Save(m, System.Drawing.Imaging.ImageFormat.Gif);
return m.GetBuffer ();
}
}
------------------------------------------------------------------------------------------------------------------------
在客户端将图片的byte[]类型数据转换为bitmap 再显示出来
首先添加webservice的web引用
使用picturebox显示从web服务返回的图片数据
------------------------------------------------------------------------------------------------------------------------
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
namespace test
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
testweb.Service s = new test.testweb.Service();
byte[] buf = s.GetPicture();
System.IO.MemoryStream m = new System.IO.MemoryStream(buf);
Bitmap b = new Bitmap(m);
pictureBox1.Image = b;
}
}
}
0 0
- c#使用Web服务返回图片数据的方法
- 使用 WCF Web HTTP 编程模型创建返回任意数据的服务
- 使用返回 DataTable 的 XML Web 服务时出现问题
- (.net)C#动态调用Web服务的几种方法
- C#动态调用Web服务的3种方法
- C#动态调用Web服务的3种方法
- C#动态调用web服务引用的方法
- C#动态调用Web服务的3种方法
- C#动态调用Web服务的3种方法
- infragistics.Web.Mvc 使用(读取后台返回的数据)
- 关于名片全能王扫描,返回切边增强图片web api的图片数据分割
- C#的WEB服务开发
- Dojo AJAX 访问C#Web 服务 并且返回JS 格式的数据
- C#动态调用Web服务方法
- C# 的高效方法取得图片的像素区数据
- WCF服务返回JSON格式数据、配置web调用地址
- ajax返回数据,在外部使用的方法
- 使用Struts2,但仅仅想返回json数据的方法
- linux 下命令编码转换
- POJ 1006 Biorhythms 中国剩余定理
- 获取iphone 的ip 和 mac地址
- jquery实现点击表格修改信息!
- linux之GPIO的使用
- c#使用Web服务返回图片数据的方法
- centOS 安装 hadoop-2.2.0
- 小白谈memcache和memcached的区别
- Windows事件日志详解--登陆类型
- 使用jaxb将对象和xml进行互转
- python机器学习之神经网络(一)
- Eclipse Android java与xml代码自动提示功能
- 【原创】关于转载文章提示包含被禁用URL的问题
- BZOJ [Usaco2007 Jan]Telephone Lines架设电话线(POJ 3662)