ImagProcessController.cs 2.86 KB
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Web.Http;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using System.Web.Hosting;
using System.IO;
using System.Drawing;
using System.Text;
using System.Drawing.Imaging;

namespace AIA.Highlight.POC.API.Controllers
{
    public class ImagProcessController : ApiController
    {
        // GET api/<controller>
        //public IEnumerable<string> Get()
        //{
        //    return new string[] { "amrita", "vishnoi" };
        //}

        // GET api/<controller>/5
        public string Get(int id)
        {
            return "value";
        }

                // PUT api/<controller>/5
        public void Put(int id, [FromBody]string value)
        {
        }

        // DELETE api/<controller>/5
        public void Delete(int id)
        {
        }

        public HttpResponseMessage Post([FromBody]JObject maskImg)
        {
            return new HttpResponseMessage { StatusCode = HttpStatusCode.OK, Content = new StringContent("Have some issue") };

            
        }

        public IEnumerable<string> Get()
        {
            string pixelFormat;
            string folder = "~/Content/DA/75/body-views/1/layers/50/";
            for (int i = 1; i < 2; i++)
            {
                string imageFolderPath = HostingEnvironment.MapPath(folder + i.ToString());
                string[] imageFileNames = Directory.GetFiles(imageFolderPath, "*.png");

                foreach (string fileName in imageFileNames)
                {
                    Bitmap img = new Bitmap(fileName);
                    
                    
                    //Image img = Image.FromFile(file)
                    ////Bitmap img = (Bitmap) Bitmap.FromFile(fileName, true);

                    StringBuilder imagePixelData = new StringBuilder();


                    for (int width = 0; width < 507; width++)
                    {
                        for (int height = 0; height < 348; height++)
                        {
                            Color pixel = img.GetPixel(width, height);
                            imagePixelData.Append(pixel.R.ToString());
                            imagePixelData.Append(",");
                            imagePixelData.Append(pixel.G.ToString());
                            imagePixelData.Append(",");
                            imagePixelData.Append(pixel.B.ToString());
                            imagePixelData.Append(",");
                            imagePixelData.Append(pixel.A.ToString());
                        }
                    }

                    File.WriteAllText(fileName.Replace("png", "txt"), imagePixelData.ToString());


                }
            }
            return new string[] { "1", "2" };
        }
    }
}