using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;

namespace JuSNS.Web.home.space
{
    public partial class cam : JuSNS.UI.Page.UserPage
    {
        protected void Page_Load(object sender, EventArgs e)
        {
			int w = 390;
			int h = 290;
			

			System.Text.StringBuilder sb=new System.Text.StringBuilder ();
  
			for(int i=0;i<Request.Form.Count ;i++)
			{
   
				if(Request.Params[i].ToString().Length==12)
				{ 
     
					sb.Append(Request.Params[i].ToString().Substring(0,6));
					sb.Append(",");
					sb.Append(Request.Params[i].ToString().Substring(7));
				}
				else
				{
					sb.Append(Request.Params[i].ToString());
     
				}
				sb.Append(",");
			}
			//this.Response.Write(sb.ToString());
   
   
			string b=sb.ToString();
			string[] sarr=b.Split(",".ToCharArray());
			System.Drawing.Bitmap bitmap=new Bitmap(w,h-14);
  
			int z=0;

  
			for(int y=h;y>=0;y--)   
			{
				for(int x=0;x<w;x++)
				{ 
					try
					{
						if(z<sarr.Length )
						{
							System.Drawing.Color c=System.Drawing.Color.FromArgb(System.Convert.ToInt32(sarr[z],16)); 
							bitmap.SetPixel(x,y,c);
						}
      
					}
					catch
					{
     
					}
         
					z=z+1;     
				}      
			}
			string filename=System.Guid.NewGuid().ToString()+".jpg"; 

 

			string bigdir=Server.MapPath("./") + "/images/";


			if(!System.IO.Directory.Exists(bigdir))
			{
				System.IO.Directory.CreateDirectory(bigdir);
			}
			bitmap.Save(bigdir+"/"+filename,System.Drawing.Imaging.ImageFormat.Jpeg);
			this.Image1.ImageUrl	 = bigdir+"/"+filename;
        }
    }
}
