Esempio n. 1
0
        public static Texture2D ConvertToTexture(System.Drawing.Bitmap b, GraphicsDevice graphicsDevice)
        {
            Texture2D tx = null;

            using (MemoryStream s = new MemoryStream())
            {
                b.Save(s, System.Drawing.Imaging.ImageFormat.Png);
                s.Seek(0, SeekOrigin.Begin);
                tx = Texture2D.FromStream(graphicsDevice, s);
            }
            return(tx);
        }
Esempio n. 2
0
        internal static BitmapSource ConvertToBitmapSource(System.Drawing.Bitmap wfBitmap)
        {
            /*var hBitmap = gdiPlusBitmap.GetHbitmap();
             * return Imaging.CreateBitmapSourceFromHBitmap(hBitmap, IntPtr.Zero, Int32Rect.Empty, BitmapSizeOptions.FromEmptyOptions());*/

            // WPF version of Image
            var bi3 = new BitmapImage();

            bi3.BeginInit();

            // Save to a memory stream...
            var ms = new MemoryStream();

            wfBitmap.Save(ms, ImageFormat.Png);

            // Rewind the stream...
            ms.Seek(0, SeekOrigin.Begin);

            // Tell the WPF image to use this stream...
            bi3.StreamSource = ms;
            bi3.EndInit();

            return(bi3);
        }
        internal PageImage GetPageImage(Report rpt, Row row)
        {
            string mtype = null;
            Stream strm  = null;

            System.Drawing.Bitmap im = null;
            PageImage             pi = null;

            WorkClass wc = GetWC(rpt);

            if (wc.PgImage != null)
            {                              // have we already generated this one
                                           // reuse most of the work; only position will likely change
                pi      = new PageImage(wc.PgImage.ImgFormat, wc.PgImage.ImageData, wc.PgImage.SamplesW, wc.PgImage.SamplesH);
                pi.Name = wc.PgImage.Name; // this is name it will be shared under
                return(pi);
            }

            try
            {
                strm = GetImageStream(rpt, row, out mtype);
                if (strm == null)
                {
                    rpt.rl.LogError(4, string.Format("Unable to load image {0}.",
                                                     this._Value == null?"": this._Value.EvaluateString(rpt, row)));
                    return(null);
                }
                im = Bitmap.FromStream(strm);
                int          height = im.Height;
                int          width  = im.Width;
                MemoryStream ostrm  = new MemoryStream();
                ImageFormat  imf;
                //				if (mtype.ToLower() == "image/jpeg")    //TODO: how do we get png to work
                //					imf = ImageFormatType.Jpeg;
                //				else

                imf = ImageFormat.Jpeg;
                System.Drawing.Imaging.ImageCodecInfo[] info;
                info = ImageCodecInfo.GetImageEncoders();
                EncoderParameters encoderParameters;
                encoderParameters          = new EncoderParameters(1);
                encoderParameters.Param[0] = new EncoderParameter(System.Drawing.Imaging.Encoder.Quality, ImageQualityManager.EmbeddedImageQuality);
                System.Drawing.Imaging.ImageCodecInfo codec = null;
                for (int i = 0; i < info.Length; i++)
                {
                    if (info[i].FormatDescription == "JPEG")
                    {
                        codec = info[i];
                        break;
                    }
                }
                im.Save(ostrm, codec, encoderParameters);

                byte[] ba = ostrm.ToArray();
                ostrm.Close();
                pi    = new PageImage(imf, ba, width, height);
                pi.SI = new StyleInfo();                        // this will just default everything
                if (_BackgroundRepeat != null)
                {
                    string r = _BackgroundRepeat.EvaluateString(rpt, row).ToLower();
                    switch (r)
                    {
                    case "repeat":
                        pi.Repeat = ImageRepeat.Repeat;
                        break;

                    case "repeatx":
                        pi.Repeat = ImageRepeat.RepeatX;
                        break;

                    case "repeaty":
                        pi.Repeat = ImageRepeat.RepeatY;
                        break;

                    case "norepeat":
                    default:
                        pi.Repeat = ImageRepeat.NoRepeat;
                        break;
                    }
                }
                else
                {
                    pi.Repeat = ImageRepeat.Repeat;
                }

                if (_ConstantImage)
                {
                    wc.PgImage = pi;
                    // create unique name; PDF generation uses this to optimize the saving of the image only once
                    pi.Name = "pi" + Interlocked.Increment(ref Parser.Counter).ToString();                      // create unique name
                }
            }
            finally
            {
                if (strm != null)
                {
                    strm.Close();
                }
                if (im != null)
                {
                    im.Dispose();
                }
            }
            return(pi);
        }