Ejemplo n.º 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 (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);
        }