# Create image from UX Panel

**URL:** <https://forums.fusetools.com/t/create-image-from-ux-panel/3615>\
**Category:** Feature Suggestions\
**Created:** [November 4, 2016, 12:51am UTC](https://forums.fusetools.com/t/create-image-from-ux-panel/3615 "2016-11-04T00:51:12Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![kevin](https://avatars.discourse-cdn.com/v4/letter/k/2acd7d/32.png) [@kevin](https://forums.fusetools.com/u/kevin)\
**Post date:** [November 4, 2016, 12:51am UTC](https://forums.fusetools.com/t/create-image-from-ux-panel/3615/1 "2016-11-04T00:51:12Z")

</div>

Creating a Image from UX Panels in JS? (like a screenshot i suppose)

---

<div class="post-metadata">

**Author:** ![Emil\_Sandsto](https://yyz1.discourse-cdn.com/flex035/user_avatar/forums.fusetools.com/emil_sandsto/32/523_2.png) [@Emil\_Sandsto](https://forums.fusetools.com/u/Emil_Sandsto)\
**Post date:** [November 4, 2016, 3:41pm UTC](https://forums.fusetools.com/t/create-image-from-ux-panel/3615/2 "2016-11-04T15:41:56Z")

</div>

Hi, I have made an API for that, you can find it on github:

> **[Tapped/CapturePanel-Fuse](https://github.com/Tapped/CapturePanel-Fuse)**
>
> CapturePanel-Fuse - A panel that can be used to capture a snapshot of the underlying UX tree

Use `MainView.ux` as the reference to how the API is used. It supports iOS, macOS, Windows and Android.

---

<div class="post-metadata">

**Author:** ![kevin](https://avatars.discourse-cdn.com/v4/letter/k/2acd7d/32.png) [@kevin](https://forums.fusetools.com/u/kevin)\
**Post date:** [November 5, 2016, 12:20pm UTC](https://forums.fusetools.com/t/create-image-from-ux-panel/3615/3 "2016-11-05T12:20:50Z")

</div>

sweet ill have a look 😃

---

<div class="post-metadata">

**Author:** ![kevin](https://avatars.discourse-cdn.com/v4/letter/k/2acd7d/32.png) [@kevin](https://forums.fusetools.com/u/kevin)\
**Post date:** [November 7, 2016, 2:41pm UTC](https://forums.fusetools.com/t/create-image-from-ux-panel/3615/4 "2016-11-07T14:41:23Z")

</div>

Hi Emil theres a error when compiling for iOS

```
CapturePanel.uno(91.13): E3107: 'JpegSaver' does not contain a member called 'ByteArrayRgbaToJpeg'. Could you be missing a package reference?
/CapturePanel.uno(91,14,91,33): Error E3107: 'JpegSaver' does not contain a member called 'ByteArrayRgbaToJpeg'. Could you be missing a package reference?
```

---

<div class="post-metadata">

**Author:** ![kevin](https://avatars.discourse-cdn.com/v4/letter/k/2acd7d/32.png) [@kevin](https://forums.fusetools.com/u/kevin)\
**Post date:** [November 8, 2016, 4:50pm UTC](https://forums.fusetools.com/t/create-image-from-ux-panel/3615/5 "2016-11-08T16:50:54Z")

</div>

Hi it seems to work in iOS now 😃 one last question, when using ImageTools:

```
function capture() {
  capturePanel.capture(function(file) {
    capturedImg.value = file;
	ImageTools.getBase64FromImage(file).then(function(base64Image) { console.log("The base64 encoded image is \"" + base64Image + "\""); });
  });
}; 

```

I’m getting this error :

```
  LOG: /private/var/mobile/Containers/Data/Application/329CC89F-2356-409B-B8C3-69DBAD099E4D/tmp/579DDAF6-88AD-4F4F-8203-24CA6FCE3E9A-2742-0000024B8D5D8024.jpg

  LOG: Fuse.Scripting.ScriptException: 
         at Fuse.Scripting.JavaScriptCore.Context.OnError(Fuse.Scripting.JavaScriptCore.JSValueRef)
         at Fuse.Scripting.JavaScriptCore.JSObjectRef.CallAsFunction(Fuse.Scripting.JavaScriptCore.JSContextRef,Fuse.Scripting.JavaScriptCore.JSObjectRef,Fuse.Scripting.JavaScriptCore.JSValueRef[],Uno.Action<Fuse.Scripting.JavaScriptCore.JSValueRef>)
         at Fuse.Scripting.JavaScriptCore.Function.Call(object[])
         at CapturePanel.Draw(Fuse.DrawContext)
         at Fuse.Elements.Element.DrawNonUnderlayChildren(Fuse.DrawContext)
         at Fuse.Elements.Element.DrawWithChildren(Fuse.DrawContext)
         at Fuse.Elements.Element.CompositEffects(Fuse.DrawContext)
         at Fuse.Elements.Element.Composit(Fuse.DrawContext)
         at Fuse.Elements.Element.Draw(Fuse.DrawContext)
         at Fuse.Elements.Element.DrawNonUnderlayChildren(Fuse.DrawContext)
         at Fuse.Elements.Element.DrawWithChildren(Fuse.DrawContext)
         at Fuse.Elements.Element.CompositEffects(Fuse.DrawContext)
         at Fuse.Elements.Element.Composit(Fuse.DrawContext)
         at Fuse.Elements.Element.Draw(Fuse.DrawContext)
         at Fuse.Elements.Element.DrawNonUnderlayChildren(Fuse.DrawContext)
         at Fuse.Elements.Element.DrawWithChildren(Fuse.DrawContext)
         at Fuse.Elements.Element.CompositEffects(Fuse.DrawContext)
         at Fuse.Elements.Element.Composit(Fuse.DrawContext)
         at Fuse.Elements.Element.Draw(Fuse.DrawContext)
         at Fuse.Elements.Element.DrawNonUnderlayChildren(Fuse.DrawContext)
         at Fuse.Elements.Element.DrawWithChildren(Fuse.DrawContext)
         at Fuse.Controls.GraphicsView.DrawWithChildren(Fuse.DrawContext)
         at Fuse.Elements.Element.CompositEffects(Fuse.DrawContext)
         at Fuse.Elements.Element.Composit(Fuse.DrawContext)
         at Fuse.Elements.Element.Draw(Fuse.DrawContext)
         at Fuse.Controls.GraphicsView.DrawFrame()
         at Fuse.UpdateListener.Invoke()
         at Fuse.UpdateManager.Update(Fuse.Stage)
         at Fuse.UpdateManager.Update()
         at Fuse.AppBase.OnUpdate()
         at Fuse.App.OnUpdate()
         at Outracks.Simulator.Application.OnUpdate()
         at Fuse.App.OnTick(object,Uno.Platform.TimerEventArgs)
         at Uno.Platform2.Display.OnTick(Uno.Platform.TimerEventArgs)
      Name: TypeError
      Error message: null is not an object (evaluating 'ImageTools.getBase64FromImage(file).then')
      File name: MainView.js
      Line number: 1007
      JS stack trace: MainView.js:1007:40
      
  LOG: Detach
  LOG: Stop
  ERROR: 
      Name: TypeError
      Error message: null is not an object (evaluating 'ImageTools.getBase64FromImage(file).then')
      File name: MainView.js
      Line number: 1007
      JS stack trace: MainView.js:1007:40
```

---

<div class="post-metadata">

**Author:** ![Emil\_Sandsto](https://yyz1.discourse-cdn.com/flex035/user_avatar/forums.fusetools.com/emil_sandsto/32/523_2.png) [@Emil\_Sandsto](https://forums.fusetools.com/u/Emil_Sandsto)\
**Post date:** [November 9, 2016, 4:58pm UTC](https://forums.fusetools.com/t/create-image-from-ux-panel/3615/6 "2016-11-09T16:58:15Z")

</div>

Hi, I have updated the repo with a potential fix. I believe it was related to dispatching the JS callback on the wrong thread.

---

<div class="post-metadata">

**Author:** ![kevin](https://avatars.discourse-cdn.com/v4/letter/k/2acd7d/32.png) [@kevin](https://forums.fusetools.com/u/kevin)\
**Post date:** [November 10, 2016, 12:25am UTC](https://forums.fusetools.com/t/create-image-from-ux-panel/3615/7 "2016-11-10T00:25:40Z")

</div>

Hi im still getting this error

```
Fuse.Scripting.ScriptException: 
   at Fuse.Scripting.JavaScriptCore.Context.OnError(Fuse.Scripting.JavaScriptCore.JSValueRef)
   at Fuse.Scripting.JavaScriptCore.JSObjectRef.CallAsFunction(Fuse.Scripting.JavaScriptCore.JSContextRef,Fuse.Scripting.JavaScriptCore.JSObjectRef,Fuse.Scripting.JavaScriptCore.JSValueRef[],Uno.Action<Fuse.Scripting.JavaScriptCore.JSValueRef>)
   at Fuse.Scripting.JavaScriptCore.Function.Call(object[])
   at CallJSClosure.RunInternal()
   at Fuse.Reactive.ThreadWorker.RunInner()
   at Fuse.Reactive.ThreadWorker.Run()
   at Uno.Threading.POSIXThread.ReleasingLauncher.Run()
Name: TypeError
Error message: null is not an object (evaluating 'ImageTools.getBase64FromImage(file).then')
File name: MainView.js
Line number: 1011
JS stack trace: MainView.js:1011:40

```

when trying to use ImageTools on the `file` ps its definitely capturing as it displays the img after, but getting a Base64 string seems to be a problem…

var capturedImg = Observable();  
function capture() {

```
capturePanel.capture(function(file) {
  ImageTools.getBase64FromImage(file).then(function(base64Image) { console.log("The base64 encoded image is \"" + base64Image + "\""); });
  //debug_log(file);
  capturedImg.value = file;
});
};
```

---

<div class="post-metadata">

**Author:** ![Anders\_Bondehagen](https://yyz1.discourse-cdn.com/flex035/user_avatar/forums.fusetools.com/anders_bondehagen/32/98_2.png) [@Anders\_Bondehagen](https://forums.fusetools.com/u/Anders_Bondehagen)\
**Post date:** [November 10, 2016, 10:33am UTC](https://forums.fusetools.com/t/create-image-from-ux-panel/3615/8 "2016-11-10T10:33:35Z")

</div>

What does it say if you do

```auto
capturePanel.capture(function(file) {
  console.dir(file);
};

```

---

<div class="post-metadata">

**Author:** ![kevin](https://avatars.discourse-cdn.com/v4/letter/k/2acd7d/32.png) [@kevin](https://forums.fusetools.com/u/kevin)\
**Post date:** [November 10, 2016, 10:57am UTC](https://forums.fusetools.com/t/create-image-from-ux-panel/3615/9 "2016-11-10T10:57:07Z")

</div>

LOG: “/private/var/mobile/Containers/Data/Application/FE2CE687-A689-42F2-8D4B-9564C67C5B01/tmp/A1971CD4-2FAF-4A06-9E5E-FD52824EE107-4710-0000037304EADAF3.jpg”

---

<div class="post-metadata">

**Author:** ![Emil\_Sandsto](https://yyz1.discourse-cdn.com/flex035/user_avatar/forums.fusetools.com/emil_sandsto/32/523_2.png) [@Emil\_Sandsto](https://forums.fusetools.com/u/Emil_Sandsto)\
**Post date:** [November 10, 2016, 11:02am UTC](https://forums.fusetools.com/t/create-image-from-ux-panel/3615/10 "2016-11-10T11:02:48Z")

</div>

What’s happens if you call:

```auto
ImageTools.getBase64FromImage(file)
.then(function(base64Image) { console.log("The base64 encoded image is \"" + base64Image + "\"");
}).catch(function(e) 
{
   debug_log("An error occured: " + e);
});

```

---

<div class="post-metadata">

**Author:** ![kevin](https://avatars.discourse-cdn.com/v4/letter/k/2acd7d/32.png) [@kevin](https://forums.fusetools.com/u/kevin)\
**Post date:** [November 10, 2016, 11:55am UTC](https://forums.fusetools.com/t/create-image-from-ux-panel/3615/11 "2016-11-10T11:55:02Z")

</div>

on ios fuse preview :

```
	Fuse.Scripting.ScriptException: 
	   at Fuse.Scripting.JavaScriptCore.Context.OnError(Fuse.Scripting.JavaScriptCore.JSValueRef)
	   at Fuse.Scripting.JavaScriptCore.JSObjectRef.CallAsFunction(Fuse.Scripting.JavaScriptCore.JSContextRef,Fuse.Scripting.JavaScriptCore.JSObjectRef,Fuse.Scripting.JavaScriptCore.JSValueRef[],Uno.Action<Fuse.Scripting.JavaScriptCore.JSValueRef>)
	   at Fuse.Scripting.JavaScriptCore.Function.Call(object[])
	   at CallJSClosure.RunInternal()
	   at Fuse.Reactive.ThreadWorker.RunInner()
	   at Fuse.Reactive.ThreadWorker.Run()
	   at Uno.Threading.POSIXThread.ReleasingLauncher.Run()
	Name: TypeError
	Error message: null is not an object (evaluating 'ImageTools.getBase64FromImage(file)
	      .then')
	File name: MainView.js
	Line number: 1017
	JS stack trace: MainView.js:1017:42

```

on ios debug :

```
	Fuse.Scripting.ScriptException: 
	Name: TypeError
	Error message: null is not an object (evaluating 'ImageTools.getBase64FromImage(file)
	      .then')
	File name: MainView.js
	Line number: 1017
	JS stack trace: MainView.js:1017:42
```

---

<div class="post-metadata">

**Author:** ![Emil\_Sandsto](https://yyz1.discourse-cdn.com/flex035/user_avatar/forums.fusetools.com/emil_sandsto/32/523_2.png) [@Emil\_Sandsto](https://forums.fusetools.com/u/Emil_Sandsto)\
**Post date:** [November 10, 2016, 2:40pm UTC](https://forums.fusetools.com/t/create-image-from-ux-panel/3615/12 "2016-11-10T14:40:18Z")

</div>

`ImageTools.getBase64FromImage` expects the first parameter to be a File object as

```auto
{
   name: "MyImage",
   path: "[somepath]"
}

```

In other words, please try to do the following

```auto
ImageTools.getBase64FromImage({ path: file, name: "Some random name" })
.then(function(base64Image) { console.log("The base64 encoded image is \"" + base64Image + "\"");
}).catch(function(e) 
{
   debug_log("An error occured: " + e);
});

```

---

<div class="post-metadata">

**Author:** ![kevin](https://avatars.discourse-cdn.com/v4/letter/k/2acd7d/32.png) [@kevin](https://forums.fusetools.com/u/kevin)\
**Post date:** [November 10, 2016, 5:18pm UTC](https://forums.fusetools.com/t/create-image-from-ux-panel/3615/13 "2016-11-10T17:18:35Z")

</div>

Emil sweet this works although i did needed to clean the string up a bit :

```
    ImageTools.getBase64FromImage({ path: file, name: "Some random name" })
    .then(function(base64Image) { 

        fixString = base64Image.replace(/(\r\n|\n|\r)/gm,"");
        console.log("The fixed base64 encoded image is \"" + fixString + "\"");

    }).catch(function(e) 
    {
       debug_log("An error occured: " + e);
    });
```

---

<div class="post-metadata">

**Author:** ![Emil\_Sandsto](https://yyz1.discourse-cdn.com/flex035/user_avatar/forums.fusetools.com/emil_sandsto/32/523_2.png) [@Emil\_Sandsto](https://forums.fusetools.com/u/Emil_Sandsto)\
**Post date:** [November 10, 2016, 5:24pm UTC](https://forums.fusetools.com/t/create-image-from-ux-panel/3615/14 "2016-11-10T17:24:35Z")

</div>

Good 🙂

---

<div class="post-metadata">

**Author:** ![aeq](https://yyz1.discourse-cdn.com/flex035/user_avatar/forums.fusetools.com/aeq/32/129_2.png) [@aeq](https://forums.fusetools.com/u/aeq)\
**Post date:** [February 1, 2018, 1:38pm UTC](https://forums.fusetools.com/t/create-image-from-ux-panel/3615/15 "2018-02-01T13:38:57Z")

</div>

android: 6  
iOS: 10.3.3  
fuse: 1.6

Hey guys, I’m getting the following error with the CapturePanel when exporting to android or iOS device, only happened after updating to fuse 1.6:

```auto
Projects/CapturePanel/CapturePanel.uno(26.12): E3104: Fuse.Scripting.Context does not contain a member called 'Dispatcher'. Could you be missing a package reference?

```

---

<div class="post-metadata">

**Author:** ![kevin](https://avatars.discourse-cdn.com/v4/letter/k/2acd7d/32.png) [@kevin](https://forums.fusetools.com/u/kevin)\
**Post date:** [February 1, 2018, 2:38pm UTC](https://forums.fusetools.com/t/create-image-from-ux-panel/3615/16 "2018-02-01T14:38:21Z")

</div>

update CapturePanel.uno

```
public void Run(object arg)
{	
	_arg = arg;
	//_context.Dispatcher.Invoke(RunInternal);
}
```

---

<div class="post-metadata">

**Author:** ![aeq](https://yyz1.discourse-cdn.com/flex035/user_avatar/forums.fusetools.com/aeq/32/129_2.png) [@aeq](https://forums.fusetools.com/u/aeq)\
**Post date:** [February 1, 2018, 2:43pm UTC](https://forums.fusetools.com/t/create-image-from-ux-panel/3615/17 "2018-02-01T14:43:41Z")

</div>

Thanks Kevin but what did the commented out code do? Did you also get this afterwards:

```auto
Projects/CapturePanel/CapturePanel.uno(40.46): W4139: 'Fuse.Scripting.ScriptMethod`1..ctor(string,Uno.Action<Fuse.Scripting.Context, T, object[]>,Fuse.Scripting.ExecutionThread)' is obsolete: 'Use ScriptMethod<T>(string, Uno.Action<T)>), ScriptMethod<T>(string, Uno.Action<T, object[])>) or ScriptMethod<T>(string, Uno.Func<Fuse.Scripting.Context, T, object[], object)>) instead'

```

---

<div class="post-metadata">

**Author:** ![Emil\_Sandsto](https://yyz1.discourse-cdn.com/flex035/user_avatar/forums.fusetools.com/emil_sandsto/32/523_2.png) [@Emil\_Sandsto](https://forums.fusetools.com/u/Emil_Sandsto)\
**Post date:** [February 1, 2018, 2:53pm UTC](https://forums.fusetools.com/t/create-image-from-ux-panel/3615/18 "2018-02-01T14:53:20Z")

</div>

Hi,  
Replace `_context.Dispatcher.Invoke(RunInternal);` with `_context.Invoke(RunInternal)` and see if that helps. Also, I think you can ignore the obsolete warning for now.

---

<div class="post-metadata">

**Author:** ![aeq](https://yyz1.discourse-cdn.com/flex035/user_avatar/forums.fusetools.com/aeq/32/129_2.png) [@aeq](https://forums.fusetools.com/u/aeq)\
**Post date:** [February 1, 2018, 3:08pm UTC](https://forums.fusetools.com/t/create-image-from-ux-panel/3615/19 "2018-02-01T15:08:08Z")

</div>

Just tried it but got this:

```auto
Projects/CapturePanel/CapturePanel.uno(26.12): E3128: Call to 'Fuse.Scripting.Context.Invoke(Uno.Action<Fuse.Scripting.Context>)' has some invalid arguments (<method_group>)

```

---

<div class="post-metadata">

**Author:** ![aeq](https://yyz1.discourse-cdn.com/flex035/user_avatar/forums.fusetools.com/aeq/32/129_2.png) [@aeq](https://forums.fusetools.com/u/aeq)\
**Post date:** [February 1, 2018, 4:02pm UTC](https://forums.fusetools.com/t/create-image-from-ux-panel/3615/20 "2018-02-01T16:02:10Z")

</div>

Does it do the same thing if I take what’s inside RunInternal() and place it in the Run(object arg) Emil?

```auto
        object _arg;
	public void Run(object arg)
	{	
		_arg = arg;
		//_context.Dispatcher.Invoke(RunInternal);
		_func.Call(_context,_arg);
	}
	
	void RunInternal()
	{
		_func.Call(_context,_arg);
	}

```

[Next page](https://forums.fusetools.com/t/create-image-from-ux-panel/3615.md?page=2)
