public ImageDocument ApplayImage() { ApplaypActiveCurve(); var tools = new Sbn.Controls.Imaging.SbnImageTools(); Layer ly = new Layer(); Elements elms = new Elements(); foreach (Sbn.FramWork.Drawing.Shape film in this.drawingPanel1.Shapes) { if (!(film is Sbn.AdvancedControls.Imaging.SbnPaint.BodyBackground) && !(film is Sbn.AdvancedControls.Imaging.SbnPaint.Image)) { Element el = new Element(); Sbn.AdvancedControls.Imaging.SbnPaint.Image img = new Sbn.AdvancedControls.Imaging.SbnPaint.Image(); Image img2; double ll = Math.Truncate(this.drawingPanel1.ZoomFactor * 100000); float tt = (float)(100000 / ll); if (film is Sbn.AdvancedControls.Imaging.SbnPaint.Image) { img = (Sbn.AdvancedControls.Imaging.SbnPaint.Image)film; img2 = img.Bitmap; } else { img2 = film.GetImage(this.drawingPanel1.Zoom);// img.getImageFromShape(film, this.drawingPanel1.ZoomFactor); } ((Bitmap)img2).MakeTransparent(Color.White); System.IO.MemoryStream ms = new MemoryStream(); // img2.Save("C:\\as.jpg"); img2.Save(ms, System.Drawing.Imaging.ImageFormat.Png); el.Stream = new byte[ms.Length]; el.Stream = ms.GetBuffer(); int x = (int)(film.Location.X - this.drawingPanel1.BackgroundLayer.Location.X); int y = (int)(film.Location.Y - this.drawingPanel1.BackgroundLayer.Location.Y); el.LocationX = (long)(x * tt); el.LocationY = (long)(y * tt); el.Tag = img2; // img2.Save("C:\\aa.jpg"); // el.ID = -(elms.Count + 1); ms.Close(); ms.Dispose(); if (el.ID <= 0) { el.ID = -elms.Count - 1; } if (!elms.Contains(el)) { elms.Add(el); } else { } } else { // film.Appearance.Image.Save("C:\\aa.jpg"); if (film is Sbn.AdvancedControls.Imaging.SbnPaint.BodyBackground) { //((FilmstripImage)this.CurrentImage).Image = film.Appearance.Image; try { Bitmap result = new Bitmap(film.Appearance.Image.Width, film.Appearance.Image.Height); Graphics gg = Graphics.FromImage(result); gg.DrawImage(film.Appearance.Image, new Rectangle(0, 0, film.Appearance.Image.Width, film.Appearance.Image.Height)); gg.Save(); gg.Dispose(); using (Image imageToExport = result) { MemoryStream ms = new MemoryStream(); // ((FilmstripImage)this.CurrentImage).Image.Save(ms, System.Drawing.Imaging.ImageFormat.Tiff); imageToExport.Save(ms, System.Drawing.Imaging.ImageFormat.Tiff); this.CurrentImage.Stream = ms.GetBuffer(); ms.Dispose(); } result.Dispose(); result = null; } catch { } } else { double ll = Math.Truncate(this.drawingPanel1.ZoomFactor * 100000); float tt = (float)(100000 / ll); int x = (int)(film.Location.X - this.drawingPanel1.BackgroundLayer.Location.X); int y = (int)(film.Location.Y - this.drawingPanel1.BackgroundLayer.Location.Y); //((Element)film.Tag).LocationX = (long)film.Location.X ; //((Element)film.Tag).LocationY = (long)film.Location.Y; if (film.Tag is Element) { try { ((Element)film.Tag).LocationX = (long)(x * tt); ((Element)film.Tag).LocationY = (long)(y * tt); Image iig = film.Appearance.Image; // iig.Save("C:\\dddd.jpeg"); if (film.IsEdited) { Bitmap bmp = new Bitmap((int)(iig.Width), (int)(iig.Height)); bmp = new Bitmap((int)(iig.Width * tt), (int)(iig.Height * tt)); System.Drawing.Graphics g = System.Drawing.Graphics.FromImage(bmp); g.Clear(Color.White); g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality; g.DrawImage(iig, new Rectangle(new System.Drawing.Point(0, 0), bmp.Size)); bmp.MakeTransparent(Color.White); //this.Image = bmp; g.Dispose(); MemoryStream ms = new MemoryStream(); bmp.Save(ms, System.Drawing.Imaging.ImageFormat.Png); if (((Element)film.Tag).Stream.Length != ms.GetBuffer().Length) { ((Element)film.Tag).Stream = ms.GetBuffer(); ((Element)film.Tag).Tag = bmp; ((Element)film.Tag).Title += "Edited"; } ms.Dispose(); } } catch { } } else { try { var newElm = new Element(); newElm.LocationX = (long)(x * tt); newElm.LocationY = (long)(y * tt); Image iig = film.Appearance.Image; Bitmap bmp = new Bitmap((int)(iig.Width), (int)(iig.Height)); bmp = new Bitmap((int)(iig.Width * tt), (int)(iig.Height * tt)); System.Drawing.Graphics g = System.Drawing.Graphics.FromImage(bmp); g.Clear(Color.White); g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality; g.DrawImage(iig, new Rectangle(new System.Drawing.Point(0, 0), bmp.Size)); bmp.MakeTransparent(Color.White); //this.Image = bmp; g.Dispose(); MemoryStream ms = new MemoryStream(); bmp.Save(ms, System.Drawing.Imaging.ImageFormat.Png); newElm.Stream = ms.GetBuffer(); newElm.Tag = bmp; //newElm.Title += "Edited"; ms.Dispose(); elms.Add(newElm); } catch { } } } } } if (elms.Count > 0) { ly.elements = elms; if (CurrentImage == null) { CurrentImage = new ImageDocument(); CurrentImage.layers = new Layers(); } if (CurrentImage.layers == null) { CurrentImage.layers = new Layers(); } if (ly.ID <= 0) { ly.ID = -CurrentImage.layers.Count - 1; } CurrentImage.layers.Add(ly); } // ((FilmstripImage)this.CurrentImage).Image.Save("c:\\bb.jpg"); // this.CurrentImage.layers = new Layers(); // this.CurrentImage.layers = getElements(); return(CurrentImage); }
//private void UpdateElement(Element el) //{ // //foreach (Layer ly in CurrentImage.layers.m_Col) // //{ // // foreach(ele // //} //} //public void AddImage(System.Drawing.Image img, Point location) //{ // drawingPanel1.AddImage(img , location); // tsbtnCurser.Checked = true; //} //public void AddText(string text, Point location) //{ //} public Layers getElements() { Layers lys = new Layers(); if (this.CurrentImage.layers != null && this.CurrentImage.layers.Count > 1) { foreach (Layer ly in this.CurrentImage.layers) { } } else { Layer ly = new Layer(); Elements elms = new Elements(); foreach (Sbn.FramWork.Drawing.Shape film in this.drawingPanel1.Shapes) { if (!(film is Sbn.AdvancedControls.Imaging.SbnPaint.BodyBackground)) { Element el = new Element(); Sbn.AdvancedControls.Imaging.SbnPaint.Image img = new Sbn.AdvancedControls.Imaging.SbnPaint.Image(); Image img2; double ll = Math.Truncate(this.drawingPanel1.ZoomFactor * 100000); float tt = (float)(100000 / ll); if (film is Sbn.AdvancedControls.Imaging.SbnPaint.Image) { img = (Sbn.AdvancedControls.Imaging.SbnPaint.Image)film; img2 = img.Bitmap; } else { img2 = img.getImageFromShape(film, this.drawingPanel1.ZoomFactor); } ((Bitmap)img2).MakeTransparent(Color.White); System.IO.MemoryStream ms = new MemoryStream(); img2.Save(ms, System.Drawing.Imaging.ImageFormat.Png); el.Stream = new byte[ms.Length]; el.Stream = ms.GetBuffer(); //System.IO.MemoryStream ms2 = new System.IO.MemoryStream(strem); //System.Drawing.Image myImage = System.Drawing.Image.FromStream(ms2); //myImage.Save("c:\\temp.png", System.Drawing.Imaging.ImageFormat.Png); //Bitmap bm = new Bitmap(img2); int x = (int)(film.Location.X - this.drawingPanel1.BackgroundLayer.Location.X); int y = (int)(film.Location.Y - this.drawingPanel1.BackgroundLayer.Location.Y); el.LocationX = (long)(x * tt); // this.ucPaint1.drawingPanel1.HorizontalScroll.Value + film.Location.X; el.LocationY = (long)(y * tt); // this.ucPaint1.drawingPanel1.VerticalScroll.Value + film.Location.Y; el.Tag = img2; ms.Close(); ms.Dispose(); elms.Add(el); } } ly.elements = elms; lys.Add(ly); } return(lys); }
void img_ShapeMouseUp(Sbn.FramWork.Drawing.IShape shape, Sbn.FramWork.Drawing.IDocument document, MouseEventArgs e) { try { if (shape is Sbn.AdvancedControls.Imaging.SbnPaint.Image) { Sbn.AdvancedControls.Imaging.SbnPaint.Image img = (Sbn.AdvancedControls.Imaging.SbnPaint.Image)shape; Element el = (Element)img.Tag;// (Element)img.Bitmap.Tag; Image img2; double ll = Math.Truncate(this.drawingPanel1.ZoomFactor * 100000); float tt = (float)(100000 / ll); //Bitmap bmp = new Bitmap((int)shape.Dimension.Width, (int)shape.Dimension.Height); //System.Drawing.Graphics g = System.Drawing.Graphics.FromImage(bmp); //RectangleF rect = new RectangleF(0, 0, bmp.Width, bmp.Height); //GraphicsUnit ff = GraphicsUnit.Pixel; //RectangleF Destrect; //if (img.Bitmap != null) //{ // Destrect = img.Bitmap.GetBounds(ref ff); // g.DrawImage(img.Bitmap, Destrect); //} //else //{ // // Destrect = selectedShape.Geometric.GetBounds(); // // g.DrawImage(selectedShape.Appearance.Image, rect); //} if (shape is Sbn.AdvancedControls.Imaging.SbnPaint.Image) { img = (Sbn.AdvancedControls.Imaging.SbnPaint.Image)shape; img2 = img.Bitmap; // img2 = bmp;// shape.Appearance.Image; } else { img2 = img.getImageFromShape(img, this.drawingPanel1.ZoomFactor); } ((Bitmap)img2).MakeTransparent(Color.White); System.IO.MemoryStream ms = new MemoryStream(); img2.Save(ms, System.Drawing.Imaging.ImageFormat.Png); el.Stream = new byte[ms.Length]; el.Stream = ms.GetBuffer(); //System.IO.MemoryStream ms2 = new System.IO.MemoryStream(strem); //System.Drawing.Image myImage = System.Drawing.Image.FromStream(ms2); //myImage.Save("c:\\temp.png", System.Drawing.Imaging.ImageFormat.Png); //Bitmap bm = new Bitmap(img2); int x = (int)(shape.Location.X - this.drawingPanel1.BackgroundLayer.Location.X); int y = (int)(shape.Location.Y - this.drawingPanel1.BackgroundLayer.Location.Y); el.LocationX = (long)(x * tt); // this.ucPaint1.drawingPanel1.HorizontalScroll.Value + film.Location.X; el.LocationY = (long)(y * tt); // this.ucPaint1.drawingPanel1.VerticalScroll.Value + film.Location.Y; el.Tag = img2; img2.Tag = el; ms.Close(); ms.Dispose(); } } catch { } }