示例#1
0
        private string GetLayerPicture(ReportComponentBase obj, out float Width, out float Height)
        {
            string result = String.Empty;

            Width  = 0;
            Height = 0;

            if (obj != null)
            {
                if (pictures)
                {
                    MemoryStream PictureStream = new MemoryStream();
                    System.Drawing.Imaging.ImageFormat FPictureFormat = System.Drawing.Imaging.ImageFormat.Bmp;
                    if (imageFormat == ImageFormat.Png)
                    {
                        FPictureFormat = System.Drawing.Imaging.ImageFormat.Png;
                    }
                    else if (imageFormat == ImageFormat.Jpeg)
                    {
                        FPictureFormat = System.Drawing.Imaging.ImageFormat.Jpeg;
                    }
                    else if (imageFormat == ImageFormat.Gif)
                    {
                        FPictureFormat = System.Drawing.Imaging.ImageFormat.Gif;
                    }

                    Width  = obj.Width == 0 ? obj.Border.LeftLine.Width : obj.Width;
                    Height = obj.Height == 0 ? obj.Border.TopLine.Width : obj.Height;

                    if (Math.Abs(Width) * Zoom < 1 && Zoom > 0)
                    {
                        Width = 1 / Zoom;
                    }

                    if (Math.Abs(Height) * Zoom < 1 && Zoom > 0)
                    {
                        Height = 1 / Zoom;
                    }

                    int zoom = highQualitySVG ? 3 : 1;

                    using (System.Drawing.Image image =
                               new Bitmap(
                                   (int)(Math.Abs(Math.Round(Width * Zoom * zoom))),
                                   (int)(Math.Abs(Math.Round(Height * Zoom * zoom)))
                                   ))
                    {
                        using (Graphics g = Graphics.FromImage(image))
                        {
                            if (obj is TextObjectBase)
                            {
                                g.Clear(Color.Transparent);
                            }

                            float Left = Width > 0 ? obj.AbsLeft : obj.AbsLeft + Width;
                            float Top  = Height > 0 ? obj.AbsTop : obj.AbsTop + Height;

                            float dx = 0;
                            float dy = 0;
                            g.TranslateTransform((-Left - dx) * Zoom * zoom, (-Top - dy) * Zoom * zoom);

                            BorderLines oldLines = obj.Border.Lines;
                            obj.Border.Lines = BorderLines.None;
                            obj.Draw(new FRPaintEventArgs(g, Zoom + zoom - 1, Zoom + zoom - 1, Report.GraphicCache));
                            obj.Border.Lines = oldLines;
                        }
                        using (Bitmap b = new Bitmap((int)Width, (int)Height))
                        {
                            using (Graphics gr = Graphics.FromImage(b))
                            {
                                gr.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.HighQualityBicubic;
                                gr.DrawImage(image, 0, 0, (int)Width, (int)Height);
                            }

                            if (FPictureFormat == System.Drawing.Imaging.ImageFormat.Jpeg)
                            {
                                ExportUtils.SaveJpeg(b, PictureStream, 95);
                            }
                            else
                            {
                                b.Save(PictureStream, FPictureFormat);
                            }
                        }
                    }
                    PictureStream.Position = 0;

                    string hash = String.Empty;
                    if (obj is PictureObject)
                    {
                        PictureObject pic = (obj as PictureObject);
                        if (pic.Image != null)
                        {
#if MONO
                            using (MemoryStream picStr = new MemoryStream())
                            {
                                ImageHelper.Save(pic.Image, picStr);
                                using (StreamWriter picWriter = new StreamWriter(picStr))
                                {
                                    picWriter.Write(pic.Width);
                                    picWriter.Write(pic.Height);
                                    picWriter.Write(pic.Angle);
                                    picWriter.Write(pic.Transparency);
                                    picWriter.Write(pic.TransparentColor.ToArgb());
                                    picWriter.Write(pic.CanShrink);
                                    picWriter.Write(pic.CanGrow);
                                    hash = Crypter.ComputeHash(picStr);
                                }
                            }
#else
                            hash = Crypter.ComputeHash(PictureStream);
                            PictureStream.Position = 0;
#endif
                        }
                    }
                    else
                    {
                        hash = Crypter.ComputeHash(PictureStream);
                    }
                    result = HTMLGetImage(0, 0, 0, hash, true, null, PictureStream, false);
                }
            }
            return(result);
        }
        private string GetLayerPicture(ReportComponentBase obj, out float Width, out float Height)
        {
            string result = String.Empty;

            Width  = 0;
            Height = 0;

            if (obj != null)
            {
                if (pictures)
                {
                    MemoryStream PictureStream = new MemoryStream();
                    System.Drawing.Imaging.ImageFormat FPictureFormat = System.Drawing.Imaging.ImageFormat.Bmp;
                    if (imageFormat == ImageFormat.Png)
                    {
                        FPictureFormat = System.Drawing.Imaging.ImageFormat.Png;
                    }
                    else if (imageFormat == ImageFormat.Jpeg)
                    {
                        FPictureFormat = System.Drawing.Imaging.ImageFormat.Jpeg;
                    }
                    else if (imageFormat == ImageFormat.Gif)
                    {
                        FPictureFormat = System.Drawing.Imaging.ImageFormat.Gif;
                    }

                    Width  = obj.Width == 0 ? obj.Border.LeftLine.Width : obj.Width;
                    Height = obj.Height == 0 ? obj.Border.TopLine.Width : obj.Height;

                    if (Math.Abs(Width) * Zoom < 1 && Zoom > 0)
                    {
                        Width = 1 / Zoom;
                    }

                    if (Math.Abs(Height) * Zoom < 1 && Zoom > 0)
                    {
                        Height = 1 / Zoom;
                    }

                    using (System.Drawing.Image image =
                               new Bitmap(
                                   (int)(Math.Abs(Math.Round(Width * Zoom))),
                                   (int)(Math.Abs(Math.Round(Height * Zoom)))
                                   )
                           )
                    {
                        using (Graphics g = Graphics.FromImage(image))
                        {
                            if (obj is TextObjectBase)
                            {
                                g.Clear(Color.White);
                            }

                            float Left = Width > 0 ? obj.AbsLeft : obj.AbsLeft + Width;
                            float Top  = Height > 0 ? obj.AbsTop : obj.AbsTop + Height;

                            float dx = 0;
                            float dy = 0;
                            g.TranslateTransform((-Left - dx) * Zoom, (-Top - dy) * Zoom);

                            BorderLines oldLines = obj.Border.Lines;
                            obj.Border.Lines = BorderLines.None;
                            obj.Draw(new FRPaintEventArgs(g, Zoom, Zoom, Report.GraphicCache));
                            obj.Border.Lines = oldLines;
                        }

                        if (FPictureFormat == System.Drawing.Imaging.ImageFormat.Jpeg)
                        {
                            ExportUtils.SaveJpeg(image, PictureStream, 95);
                        }
                        else
                        {
                            image.Save(PictureStream, FPictureFormat);
                        }
                    }
                    PictureStream.Position = 0;
                    result = HTMLGetImage(0, 0, 0, Crypter.ComputeHash(PictureStream), true, null, PictureStream, false);
                }
            }
            return(result);
        }
示例#3
0
        private string GetLayerPicture(ReportComponentBase obj, out float Width, out float Height)
        {
            string result = String.Empty;

            Width  = 0;
            Height = 0;

            if (obj != null)
            {
                if (FPictures)
                {
                    MemoryStream PictureStream = new MemoryStream();
                    System.Drawing.Imaging.ImageFormat FPictureFormat = System.Drawing.Imaging.ImageFormat.Bmp;
                    if (FImageFormat == ImageFormat.Png)
                    {
                        FPictureFormat = System.Drawing.Imaging.ImageFormat.Png;
                    }
                    else if (FImageFormat == ImageFormat.Jpeg)
                    {
                        FPictureFormat = System.Drawing.Imaging.ImageFormat.Jpeg;
                    }
                    else if (FImageFormat == ImageFormat.Gif)
                    {
                        FPictureFormat = System.Drawing.Imaging.ImageFormat.Gif;
                    }

                    Width  = obj.Width == 0 ? obj.Border.LeftLine.Width : obj.Width;
                    Height = obj.Height == 0 ? obj.Border.TopLine.Width : obj.Height;

                    if (Math.Abs(Width) * Zoom < 1 && Zoom > 0)
                    {
                        Width = 1 / Zoom;
                    }

                    if (Math.Abs(Height) * Zoom < 1 && Zoom > 0)
                    {
                        Height = 1 / Zoom;
                    }

                    using (System.Drawing.Image image = new Bitmap((int)(Math.Abs(Width * Zoom)), (int)(Math.Abs(Height * Zoom))))
                    {
                        using (Graphics g = Graphics.FromImage(image))
                        {
                            if (obj is TextObjectBase)
                            {
                                g.Clear(Color.White);
                            }

                            float Left = Width > 0 ? obj.AbsLeft : obj.AbsLeft + Width;
                            float Top  = Height > 0 ? obj.AbsTop : obj.AbsTop + Height;

                            float dx = 0; // (obj.Border.Lines & BorderLines.Left) != 0 ? obj.Border.LeftLine.Width : 0; !!! fix for borders
                            float dy = 0; // (obj.Border.Lines & BorderLines.Top) != 0 ? obj.Border.TopLine.Width : 0;
                            g.TranslateTransform((-Left - dx) * Zoom, (-Top - dy) * Zoom);

                            BorderLines oldLines = obj.Border.Lines;
                            obj.Border.Lines = BorderLines.None;
                            obj.Draw(new FRPaintEventArgs(g, Zoom, Zoom, Report.GraphicCache));
                            obj.Border.Lines = oldLines;
                        }

                        if (FPictureFormat == System.Drawing.Imaging.ImageFormat.Jpeg)
                        {
                            ImageCodecInfo[] codecs = ImageCodecInfo.GetImageEncoders();
                            ImageCodecInfo   ici    = null;
                            foreach (ImageCodecInfo codec in codecs)
                            {
                                if (codec.MimeType == "image/jpeg")
                                {
                                    ici = codec;
                                    break;
                                }
                            }
                            EncoderParameters ep = new EncoderParameters();
                            ep.Param[0] = new EncoderParameter(System.Drawing.Imaging.Encoder.Quality, 95);
                            image.Save(PictureStream, ici, ep);
                        }
                        else
                        {
                            image.Save(PictureStream, FPictureFormat);
                        }
                    }
                    PictureStream.Position = 0;

                    result = HTMLGetImage(0, 0, 0, ExportUtils.Crc32(PictureStream, PictureStream.Length - 128, 128).ToString(), true, null, PictureStream);
                }
            }
            return(result);
        }