Let’s go thru the code:
WCF Service:
Service1.svc.cs
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Runtime.Serialization;
- using System.ServiceModel;
- using System.ServiceModel.Web;
- using System.Text;
- using System.IO;
- using System.Drawing;
- using System.Drawing.Imaging;
- namespace PhotoService {
- public class Service1: IService1 {
- //This method will be called by the application to get Thumbnail
- public Stream GetThumbnail(string path) {
- try {
- Image imgThumb = null;
- Image img = Image.FromFile("/\\" + path); //Path for Image Eg. http://localhost:35798/RestServiceImpl.svc/GetThumbnail///YourServer//Images//SampleImage.jpg
- imgThumb = CreateThumbnail(img, 100, 100);
- var stream = ToStream(imgThumb, ImageFormat.Jpeg);
- WebOperationContext.Current.OutgoingResponse.ContentType = "image/jpeg";
- return stream;
- } catch (Exception ex) {
- throw ex;
- }
- }
- //This method will generate thumbanail of 100 x 100
- private Image CreateThumbnail(Image image, int thumbWidth, int thumbHeight) {
- try {
- return image.GetThumbnailImage(
- thumbWidth,
- thumbHeight,
- delegate() {
- return false;
- },
- IntPtr.Zero);
- } catch (Exception ex) {
- throw ex;
- }
- }
- //Method to convert image in stream
- public Stream ToStream(Image image, ImageFormat formaw) {
- try {
- var stream = new System.IO.MemoryStream();
- image.Save(stream, formaw);
- stream.Position = 0;
- return stream;
- } catch (Exception ex) {
- throw;
- }
- }
- }
- }
- using System;
- using System.Runtime.Serialization;
- using System.ServiceModel;
- using System.ServiceModel.Web;
- using System.IO;
- using System.Drawing;
- using System.Drawing.Imaging;
- namespace PhotoService {
- [ServiceContract]
- public interface IService1 {
- [OperationContract]
- [WebInvoke(Method = "GET", ResponseFormat = WebMessageFormat.Json, BodyStyle = WebMessageBodyStyle.Wrapped, UriTemplate = "GetThumbnail/{*path}")]
- Stream GetThumbnail(string path);
- }
- }



pardha saradhiPosted Aug 14, 2016, 8:58 AM
U did good job
pardha saradhiPosted Aug 14, 2016, 8:58 AM
Please send me code
Van LaiPosted May 25, 2015, 11:44 PM
Very helpful, thx a lot
Santhakumar MunuswamyPosted May 21, 2015, 3:08 PM
Nice