Reputation: 1086
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. 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.
I'm not even sure where to begin with such a project, as I've never created a web service. Or should I be using a WCF?
Upvotes: 0
Views: 1565
Reputation: 33738
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..
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
}
Upvotes: 0
Reputation: 2542
Start by creating the dyamic image how you want it, check this out: http://www.codeproject.com/KB/web-image/AspNetCreateTextImage.aspx
Then work on adding that code to a web service. 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.
This one looks even simpler: 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.
Upvotes: 1