-
- ai_enabled
- Posts: 231
- Joined:
- Contact:
Re: How to change Image source at runtime?
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
Re: How to change Image source at runtime?
Hi Vladimir,
Not yet. But it is planned for v1.0.5. Very soon then, hehe.
Not yet. But it is planned for v1.0.5. Very soon then, hehe.
-
- Andreas Schooll
- Posts: 25
- Joined:
Re: How to change Image source at runtime?
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
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
Re: How to change Image source at runtime?
Hi,
The next release, probably at the end of this week, will include:
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.
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.
Re: How to change Image source at runtime?
The release is almost ready and will include this feature. Just want to show you how is is done:
C++
Unity
C++
Code: Select all
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());
Code: Select all
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);
Re: How to change Image source at runtime?
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?
-
-
sfernandez
Site Admin
- Posts: 3197
- Joined:
Re: How to change Image source at runtime?
Hi,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?
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:
Code: Select all
public class TextureSource
{
public TextureSource(IntPtr nativeTexturePtr, int width, int height, int numMipMaps) { ...}
...
}
Re: How to change Image source at runtime?
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.
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.
thanks
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.
Code: Select all
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;
}
Code: Select all
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();
Re: How to change Image source at runtime?
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: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?
- 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.
Re: How to change Image source at runtime?
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!
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 14 guests