public bool DeleteUser(string AccessKey, string UserName) { if (AccessKey == qpsSystem.GetAccessCode()) { try { qprPath resources = new qprPath(UserName); Directory.Delete(resources.Current_User, true); } catch (Exception) { } return true; } return false; }
public static NewImagePart PointGenerator(string UserName, byte[] ImagePart, int _x, int _y, int width, int height, int PxFormat) { try { Rectangle recti = new Rectangle(_x, _y, width, height); PixFormat _pixFor = (PixFormat)StringToEnum(typeof(PixFormat), Convert.ToString("_" + PxFormat.ToString() + "x" + PxFormat.ToString())); qprPath resources = new qprPath(UserName); if (_pixFor == PixFormat._null) throw new Exception("Format null olamaz") { Source = "" }; //GC.Collect(); //Bitmap bmp; //using (var ms = new MemoryStream(ImagePart)) //{ // bmp = new Bitmap(ms); //} using (MagickImage imagem = new MagickImage(ImagePart)) { imagem.Quality = 100; imagem.Blur(5, 5); List<ImgSquare> sp0 = new List<ImgSquare>(); if (true) { int[,] pixavg = new int[5, 3]; int _pixformat = (int)_pixFor; WritablePixelCollection _totalpix = imagem.GetWritablePixels(0, 0, imagem.Width, imagem.Height); int range = _pixformat / 2; for (int w = 0; w < imagem.Width; w += _pixformat) { for (int h = 0; h < imagem.Height; h += _pixformat) { if (!(w + _pixformat <= imagem.Width && h + _pixformat <= imagem.Height)) continue;//olmazda olursa diye pixavg = new int[5, 3]; for (int x = 0; x < range; x++) { for (int y = 0; y < range; y++) { Color a = _totalpix.GetPixel(x + w + 0, h + 0 + y).ToColor().ToColor(); pixavg[0, 0] += a.R; pixavg[0, 1] += a.G; pixavg[0, 2] += a.B; Color b = _totalpix.GetPixel(x + w + range, h + y).ToColor().ToColor(); pixavg[1, 0] += b.R; pixavg[1, 1] += b.G; pixavg[1, 2] += b.B; Color c = _totalpix.GetPixel(x + w, h + range + y).ToColor().ToColor(); pixavg[2, 0] += c.R; pixavg[2, 1] += c.G; pixavg[2, 2] += c.B; Color d = _totalpix.GetPixel(x + w + range, h + range + y).ToColor().ToColor(); pixavg[3, 0] += d.R; pixavg[3, 1] += d.G; pixavg[3, 2] += d.B; } } //tümü için aynı toplanıyor pixavg[4, 0] = pixavg[0, 0] + pixavg[1, 0] + pixavg[2, 0] + pixavg[3, 0]; pixavg[4, 1] = pixavg[0, 1] + pixavg[1, 1] + pixavg[2, 1] + pixavg[3, 1]; pixavg[4, 2] = pixavg[0, 2] + pixavg[1, 2] + pixavg[2, 2] + pixavg[3, 2]; //---- int totalminiPix = (range * range); pixavg[0, 0] /= totalminiPix; pixavg[0, 1] /= totalminiPix; pixavg[0, 2] /= totalminiPix; pixavg[1, 0] /= totalminiPix; pixavg[1, 1] /= totalminiPix; pixavg[1, 2] /= totalminiPix; pixavg[2, 0] /= totalminiPix; pixavg[2, 1] /= totalminiPix; pixavg[2, 2] /= totalminiPix; pixavg[3, 0] /= totalminiPix; pixavg[3, 1] /= totalminiPix; pixavg[3, 2] /= totalminiPix; int totalPix = totalminiPix * 4; pixavg[4, 0] /= totalPix; pixavg[4, 1] /= totalPix; pixavg[4, 2] /= totalPix; sp0.Add(new ImgSquare(w, h, new List<QuardPixAvg>() { new QuardPixAvg(Color.FromArgb((pixavg[0, 0]), (pixavg[0, 1]), (pixavg[0, 2])), QuardBolum.SolUst), new QuardPixAvg (Color.FromArgb((pixavg[1, 0]), (pixavg[1, 1]), (pixavg[1, 2])), QuardBolum.SagUst), new QuardPixAvg(Color.FromArgb((pixavg[2, 0]), (pixavg[2, 1]), (pixavg[2, 2])), QuardBolum.SolAlt), new QuardPixAvg(Color.FromArgb((pixavg[3, 0]), (pixavg[3, 1]), (pixavg[3, 2])), QuardBolum.SagAlt), new QuardPixAvg(Color.FromArgb((pixavg[4, 0]), (pixavg[4, 1]), (pixavg[4, 2])), QuardBolum.TotalAvg) })); } } _totalpix = null; pixavg = null; ////////////////////////////// xml generate /////////////////////////////// #region xml oluşturma //XmlDocument doc = new XmlDocument(); //XmlElement root = doc.CreateElement("SquarePoints"); //root.SetAttribute("Count", sp0.Count.ToString()); //root.SetAttribute("PixFormat", _pixFor.ToString()); //foreach (ImgSquare item in sp0) //{ // XmlElement child = doc.CreateElement("SquarePoint"); // child.SetAttribute("WxH", item.ToString()); // child.SetAttribute("ColorAVG", item.SAvgArb.ToString()); // List<QuardPixAvg> lstQ = item.QuardAvg; // child.SetAttribute("SolUst", lstQ[0].QuardAvg.ToString()); // child.SetAttribute("SagUst", lstQ[1].QuardAvg.ToString()); // child.SetAttribute("SolAlt", lstQ[2].QuardAvg.ToString()); // child.SetAttribute("SagAlt", lstQ[3].QuardAvg.ToString()); // root.AppendChild(child); //} //doc.AppendChild(root); //if (!Directory.Exists(finf.Directory.FullName)) // Directory.CreateDirectory(finf.Directory.FullName); //doc.Save(path); //doc = null; #endregion xml oluşturma } else { #region xml okuma //XmlDocument doc = new XmlDocument(); //doc.Load(path); //XmlNodeList root1 = doc.GetElementsByTagName("SquarePoints"); //XmlNode root2 = root1.Item(0); //foreach (XmlNode item in root2.ChildNodes) //{ // try // { // XmlAttribute at1 = item.Attributes[0]; // string[] point = at1.InnerText.Split('x'); // XmlAttribute at2 = item.Attributes[1]; // string ColorAvg = at2.InnerText; // List<QuardPixAvg> lQuard = new List<QuardPixAvg>(); // int SolUst = int.Parse(item.Attributes[2].InnerText); // int SagUst = int.Parse(item.Attributes[3].InnerText); // int SolAlt = int.Parse(item.Attributes[4].InnerText); // int SagAlt = int.Parse(item.Attributes[5].InnerText); // int Tumu = int.Parse(item.Attributes[1].InnerText); // lQuard.Add(new QuardPixAvg(Color.FromArgb(SolUst), QuardBolum.SolUst)); // lQuard.Add(new QuardPixAvg(Color.FromArgb(SagUst), QuardBolum.SagUst)); // lQuard.Add(new QuardPixAvg(Color.FromArgb(SolAlt), QuardBolum.SolAlt)); // lQuard.Add(new QuardPixAvg(Color.FromArgb(SagAlt), QuardBolum.SagAlt)); // lQuard.Add(new QuardPixAvg(Color.FromArgb(Tumu), QuardBolum.Tumu)); // sp0.Add(new ImgSquare(int.Parse(point[0]), int.Parse(point[1]), lQuard)); // } // catch (Exception e) // { // throw e; // } //} //root2 = null; //root1 = null; //doc = null; #endregion xml okuma } //#--------------------------------- int opacity = 50; switch (_pixFor) { case PixFormat._null: sp0.Clear(); throw new Exception("Tanımsız format") { Source = "" }; break; case PixFormat._12x12: opacity = 50; break; case PixFormat._20x20: opacity = 50; break; case PixFormat._36x36: opacity = 50; break; case PixFormat._48x48: opacity = 50; break; case PixFormat._64x64: opacity = 50; break; case PixFormat._94x94: opacity = 50; break; } string MiniPicturePath = Path.Combine(resources.Data_InstagramPhotos); if (Directory.Exists(MiniPicturePath)) { Bitmap btm = imagem.ToBitmap(); using (Graphics gr1 = Graphics.FromImage(btm)) { /////////////////////////////////////////////////////////////// string[] file = Directory.GetFiles(resources.Current_User, resources.UserXmlInfo); if (file.Count() != 1) throw new Exception("Geçersiz kullanıcı bilgileri"); XDocument doc = XDocument.Load(file[0]); XElement root = doc.Elements("_" + resources.UserName).First(); XElement InstagramP = root.Elements("InstagramPhotos").FirstOrDefault(); XElement[] photos = (from p in InstagramP.Elements() where p.Attribute("useThis").Value.ToLower() == "true" select p).ToArray(); /////////////////////////////////////////////////// if (photos.Count() == 0) throw new Exception("Bu Formata Uygun Resimler Bulunamadı") { Source = "" }; List<ImgSquare> spl2 = new List<ImgSquare>(); for (int i = 0; i < photos.Count(); i++) { if (File.Exists(Path.Combine(MiniPicturePath, Path.GetFileName(photos[i].Value)))) { using (MagickImage mini = new MagickImage(Path.Combine(MiniPicturePath, Path.GetFileName(photos[i].Value)))) { mini.Quality = 100; if (mini.Width != 94 && mini.Height != 94) mini.Resize((int)_pixFor, (int)_pixFor); spl2.Add(new ImgSquare(mini.ToBitmap())); mini.Dispose(); } } } photos = null; doc = null; root = null; InstagramP = null; List<ImgSquare> spl4 = new List<ImgSquare>(); spl4.AddRange(sp0); spl4.AddRange(spl2); spl2.Clear(); spl4 = spl4.OrderBy(p => p.GeneratedColorCode).ToList(); int qpiro_number = 432101; int qpiro_number2 = 0; int undefined = 0; for (int i = 0; i < sp0.Count; i++) { ImgSquare item = sp0[i]; try { qpiro_number2 = 0; List<ImgSquare> snc = null; int cont = 0; do { snc = spl4.Where(p => (p.GeneratedColorCode - (qpiro_number + qpiro_number2) < item.GeneratedColorCode && p.GeneratedColorCode + (qpiro_number + qpiro_number2) > item.GeneratedColorCode) && p.isArea == false).ToList(); qpiro_number2 += 332101; cont++; } while (snc.Count == 0 && cont < 5); Rectangle rec = new Rectangle(item.W, item.H, (int)_pixFor, (int)_pixFor); if (snc.Count != 0) { int randi = random.Next(0, snc.Count); System.Drawing.Image img = SmartRotate(item, snc[randi]); snc.Clear();// img = Transparnt(img, opacity); gr1.DrawImage(img, rec); sp0.RemoveAt(i); i--; img.Dispose(); } else { cont = 0; qpiro_number2 = (332101 * 5); do { snc = spl4.Where(p => (p.GeneratedColorCode - (qpiro_number + qpiro_number2) < item.GeneratedColorCode && p.GeneratedColorCode + (qpiro_number + qpiro_number2) > item.GeneratedColorCode) && p.isArea == false).ToList(); qpiro_number2 += 332101; cont++; } while (snc.Count == 0 && cont < 11); if (snc.Count > 0) { int randi = random.Next(0, snc.Count); System.Drawing.Image img = SmartRotate(item, snc[randi]); snc.Clear(); Bitmap bt0 = new Bitmap(rec.Width, rec.Height); Graphics g = Graphics.FromImage(bt0); g.Clear(Color.FromArgb(item.GeneratedColorCode)); if (opacity != 100) { img = Transparnt(img, opacity + 20); } g.DrawImage(img, new Rectangle(0, 0, rec.Width, rec.Height)); g.Dispose(); gr1.DrawImage(bt0, rec); sp0.RemoveAt(i); i--; img.Dispose(); } undefined++; } } catch (Exception ef) { throw ef; } } sp0.Clear(); spl4.Clear(); gr1.Dispose(); imagem.Dispose(); return new NewImagePart() { newImage = new MagickImage(btm).ToByteArray(), ImagePartInfo = recti.ToString() }; } } else { throw new Exception("Bu Formata Uygun Resimler Bulunamadı2") { Source = "" }; } } } catch (Exception e) { throw e; } return null; }