public override void compressFile(NormaliseImage norm) { double[] tmpInput = new double[8]; double[] tmpOutput = new double[8]; List <CImage.posCol> pcList = new List <CImage.posCol>(); ci = new CImage(norm._image.Width, norm._image.Height); bool checkloopdone; for (int y = 0; y < norm._image.Height; y++) { checkloopdone = true; int num = 1; CImage.posCol pc = new CImage.posCol(); for (int x = 0; x < norm._image.Width; x++) { foreach (KeyValuePair <double, double[]> kv in norm._DataList) { if (kv.Key == norm._numArray[x, y]) { tmpInput = kv.Value; break; } } bpnetwork.run(ref tmpInput, out tmpOutput); for (int i = 0; i < 8; i++) { tmpOutput[i] = Math.Round(tmpOutput[i]); } double checkVal = 0; foreach (KeyValuePair <double, double[]> kvk in norm._DataList) { if (tmpOutput.SequenceEqual(kvk.Value)) { checkVal = kvk.Key; break; } } bool one = false; Color col = new Color(); foreach (KeyValuePair <Color, double> kv in norm._ColourList) { if (kv.Value == checkVal) { one = true; col = kv.Key; num++; break; } } if (checkloopdone) { if (one) { pc.x = x; pc.y = y; pc.col = col; pc.num = num; } } else if (one) { pc.num = num; } if (!one) { foreach (KeyValuePair <Color, double> kv in norm._ColourList) { if (kv.Value == tmpInput[0]) { pc.col = kv.Key; break; } } pc.x = x; pc.y = y; pc.num = 1; pcList.Add(pc); } one = false; checkloopdone = false; } pcList.Add(pc); } ci._PosList = pcList.ToArray(); }
public void extractfile(object sender, EventArgs e) { if ((File1.PostedFile != null) && (File1.PostedFile.ContentLength > 0)) { string fn = System.IO.Path.GetFileName(File1.PostedFile.FileName); Session["filename"] = fn; string SaveLocation = Server.MapPath("uploadedFiles") + "\\" + fn; try { File1.PostedFile.SaveAs(SaveLocation); btnExtract.Visible = true; String filepath = findFilePath((String)Session["filename"]); String actualFile = findFile((String)Session["filename"]); string fileType = Path.GetExtension(filepath); Session["filetype"] = fileType; switch (fileType) { case ".cmi": CImage cimage = DecompressAndDeserialize <CImage>(File.ReadAllBytes(actualFile)); ExtractImage extI = new ExtractImage(cimage); ImageCodecInfo jpgEncoder = GetEncoder(ImageFormat.Jpeg); System.Drawing.Imaging.Encoder myEncoder = System.Drawing.Imaging.Encoder.Quality; EncoderParameters myEncoderParameters = new EncoderParameters(1); EncoderParameter myEncoderParameter = new EncoderParameter(myEncoder, 100L); myEncoderParameters.Param[0] = myEncoderParameter; string filename = Server.MapPath("resources/ExtractedImage.jpg"); extI.extract().Save(filename, jpgEncoder, myEncoderParameters); OpenWindow(); break; case ".cmx": ExtractText ext = new ExtractText(File.ReadAllBytes(actualFile)); string filenam = Server.MapPath("resources/ExtractedText.txt"); File.WriteAllText(filenam, ext.extract()); OpenWindow(); break; default: btnExtract.Visible = true; ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "alertMessage", "alert('Please Upload .cmx or.cmi files only')", true); break; } } catch (Exception ex) { ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "alertMessage", "alert('Unkown error occured')", true); } } else { ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "alertMessage", "alert('Please upload a file')", true); } }
public ExtractImage(CImage cimage) { this.cimage = cimage; }