User avatar
ai_enabled
Posts: 221
Joined: 18 Jul 2013, 05:28
Contact:

Re: How to change Image source at runtime?

22 Sep 2013, 04:27

jsantos, I want to congratulate you on the NoesisGUI 1.0.4 release! Is the setting Image source from the Unity Texture2D possible now, or you plan to implement this feature in the next release?
AtomicTorch Studio Pte. Ltd. http://atomictorch.com
 
User avatar
jsantos
Site Admin
Posts: 2906
Joined: 20 Jan 2012, 17:18
Contact:

Re: How to change Image source at runtime?

23 Sep 2013, 12:58

Hi Vladimir,

Not yet. But it is planned for v1.0.5. Very soon then, hehe.
 
Andreas Schooll
Posts: 25
Joined: 30 Sep 2013, 16:58

Re: How to change Image source at runtime?

30 Sep 2013, 17:09

We would need something like this in our current project as well.

In our project you can configure something that will be visualized ith images. We will have a feature to update the content database via web. So the content and images can change during runtime. Right now we have all images as brushes in a resource dictionary but this is only a temporary solution.

I guess there is no other way to dynamically create brushes from memory / files than using the Image class proxy you mentioned before?

Can you give a rough estimation (date) of when you plan to implement this proxy? Our projects deadline is the 15th of november.

best regards,
Andreas
 
User avatar
jsantos
Site Admin
Posts: 2906
Joined: 20 Jan 2012, 17:18
Contact:

Re: How to change Image source at runtime?

30 Sep 2013, 18:00

Hi,

The next release, probably at the end of this week, will include:
  • Unity: Support for creating NoesisGUI images from Unity2D texture
  • Native: support from creating NoesisGUI image from a texture handle
  • Documentation added for all this in the Images tutorial

Note that, in native you can already do this by filling a Drawing::Image class (this will be documented too).
Anything is not clear? Now it is a good moment to discuss all this.
 
User avatar
jsantos
Site Admin
Posts: 2906
Joined: 20 Jan 2012, 17:18
Contact:

Re: How to change Image source at runtime?

08 Oct 2013, 03:59

The release is almost ready and will include this feature. Just want to show you how is is done:

C++
FrameworkElement* fe = NsDynamicCast<FrameworkElement*>(content);
Gui::Image* img = fe->FindName<Image>("img");

Ptr<Drawing::Image> bits = *new Drawing::Image(Drawing::ImageFormat_A8R8G8B8, 256, 256);
bits->Fill(Drawing::Color::Red);

Ptr<Gui::ImageSource> source = *new Gui::BitmapSource(bits.GetPtr());
img->SetSource(source.GetPtr());
Unity
Grid grid = GetComponent<NoesisGUIPanel>().GetRoot<Grid>();

Texture2D texture = Resources.Load("Noesis") as Texture2D;
TextureSource source = new TextureSource(texture);

Image img = grid.FindName<Image>("img");
img.SetSource(source);
 
ritwick
Posts: 3
Joined: 08 Mar 2015, 16:09

Re: How to change Image source at runtime?

22 Apr 2015, 12:04

The Texture2D is a Unity class. If we have to change the image at runtime using C# and when we are not using Unity, then how can it be done?
 
User avatar
sfernandez
Site Admin
Posts: 1918
Joined: 22 Dec 2011, 19:20

Re: How to change Image source at runtime?

23 Apr 2015, 12:16

The Texture2D is a Unity class. If we have to change the image at runtime using C# and when we are not using Unity, then how can it be done?
Hi,

This code was initially designed only for Unity, we still have to adapt it for the .NET/Mono API. What we have in mind is the possibility of creating the TextureSource by providing the texture native pointer:
public class TextureSource
{
  public TextureSource(IntPtr nativeTexturePtr, int width, int height, int numMipMaps) { ...}
  ...
} 
 
ritwick
Posts: 3
Joined: 08 Mar 2015, 16:09

Re: How to change Image source at runtime?

10 Jun 2015, 12:09

Hi,

I am able to set the texture source for the image using C# sdk while the application is starting and the image is rendered correctly. At a later point when I am updating the texture data with a different image data, the image is not getting updated. I am using OpenGL. What do I need to do get the updated image?

Steps:
1. The following is done before GLUTWrapper.Run(). In opengl, LoadImage() uses glTexImage2D() to set the image data.
         IntPtr p = GLUTWrapper.LoadImage("sample1.png");
         Noesis.Image image = root.FindName("image") as Noesis.Image;
         if (image != null)
         {
             source = new Noesis.TextureSource(p, 992, 992, 1);
             image.Source = source;
         }
2. At a later time after the image is rendered, I am using glTexSubImage2D() to update the texture data. I am not changing any property of the Image control, just calling C++ method to read a new png file and update the texture. BackgroundWorker is created on the main thread, and so RunWorkerCompleted handler is also called on the main thread.
                    BackgroundWorker worker = new BackgroundWorker();
                    worker.DoWork += new DoWorkEventHandler((s, e) =>
                    {
                        System.Threading.Thread.Sleep(15000);
                    });

                    worker.RunWorkerCompleted += new RunWorkerCompletedEventHandler((s, e) =>
                    {
                        GLUTWrapper.UpdateImage("sample2.png");
                    });

                    worker.RunWorkerAsync();
thanks
 
User avatar
jsantos
Site Admin
Posts: 2906
Joined: 20 Jan 2012, 17:18
Contact:

Re: How to change Image source at runtime?

10 Jun 2015, 20:36

I am able to set the texture source for the image using C# sdk while the application is starting and the image is rendered correctly. At a later point when I am updating the texture data with a different image data, the image is not getting updated. I am using OpenGL. What do I need to do get the updated image?
It should work the way you are describing. We do not copy the handle internally so if the content of the handle changes it should automatically appear in the next render. Please, verify the following:
  • Make sure that you are not creating a new texture handle.
  • Check the error code returned by glTexSubImage2D to verify that the operation was executed successfully.
  • Make sure you are calling glTexSubImage2D in the same thread you are doing the Renderer.Render() and also make sure that the proper context is bound.
 
ritwick
Posts: 3
Joined: 08 Mar 2015, 16:09

Re: How to change Image source at runtime?

15 Jun 2015, 13:46

Hi Jesus,

Thanks for the hints. Indeed it was thread issue.

I was using the C# sdk integration sample with OpenGL based on glut. I was setting the texture source from the main method of the C# console application. Also both the images were loaded using the application thread on which the console application was started. It didn't work.

It seems that the texture update needs to be done on the thread used by NoesisGUI. So when I used the button click handler to update the texture data (using glTextSubImage2D), it started working.

Thanks!

Who is online

Users browsing this forum: No registered users and 1 guest