private static Byte[] GetImageData(nsIDOMHTMLCanvasElement canvasElement)
		{
			String data = XpcomStringHelper.Get(canvasElement.ToDataURLAs, "image/png", String.Empty);
			if (String.IsNullOrWhiteSpace(data))
			{
				return null;
			}

#if USE_IOSERVICE

			var ioService = Xpcom.GetService<nsIIOService>(Xpcom.NS_IOSERVICE_CONTRACTID);
			nsIChannel channel = ioService.NewChannel(data, null, null);
			nsIInputStream stream = channel.Open();
			try
			{
				Byte[] imageData = null;
				stream.ReadSegments(
					delegate(nsIInputStream inStream, IntPtr closure, IntPtr segment, UInt32 offset, UInt32 count, ref UInt32 writeCount)
					{
						var buffer = new Byte[count];
						Marshal.Copy(segment, buffer, 0, buffer.Length);
						writeCount = count;

						Array.Resize(ref imageData, (imageData != null ? imageData.Length : 0) + buffer.Length);
						Array.Copy(buffer, 0, imageData, imageData.Length - buffer.Length, buffer.Length);
						return nsResult.NS_OK;
					},
					IntPtr.Zero, UInt32.MaxValue);

				return imageData;
			}
			finally
			{
				stream.Close();
				Marshal.ReleaseComObject(stream);
				Marshal.ReleaseComObject(channel);
				Marshal.ReleaseComObject(ioService);
			}

#else

			const String dataPrefix = "data:image/png;base64,";
			if (!data.StartsWith(dataPrefix))
			{
				return null;
			}

			String base64Data = data.Substring(dataPrefix.Length);
			Byte[] imageData = Convert.FromBase64String(base64Data);
			return imageData;

#endif
		}
Exemple #2
0
        /// <summary>
        /// Get byte array with png image of the current browsers Window.
        /// Wpf methods on windows platform don't use a Bitmap :-/
        /// Not captures plugin (Flash,etc...) windows
        /// </summary>
        /// <param name="xOffset"></param>
        /// <param name="yOffset"></param>
        /// <param name="width"></param>
        /// <param name="height"></param>
        /// <returns></returns>
        public byte[] CanvasGetPngImage(uint xOffset, uint yOffset, uint width, uint height)
        {
            if (width == 0)
            {
                throw new ArgumentException("width");
            }

            if (height == 0)
            {
                throw new ArgumentException("height");
            }

            // Use of the canvas technique was inspired by: the abduction! firefox plugin by Rowan Lewis
            // https://addons.mozilla.org/en-US/firefox/addon/abduction/

            // Some opertations fail without a proper JSContext.
            using (AutoJSContext jsContext = new AutoJSContext())
            {
                GeckoCanvasElement canvas = (GeckoCanvasElement)m_browser.Document.CreateElement("canvas");
                canvas.Width  = width;
                canvas.Height = height;

                nsIDOMHTMLCanvasElement        canvasPtr = (nsIDOMHTMLCanvasElement)canvas.DomObject;
                nsIDOMCanvasRenderingContext2D context;
                using (nsAString str = new nsAString("2d"))
                {
                    context = (nsIDOMCanvasRenderingContext2D)canvasPtr.MozGetIPCContext(str);
                }

                using (nsAString color = new nsAString("rgb(255,255,255)"))
                {
                    context.DrawWindow((nsIDOMWindow)m_browser.Window.DomWindow, xOffset, yOffset, width, height, color, 0);
                }

                string data  = canvas.toDataURL("image/png");
                byte[] bytes = Convert.FromBase64String(data.Substring("data:image/png;base64,".Length));
                return(bytes);
            }
        }
Exemple #3
0
 public void TexSubImage2D(UInt32 target, Int32 level, Int32 xoffset, Int32 yoffset, UInt32 format, UInt32 type, nsIDOMHTMLCanvasElement canvas)
 {
     this.CallVoidMethod("texSubImage2D", target, level, xoffset, yoffset, format, type, canvas);
 }
Exemple #4
0
 public void TexImage2D(UInt32 target, Int32 level, UInt32 internalformat, UInt32 format, UInt32 type, nsIDOMHTMLCanvasElement canvas)
 {
     this.CallVoidMethod("texImage2D", target, level, internalformat, format, type, canvas);
 }
		public GeckoCanvasElement(object element) : base(element as nsIDOMHTMLElement)
		{
			this.DOMHTMLElement = element as nsIDOMHTMLCanvasElement;
		}
		internal GeckoCanvasElement(nsIDOMHTMLCanvasElement element) : base(element)
		{
			this.DOMHTMLElement = element;
		}
 public GeckoCanvasElement(object element) : base(element as nsIDOMHTMLElement)
 {
     this.DOMHTMLElement = element as nsIDOMHTMLCanvasElement;
 }
 internal GeckoCanvasElement(nsIDOMHTMLCanvasElement element) : base(element)
 {
     this.DOMHTMLElement = element;
 }
		private static void DrawWindow(nsIDOMHTMLCanvasElement canvasElement, nsIDOMWindow domWindow, Color bgColor, CaptureFlags captureFlags)
		{
			var context = (nsIDOMCanvasRenderingContext2D)canvasElement.GetContext("2d", JsVal.JSVAL_NULL);
			String cssBgColor = String.Format(CssColorFormatInfo.CurrentInfo, "{0:rgba}", bgColor);
			context.DrawWindow(domWindow, 0, 0, canvasElement.Width, canvasElement.Height, cssBgColor, (UInt32)captureFlags);
		}