Represents an image
Inheritance: Image
Esempio n. 1
0
		public TextureBrushesSection2()
		{
			image = TestIcons.Textures;
			var drawable = new BufferedDrawable();
			var layout = new DynamicLayout { DefaultSpacing = new Size(5, 5), Padding = new Padding(10) };
			layout.AddSeparateRow(null, drawable.Checkbox(), null);
			layout.Add(drawable);
			this.Content = layout;

			var w = image.Size.Width / 3; // same as height
			var img = image.Clone(new Rectangle(w, w, w, w));
			var textureBrush = new TextureBrush(img);
			var solidBrush = new SolidBrush(Colors.Blue);
			var linearGradientBrush = new LinearGradientBrush(Colors.White, Colors.Black, PointF.Empty, new PointF(0, 100));
			var font = SystemFonts.Default();
			drawable.BackgroundColor = Colors.Green;
			drawable.MouseMove += HandleMouseMove;
			drawable.MouseDown += HandleMouseMove;

			drawable.Paint += (s, e) =>
			{
				var graphics = e.Graphics;
				graphics.DrawText(font, Colors.White, 3, 3, "Move the mouse in this area to move the shapes.");
				// texture brushes
				var temp = location;
				DrawShapes(textureBrush, temp, img.Size, graphics);
				// solid brushes
				temp = temp + new PointF(200, 0);
				DrawShapes(solidBrush, temp, img.Size, graphics);
				// linear gradient brushes
				temp = temp + new PointF(200, 0);
				DrawShapes(linearGradientBrush, temp, img.Size, graphics);
			};
		}
Esempio n. 2
0
		void DrawTest(Bitmap image)
		{
			// should always ensure .Dispose() is called when you are done with a Graphics or BitmapData object.

			// Test setting pixels directly
			using (var bd = image.Lock())
			{
				var sz = image.Size / 5;
				for (int x = sz.Width; x < sz.Width * 2; x++)
					for (int y = sz.Height; y < sz.Height * 2; y++)
						bd.SetPixel(x, y, Colors.Green);
			}

			// Test using Graphics object
			using (var graphics = new Graphics(image))
			{
				graphics.DrawLine(Pens.Blue, Point.Empty, new Point(image.Size));
				graphics.DrawRectangle(Pens.Blue, new Rectangle(image.Size - 1));
			}

			// should be able to set pixels after using graphics object
			using (var bd = image.Lock())
			{
				var sz = image.Size / 5;
				for (int x = sz.Width * 3; x < sz.Width * 4; x++)
					for (int y = sz.Height * 3; y < sz.Height * 4; y++)
						bd.SetPixel(x, y, Colors.Red);
			}

		}
Esempio n. 3
0
        /// <summary>
        /// Sets the specified image.
        /// </summary>
        /// <param name="image">Image to display.</param>
        public void SetImage(Bgr<byte>[,] image)
        {
            if (bmp == null || bmp.Width != image.Width() || bmp.Height != image.Height())
            {
                bmp = new Bitmap(image.Width(), image.Height(), PixelFormat.Format24bppRgb);
            }

            BitmapData bmpData = bmp.Lock();
            if (bmpData.BytesPerPixel != image.ColorInfo().Size)
            {
                bmpData.Dispose();
                bmpData = null;
                bmp = new Bitmap(image.Width(), image.Height(), PixelFormat.Format24bppRgb);
            }

            bmpData = bmpData ?? bmp.Lock();
            using (var uIm = image.Lock())
            {
                Copy.UnsafeCopy2D(uIm.ImageData, bmpData.Data, uIm.Stride, bmpData.ScanWidth, uIm.Height);
            }

            bmpData.Dispose();

            imageView.Image = bmp;

            if (ScaleForm)
                ClientSize = new Size(image.Width(), image.Height());
        }
Esempio n. 4
0
		Control LoadFromStream ()
		{
			var resourceStream = GetType().Assembly.GetManifestResourceStream ("Eto.Test.TestImage.png");

			var image = new Bitmap (resourceStream);

			return new ImageView { Image = image };
		}
Esempio n. 5
0
        Control LoadFromStream()
        {
            var resourceStream = Resources.GetResource ("Eto.Test.TestImage.png");

            var image = new Bitmap (resourceStream);

            return new ImageView { Image = image };
        }
Esempio n. 6
0
		Control CreateCustom32Alpha ()
		{
			var image = new Bitmap (100, 100, PixelFormat.Format32bppRgba);

			// should always ensure .Dispose() is called when you are done with a Graphics object
			using (var graphics = new Graphics (image)) {
				graphics.DrawLine (Color.Blue, Point.Empty, new Point (image.Size));
				graphics.DrawRectangle (Color.Black, new Rectangle (image.Size));
			}

			return new ImageView { Image = image };
		}
Esempio n. 7
0
        public static ed.Image ToEto(this IImage cImage)
        {
            var eImage = new ed.Bitmap(cImage.Size.Width, cImage.Size.Height, ed.PixelFormat.Format32bppRgba);

            using (var eData = eImage.Lock())
            {
                if (eData.ScanWidth != cImage.Size.Width * 4)
                {
                    throw new NotImplementedException();
                }
                var rawData = cImage.GetRawData();
                Marshal.Copy(rawData, 0, eData.Data, rawData.Length);
            }
            return(eImage);
        }
Esempio n. 8
0
        private ed.Bitmap LockEtoBitmap()
        {
            sdGraphics?.Flush();

            var sdData        = sdBuffer.LockBits(new sd.Rectangle(0, 0, sdBuffer.Width, sdBuffer.Height), sd.Imaging.ImageLockMode.ReadOnly, sdBuffer.PixelFormat);
            var bytesPerPixel = ((int)sdBuffer.PixelFormat >> 11) & 31;
            var byteLength    = sdData.Height * sdData.Width * bytesPerPixel;

            var etoBuffer = new ed.Bitmap(sdBuffer.Width, sdBuffer.Height, ed.PixelFormat.Format32bppRgba);
            var etoData   = etoBuffer.Lock();

            if (sdData.Stride < 0)
            {
                throw new Exception("Negative stride value encountered!");
            }

            unsafe
            {
                if (sdData.Stride > 0 && sdData.Stride == sdData.Width * bytesPerPixel)
                {
                    Buffer.MemoryCopy((void *)sdData.Scan0, (void *)etoData.Data, byteLength, byteLength);
                }
                else // Slightly slower route using the given stride width
                {
                    var switchColors     = MColor.ShouldSwitchColors;
                    var scan             = (byte *)sdData.Scan0;
                    var bytesPerScanLine = sdData.Width * bytesPerPixel;
                    Parallel.For(0, sdData.Height, i =>
                    {
                        var line = scan + (i * sdData.Stride);
                        for (int j = 0; j < bytesPerScanLine; j += bytesPerPixel)
                        {
                            var b = line[j];
                            var g = line[j + 1];
                            var r = line[j + 2];
                            var a = line[j + 3];
                            var c = ed.Color.FromArgb(switchColors ? b : r, g, switchColors ? r : b, a);
                            etoData.SetPixel(j / bytesPerPixel, i, c);
                        }
                    });
                }
            }

            etoData.Dispose();
            sdBuffer.UnlockBits(sdData);

            return(etoBuffer);
        }
Esempio n. 9
0
		private void CreateXamlRenderTarget(SizeF size)
		{
			if (!double.IsNaN(size.Width) &&
				!double.IsNaN(size.Height) &&
				!size.IsEmpty &&
				(image == null ||
				 image.Width != size.Width ||
				 image.Height != size.Height))
			{
				if (image != null)
					image.Dispose();

				image = new Bitmap(new Size((int)size.Width, (int)size.Height), PixelFormat.Format32bppRgba);
				CreateWicTarget();
			}
		}
Esempio n. 10
0
		Control CreateImage (ImageInterpolation interpolation)
		{
			var resourceStream = GetType().Assembly.GetManifestResourceStream ("Eto.Test.TestImage.png");

			var image = new Bitmap (resourceStream);
			var drawable = new Drawable { Size = new Size(250, 160) };

			drawable.Paint += (sender, pe) => {
				pe.Graphics.ImageInterpolation = interpolation;
				pe.Graphics.DrawImage (image, 0, 0, 20, 20);
				pe.Graphics.DrawImage (image, 0, 20, 50, 50);
				pe.Graphics.DrawImage (image, 0, 70, 100, 100);
				pe.Graphics.DrawImage (image, 120, 0, 300, 300);
			};

			return drawable;
		}
Esempio n. 11
0
        /// <summary>
        /// Sets the specified image.
        /// </summary>
        /// <param name="image">Image to display.</param>
        public void SetImage(Bgr<byte>[,] image)
        {
            if (bmp == null || bmp.Width != image.Width() || bmp.Height != image.Height())
            {
                bmp = new Bitmap(image.Width(), image.Height(), PixelFormat.Format24bppRgb);
            }

            using (BitmapData bmpData = bmp.Lock())
            using (var uIm = image.Lock())
            {
                Copy.UnsafeCopy2D(uIm.ImageData, bmpData.Data, uIm.Stride, bmpData.ScanWidth, uIm.Height);
            }

            PictureBox.Image = bmp;

            if (ScaleForm)
                ClientSize = new Size(image.Width(), image.Height());
        }
Esempio n. 12
0
		static void ValidateImages(Bitmap image, Bitmap clone, Rectangle? rect = null)
		{
			var testRect = rect ?? new Rectangle(image.Size);
			using (var imageData = image.Lock())
			using (var cloneData = clone.Lock())
			{
				if (imageData.BytesPerPixel == 1)
				{
					unsafe
					{
						// test pixels directly
						byte* imageptr = (byte*)imageData.Data;
						imageptr += testRect.Top * imageData.ScanWidth + testRect.Left;
						byte* cloneptr = (byte*)cloneData.Data;
						for (int y = 0; y < testRect.Height; y++)
						{
							byte* imagerow = imageptr;
							byte* clonerow = cloneptr;
							for (int x = 0; x < testRect.Width; x++)
							{
								var imagePixel = *(imagerow++);
								var clonePixel = *(clonerow++);
								if (imagePixel != clonePixel)
								{
									Assert.Fail("Image pixels are not the same at position {0},{1} (source: {2}, clone: {3})", x, y, imagePixel, clonePixel);
								}
							}
							imageptr += imageData.ScanWidth;
							cloneptr += cloneData.ScanWidth;
						}
					}
				}
				else
					for (int x = 0; x < testRect.Width; x++)
						for (int y = 0; y < testRect.Height; y++)
						{
							var imagePixel = imageData.GetPixel(x + testRect.Left, y + testRect.Top);
							var clonePixel = cloneData.GetPixel(x, y);
							if (imagePixel != clonePixel)
								Assert.Fail("Image pixels are not the same at position {0},{1} (source: {2}, clone: {3})", x, y, imagePixel, clonePixel);
						}
			}
		}
Esempio n. 13
0
		protected sealed override void OnPaint(PaintEventArgs e)
		{
			if (EnableDoubleBuffering)
			{
				var screen = ParentWindow.Screen;
				var scale = screen.RealScale / screen.Scale;
				renderSize = Size.Round(e.ClipRectangle.Size * scale);
				if (bitmap == null ||
					bitmap.Size.Width < renderSize.Width ||
					bitmap.Size.Height < renderSize.Height)
				{
					if (bitmap != null)
						bitmap.Dispose();

					bitmap = new Bitmap(renderSize, PixelFormat.Format32bppRgba);
				}
				var bitmapGraphics = new Graphics(bitmap);
				bitmapGraphics.Clear(Brushes.Cached(BackgroundColor));
				bitmapGraphics.ScaleTransform(scale);
				bitmapGraphics.TranslateTransform(-e.ClipRectangle.Location);
				bitmapGraphics.SetClip(e.ClipRectangle * scale); // should be affected by transform

				var childArgs = new PaintEventArgs(bitmapGraphics, e.ClipRectangle);
				base.OnPaint(childArgs);

				OnBufferedPaint(childArgs);

				bitmapGraphics.Dispose();
				bitmapGraphics = null;
				e.Graphics.DrawImage(bitmap, new RectangleF(renderSize), e.ClipRectangle);
				if (Platform.IsWpf)
				{
					// wpf runs out of resources fast here, so we garbage collect
					GC.Collect();
				}
			}
			else
			{
				base.OnPaint(e);
				OnBufferedPaint(e);
			}
		}
Esempio n. 14
0
		public Graphics BeginDraw(PaintEventArgs e)
		{
			if (UseOffScreenBitmap)
			{
				if (OffscreenBitmap == null ||
					OffscreenBitmap.Size.Width < e.ClipRectangle.Width ||
					OffscreenBitmap.Size.Height < e.ClipRectangle.Height)
				{
					if (OffscreenBitmap != null)
						OffscreenBitmap.Dispose();

					OffscreenBitmap = new Bitmap(Size.Round(e.ClipRectangle.Size), PixelFormat.Format32bppRgba);
				}
				bitmapGraphics = new Graphics(OffscreenBitmap);
				bitmapGraphics.TranslateTransform(-e.ClipRectangle.Location);
				bitmapGraphics.SetClip(e.ClipRectangle);
				bitmapGraphics.Clear(Brushes.Cached(drawable.BackgroundColor));
				return bitmapGraphics;
			}
			return e.Graphics;
		}
Esempio n. 15
0
        public override async Task<Bitmap> GetIcon()
        {
            if (string.IsNullOrEmpty(Gravatar))
                return DefaultUserIcon;

            var url = string.Format("http://www.gravatar.com/avatar/{0}?s=16&d=404", Gravatar);
            //Debug.Print("Getting icon {0}", url);
            var request = HttpWebRequest.Create(url);
            var response = await Task.Factory.FromAsync<WebResponse>(request.BeginGetResponse, request.EndGetResponse, null);
            try
            {
                using (var stream = response.GetResponseStream ())
                {
                    if (Generator.Current.IsWpf)
                    {
                        using (var ms = new MemoryStream ())
                        {
                            stream.CopyTo(ms);
                            ms.Position = 0;
                            return new Bitmap(ms);
                        }
                    }
                    else
                    {
                        var bmp = new Bitmap(stream);
                        //Debug.Print ("Got Image for user '{0}', {1}", this.Name, url);
                        return bmp;
                    }
                }
            }
            catch (Exception ex)
            {
                Debug.Print("Error getting Icon for user '{0}', {1}, {2}", this.Name, url, ex);
                return DefaultUserIcon;
            }
        }
Esempio n. 16
0
		Control DrawImageToRect()
		{
			var image64 = TestIcons.Textures;

			var bitmap = new Bitmap(new Size(105, 105), PixelFormat.Format32bppRgba);
			using (var g = new Graphics(bitmap))
			{
				// Draw the "5" portion of the texture at a smaller size at the origin.
				g.DrawImage(image64, new RectangleF(80, 80, 80, 80), new RectangleF(0, 0, 32, 32));
				// draw two rulers to indicate how big the green image should be
				g.SaveTransform();
				g.MultiplyTransform(Matrix.Create(1, 0, 0, 1, 0, 70));
				DrawRuler(32, g, Colors.Blue);
				g.RestoreTransform();

				g.SaveTransform();
				g.MultiplyTransform(Matrix.Create(0, 1, 1, 0, 70, 0));
				DrawRuler(32, g, Colors.Blue);
				g.RestoreTransform();
			}
			return new DrawableImageView { Image = bitmap };
		}
Esempio n. 17
0
		Control DrawImageToRect()
		{
			var image64 = new Bitmap(new Size(64, 64), PixelFormat.Format32bppRgba);
			var image32 = new Bitmap(new Size(32, 32), PixelFormat.Format32bppRgba);

			using (var g = new Graphics(image64))
				g.Clear(Brushes.Cached(Colors.Green) as SolidBrush);

			using (var g = new Graphics(image32))
				g.Clear(Brushes.Cached(Colors.Blue) as SolidBrush);

			var bitmap = new Bitmap(new Size(105, 105), PixelFormat.Format32bppRgba);
			using (var g = new Graphics(bitmap))
			{
				// draw the big image at the origin, but with a smaller dest rect
				g.DrawImage(image64, new RectangleF(0, 0, 32, 32), new RectangleF(0, 0, 32, 32));
				// draw two guide images to indicate how big the green image should be
				g.DrawImage(image32, new PointF(70, 0));
				g.DrawImage(image32, new PointF(0, 70));
			}
			return new DrawableImageView { Image = bitmap };
		}
Esempio n. 18
0
		Control CloneTiles()
		{
			// Creates a duplicate of the bitmap by cloning tiles of it
			// and drawing them in the same location in the duplicate.
			var image = TestIcons.TestImage();
			var bitmap = new Bitmap(new Size(image.Size), PixelFormat.Format32bppRgba);
			var tile = 64; // the test image is 128x128 so this produces 4 tiles.
			using (var g = new Graphics(bitmap))
			{
				for (var x = 0; x < image.Width; x += tile)
					for (var y = 0; y < image.Height; y += tile)
					{
						var clone = image.Clone(new Rectangle(x, y, tile, tile));
						g.DrawImage(clone, x, y);
					}
			}
			return new DrawableImageView { Image = bitmap };
		}
Esempio n. 19
0
		/// <summary>
		/// Initializes a new instance of the Generator class to draw on the given <paramref name="image"/>
		/// </summary>
		/// <param name="generator">Generator to create this graphics context for</param>
		/// <param name="image">Image to draw on using this graphics context</param>
		public Graphics (Generator generator, Bitmap image)
			: base (generator, typeof (IGraphics))
		{
			this.handler = (IGraphics)Handler;
			this.handler.CreateFromImage (image);
		}
Esempio n. 20
0
		public void CreateFromImage(Bitmap image)
		{

		}
Esempio n. 21
0
		/// <summary>
		/// Initializes a new instance of the <see cref="Eto.Drawing.IconFrame"/> class.
		/// </summary>
		/// <param name="scale">Scale of logical to physical pixels.</param>
		/// <param name="bitmap">Bitmap for the frame</param>
		public IconFrame(float scale, Bitmap bitmap)
			: this(scale)
		{
			ControlObject = Handler.Create(this, bitmap);
		}
Esempio n. 22
0
		Image CreateImage()
		{
			var image = new Bitmap(200, 200, PixelFormat.Format32bppRgba);
			using (var graphics = new Graphics(image))
			{
				DrawSample(graphics);
			}
			return image;
		}
Esempio n. 23
0
        public void RenderScene(string scenename)
        {
            var dev = Device.FirstGpu;
            Console.WriteLine("Using device {0} {1}", dev.Name, dev.Description);

            var scene_params = new SceneParameters(Client, ShadingSystem.SVM, BvhType.Static, false, false, false);
            var scene = new Scene(Client, scene_params, dev);

            var xml = new CSyclesXmlReader(Client, scenename);
            xml.Parse(false);
            var width = (uint)scene.Camera.Size.Width;
            var height = (uint)scene.Camera.Size.Height;

            var session_params = new SessionParameters(Client, dev)
            {
                Experimental = false,
                Samples = (int) samples,
                TileSize = new Size(64, 64),
                StartResolution = 64,
                Threads = (uint)(dev.IsCpu ? 0 : 0),
                ShadingSystem = ShadingSystem.SVM,
                Background = true,
                ProgressiveRefine = false,
                Progressive = false,
                TileOrder = TileOrder.HilbertSpiral
            };
            var Session = new Session(Client, session_params, scene);
            Session.Reset(width, height, samples);

            g_write_render_tile_callback = WriteRenderTileCallback;
            Session.WriteTileCallback = g_write_render_tile_callback;

            /*if (!silent)
            {
                Session.UpdateCallback = g_update_callback;
                Session.UpdateTileCallback = g_update_render_tile_callback;
                Session.WriteTileCallback = g_write_render_tile_callback;
            }
            CSycles.set_logger(Client.Id, g_logger_callback);
            */

            Session.Start();
            Session.Wait();

            uint bufsize;
            uint bufstride;
            CSycles.session_get_buffer_info(Client.Id, Session.Id, out bufsize, out bufstride);
            var pixels = CSycles.session_copy_buffer(Client.Id, Session.Id, bufsize);

            var bmp = new ed.Bitmap((int)width, (int)height, Eto.Drawing.PixelFormat.Format32bppRgba);
            for (var x = 0; x < width; x++)
            {
                for (var y = 0; y < height; y++)
                {
                    var i = y * (int)width * 4 + x * 4;
                    bmp.SetPixel(x, y, new ed.Color(Math.Min(pixels[i], 1.0f), Math.Min(pixels[i + 1], 1.0f), Math.Min(pixels[i + 2], 1.0f), Math.Min(pixels[i + 3], 1.0f)));
                }
            }
            bmp.Save("test.png", Eto.Drawing.ImageFormat.Png);

            Result = bmp;

            Session.Destroy();

            Console.WriteLine("Cleaning up :)");
        }
Esempio n. 24
0
		/// <summary>
		/// Initializes a new instance of the Generator class to draw on the given <paramref name="image"/>
		/// </summary>
		/// <param name="image">Image to draw on using this graphics context</param>
		public Graphics (Bitmap image)
			: this(image.Generator, image)
		{
		}
Esempio n. 25
0
		Control CreateCustom24()
		{
			var image = new Bitmap(100, 100, PixelFormat.Format24bppRgb);

			DrawTest(image);

			return new DrawableImageView { Image = image };
		}
Esempio n. 26
0
		public object Create(IconFrame frame, Bitmap bitmap)
		{
			return bitmap;
		}
Esempio n. 27
0
		Control CreateCustom32Alpha()
		{
			var image = new Bitmap(100, 100, PixelFormat.Format32bppRgba);

			DrawTest(image);
			return new DrawableImageView { Image = image };
		}
Esempio n. 28
0
        /// <summary>
        /// 
        /// </summary>
        /// <param name="gfx"></param>
        /// <param name="image"></param>
        /// <param name="dx"></param>
        /// <param name="dy"></param>
        /// <param name="db"></param>
        /// <param name="r"></param>
        public void Draw(object gfx, XImage image, double dx, double dy, ImmutableArray<ShapeProperty> db, Record r)
        {
            var _gfx = gfx as Graphics;

            var rect = CreateRect(
                image.TopLeft,
                image.BottomRight,
                dx, dy);

            var srect = new RectangleF(
                _scaleToPage(rect.X),
                _scaleToPage(rect.Y),
                _scaleToPage(rect.Width),
                _scaleToPage(rect.Height));

            if (image.IsFilled)
            {
                Brush brush = ToSolidBrush(image.Style.Fill);
                _gfx.FillRectangle(
                    brush,
                    srect);
                brush.Dispose();
            }

            if (image.IsStroked)
            {
                Pen pen = ToPen(image.Style, _scaleToPage);
                _gfx.DrawRectangle(
                    pen,
                    srect);
                pen.Dispose();
            }

            if (_enableImageCache
                && _biCache.ContainsKey(image.Path))
            {
                _gfx.DrawImage(_biCache[image.Path], srect);
            }
            else
            {
                if (_state.ImageCache == null || string.IsNullOrEmpty(image.Path))
                    return;

                var bytes = _state.ImageCache.GetImage(image.Path);
                if (bytes != null)
                {
                    var bi = new Bitmap(bytes);

                    if (_enableImageCache)
                        _biCache[image.Path] = bi;

                    _gfx.DrawImage(bi, srect);

                    if (!_enableImageCache)
                        bi.Dispose();
                }
            }
        }
Esempio n. 29
0
File: Icon.cs Progetto: picoe/Eto
		/// <summary>
		/// Initializes a new instance of the <see cref="Eto.Drawing.Icon"/> class with the specified bitmap.
		/// </summary>
		/// <remarks>
		/// This is used when you want to create an icon with a single bitmap frame with the specified logical scale.
		/// </remarks>
		/// <param name="scale">Logical pixel scale of the specified bitmap.</param>
		/// <param name="bitmap">Bitmap for the frame.</param>
		public Icon(float scale, Bitmap bitmap)
			: this(new IconFrame(scale, bitmap))
		{
		}
Esempio n. 30
0
 public void Create(Bitmap b)
 {
     throw new NotImplementedException();
 }
Esempio n. 31
0
		public void CreateFromImage(Bitmap image)
		{
			var handler = image.Handler as BitmapHandler;
			SourceImage = image;
#if OSX
			var rep = handler.Control.Representations().OfType<NSBitmapImageRep>().FirstOrDefault();
			if (rep.BitsPerPixel != 32)
			{
				// CoreGraphics only supports drawing to 32bpp, create a new 32-bpp image and copy back when disposed or flushed.
				DrawingImage = new Bitmap(image.Width, image.Height, PixelFormat.Format32bppRgb);
				handler = DrawingImage.Handler as BitmapHandler;
				rep = handler.Control.Representations().OfType<NSBitmapImageRep>().FirstOrDefault();
			}
			graphicsContext = NSGraphicsContext.FromBitmap(rep);

			graphicsContext = graphicsContext.IsFlipped ? graphicsContext : NSGraphicsContext.FromGraphicsPort(graphicsContext.GraphicsPortHandle, true);
			disposeContext = true;
			Control = graphicsContext.GraphicsPort;
			PointsPerPixel = (float)(rep.PixelsWide / handler.Control.Size.Width);
#elif IOS
			var cgimage = handler.Control.CGImage;
			Control = new CGBitmapContext(handler.Data.MutableBytes, cgimage.Width, cgimage.Height, cgimage.BitsPerComponent, cgimage.BytesPerRow, cgimage.ColorSpace, cgimage.BitmapInfo);
			PointsPerPixel = (float)(cgimage.Width / handler.Control.Size.Width);
#endif

			height = image.Size.Height;
			SetDefaults();
			InitializeContext(true);
			if (DrawingImage != null && SourceImage != null)
			{
				// draw source image onto context, when source is incompatible for CoreGraphics drawing.
				DrawImage(SourceImage, 0, 0);
			}
		}
Esempio n. 32
0
        public void RenderScene(string scenename)
        {
            var dev = Device.FirstGpu;

            Console.WriteLine("Using device {0} {1}", dev.Name, dev.Description);

            var scene_params = new SceneParameters(Client, ShadingSystem.SVM, BvhType.Static, false, false, false);
            var scene        = new Scene(Client, scene_params, dev);

            var xml = new CSyclesXmlReader(Client, scenename);

            xml.Parse(false);
            var width  = (uint)scene.Camera.Size.Width;
            var height = (uint)scene.Camera.Size.Height;

            var session_params = new SessionParameters(Client, dev)
            {
                Experimental      = false,
                Samples           = (int)samples,
                TileSize          = new Size(64, 64),
                StartResolution   = 64,
                Threads           = (uint)(dev.IsCpu ? 0 : 0),
                ShadingSystem     = ShadingSystem.SVM,
                Background        = true,
                ProgressiveRefine = false,
                Progressive       = false,
                TileOrder         = TileOrder.HilbertSpiral
            };
            var Session = new Session(Client, session_params, scene);

            Session.Reset(width, height, samples);

            g_write_render_tile_callback = WriteRenderTileCallback;
            Session.WriteTileCallback    = g_write_render_tile_callback;

            /*if (!silent)
             * {
             *      Session.UpdateCallback = g_update_callback;
             *      Session.UpdateTileCallback = g_update_render_tile_callback;
             *      Session.WriteTileCallback = g_write_render_tile_callback;
             * }
             * CSycles.set_logger(Client.Id, g_logger_callback);
             */

            Session.Start();
            Session.Wait();

            uint bufsize;
            uint bufstride;

            CSycles.session_get_buffer_info(Client.Id, Session.Id, out bufsize, out bufstride);
            var pixels = CSycles.session_copy_buffer(Client.Id, Session.Id, bufsize);

            var bmp = new ed.Bitmap((int)width, (int)height, Eto.Drawing.PixelFormat.Format32bppRgba);

            for (var x = 0; x < width; x++)
            {
                for (var y = 0; y < height; y++)
                {
                    var i = y * (int)width * 4 + x * 4;
                    bmp.SetPixel(x, y, new ed.Color(Math.Min(pixels[i], 1.0f), Math.Min(pixels[i + 1], 1.0f), Math.Min(pixels[i + 2], 1.0f), Math.Min(pixels[i + 3], 1.0f)));
                }
            }
            bmp.Save("test.png", Eto.Drawing.ImageFormat.Png);

            Result = bmp;

            Session.Destroy();

            Console.WriteLine("Cleaning up :)");
        }
Esempio n. 33
0
		Control CloneRectangle()
		{
			var image = TestIcons.TestImage;
			var bitmap = new Bitmap(image.Size, PixelFormat.Format32bppRgba);
			using (var g = new Graphics(bitmap))
			{
				foreach (var tile in GetTiles(image))
				{
					using (var clone = image.Clone(tile))
						g.DrawImage(clone, tile.X, tile.Y);
				}
			}
			return new DrawableImageView { Image = bitmap };
		}