简体   繁体   English

网络服务,提供图片

[英]web service, serving image

I need to create a web service that is called from an external website, accepts parameters from the call, and serves a dynamically created image (most likely a .png with numbers inserted based on those parameters) back to that website. 我需要创建一个从外部网站调用的Web服务,接受来自调用的参数,然后将动态创建的图像(最有可能是基于这些参数插入数字的.png)提供给该网站。 This is very high level stuff for me. 对我来说,这是非常高级的东西。 I had created a dynamic pdf with itextsharp, but then they said they wanted to go with an image instead. 我用itextsharp创建了一个动态pdf,但是后来他们说他们想代替一张图片。

I'm not even sure where to begin with such a project, as I've never created a web service. 我什至不确定从哪里开始这样的项目,因为我从未创建过Web服务。 Or should I be using a WCF? 还是应该使用WCF?

Start by creating the dyamic image how you want it, check this out: http://www.codeproject.com/KB/web-image/AspNetCreateTextImage.aspx 首先根据需要创建动态图像,请查看以下内容: http : //www.codeproject.com/KB/web-image/AspNetCreateTextImage.aspx

Then work on adding that code to a web service. 然后将代码添加到Web服务。 The web service part should be pretty simple, I'd get this working in an ASP.NET page, where you could pass the data in first, see the image, etc. and then focus on moving that code into the web service. Web服务部分应该非常简单,我将在ASP.NET页面中进行此工作,您可以在其中首先传递数据,查看图像等,然后集中精力将代码移入Web服务。

This one looks even simpler: http://www.codeproject.com/KB/aspnet/DynamicASPDotNETTextImage.aspx 这看起来更简单: http : //www.codeproject.com/KB/aspnet/DynamicASPDotNETTextImage.aspx

I've done this for when users upload an image, and you want to put the site name on to the image, it's actually pretty simple. 我这样做是为了在用户上传图像时想要将站点名称添加到图像上,这实际上非常简单。

You need an Image: 您需要一张图片:

 Image anImage = Image.FromFile(@"path to file");

Then you need to draw on it: 然后,您需要利用它:

using Graphics g = Graphics.FromImage(anImage) {
  // Draw on the image here using methods on the Graphics object...
}

Then you need to pump the image out over the web services as a byte array.. which means putting it into a memorystream.. 然后,您需要将图像作为字节数组通过Web服务泵出。这意味着将其放入内存流中。

Using MemoryStream stream = new MemoryStream {
  // Make the appropriate call to Image.Save.. something like:  anImage.Save(stream, ImageFormat.Png);
  // Turn memorystream into byte[] and return from web service method
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM