ImagProcessController.cs
2.86 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
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" };
}
}
}