-
- MarioBarbero
- Posts: 30
- Joined:
BitmapSource to BitmapImage in Noesis
I am triying to do a Loading with sprites and I dont know how to do this with Noesis.
This method throw many errors when I execute it in Noesis.
This method throw many errors when I execute it in Noesis.
Code: Select all
private BitmapImage ConvertToBitmapImage(BitmapSource bitmapSource)
{
using (MemoryStream memoryStream = new MemoryStream())
{
BitmapEncoder encoder = new PngBitmapEncoder();
encoder.Frames.Add(BitmapFrame.Create(bitmapSource));
encoder.Save(memoryStream);
BitmapImage bitmapImage = new BitmapImage();
bitmapImage.BeginInit();
bitmapImage.CacheOption = BitmapCacheOption.OnLoad;
bitmapImage.StreamSource = new MemoryStream(memoryStream.ToArray());
bitmapImage.EndInit();
return bitmapImage;
}
}
Last edited by MarioBarbero on 07 Feb 2025, 12:51, edited 1 time in total.
Re: BitmapSource to BitmapImage in Noesis
Is this in Unity? Please use the TAGS in your new posts to indicate this.
-
- MarioBarbero
- Posts: 30
- Joined:
Re: BitmapSource to BitmapImage in Noesis
Yes, First, I doint that in WPF, without UNity and without Noesis. Then, I write the code in Unity and throw many errors.
I want to do an animated loading with sprites. I have all sprite in one image, the same image.
The code is: in the attached files. I am attaching it as a zip because it won't let me attach the files separately.
I want to do an animated loading with sprites. I have all sprite in one image, the same image.
The code is: in the attached files. I am attaching it as a zip because it won't let me attach the files separately.
- Attachments
-
- BKSpinnerLoading.zip
- (88.8 KiB) Downloaded 218 times
Re: BitmapSource to BitmapImage in Noesis
Are you using native Sprites and atlases in Unity? That's the way to go in Unity, using the sprites as standard textures.
-
- MarioBarbero
- Posts: 30
- Joined:
Re: BitmapSource to BitmapImage in Noesis
Maybe I explained myself wrong. I have the xaml views associated with Unity. I'm not doing it directly in Unity.
So I want to do the Loading in a xaml.
I have seen the example that you do here (https://www.noesisengine.com/docs/Gui.C ... orial.html), but I have all the sprites in a single image, like the Aladin image in the example, but is it necessary to create an animation for each sprite? In my case,
I have 36 sprites, in 6 rows of 6 each. Total 36.
Isn't there some way to create an animation for everything and have it rotate? As in the example that I attached in the previous message.
So I want to do the Loading in a xaml.
I have seen the example that you do here (https://www.noesisengine.com/docs/Gui.C ... orial.html), but I have all the sprites in a single image, like the Aladin image in the example, but is it necessary to create an animation for each sprite? In my case,
I have 36 sprites, in 6 rows of 6 each. Total 36.
Isn't there some way to create an animation for everything and have it rotate? As in the example that I attached in the previous message.
Re: BitmapSource to BitmapImage in Noesis
Are you using native Sprites and atlases in Unity? Because this is the way to go in Unity.
Please have a look at the Inventory sample included in the package.
Please have a look at the Inventory sample included in the package.
-
- MarioBarbero
- Posts: 30
- Joined:
Re: BitmapSource to BitmapImage in Noesis
But can't it be done in WPF and then call the component, in this case a UserControl that will have this Loading inside?
When you say look at the example, do you mean the example of the Aladin images?
When you say look at the example, do you mean the example of the Aladin images?
Re: BitmapSource to BitmapImage in Noesis
In our Unity package, there is a sample called Inventory that uses sprites.
One advantage of Unity sprites is that you can design your XAML using separate images (e.g., sprite0.png, sprite1.png, sprite2.png, etc.). Then, as a completely separate step independent of the design process, you can combine all the sprites into a single atlas that is used at runtime, without doing any changes to the XAML.
One advantage of Unity sprites is that you can design your XAML using separate images (e.g., sprite0.png, sprite1.png, sprite2.png, etc.). Then, as a completely separate step independent of the design process, you can combine all the sprites into a single atlas that is used at runtime, without doing any changes to the XAML.
Re: BitmapSource to BitmapImage in Noesis
This approach is inefficient and not well-suited for Unity:
A better approach in Unity is to use image assets, as they undergo an offline process to convert them into optimized textures with mipmaps and compression.
Unity sprites allow this.
Code: Select all
bitmapImage.StreamSource = new MemoryStream(memoryStream.ToArray());
Unity sprites allow this.
-
- MarioBarbero
- Posts: 30
- Joined:
Re: BitmapSource to BitmapImage in Noesis
Thank you so much.
I followed the example you told me and
I managed to make the animation for lack of one thing: I want to paint it yellow, but if I do, nothing comes out. Originally the logo file is blank. It would be painting it yellow in code.
How can I set the color yellow?
I attach the config of sprite and the video with Atlas sprites (https://drive.google.com/file/d/18kg-l3 ... sp=sharing). It won't let me attach the video.
The code:
I followed the example you told me and
I managed to make the animation for lack of one thing: I want to paint it yellow, but if I do, nothing comes out. Originally the logo file is blank. It would be painting it yellow in code.
How can I set the color yellow?
I attach the config of sprite and the video with Atlas sprites (https://drive.google.com/file/d/18kg-l3 ... sp=sharing). It won't let me attach the video.
The code:
Code: Select all
private void LoadFrames()
{
Uri p = SpinnerLogoPath.UriSource;
BitmapImage spriteSheet = new BitmapImage(p);
_frames = new List<ImageSource>();
for (int i = 0; i < 36; i++)
{
int x = (i % 6) * 512;
int y = (i / 6) * 512;
ImageSource s = new CroppedBitmap(spriteSheet, new Int32Rect(x, y, 512, 512));
_frames.Add(s);
UnityEngine.Debug.Log(s);
}
}
private void StartAnimationSpinner()
{
Storyboard storyboard = (Storyboard)FindResource("SpinnerAnimation");
ObjectAnimationUsingKeyFrames animation = (ObjectAnimationUsingKeyFrames)storyboard.Children[0];
TimeSpan frameDuration = TimeSpan.FromMilliseconds(50); // 50ms en cada frame
TimeSpan currentTime = TimeSpan.Zero;
foreach (var frame in _frames)
{
ObjectKeyFrame keyFrame = new Noesis.DiscreteObjectKeyFrame()
{
Value = frame,
KeyTime = currentTime
};
animation.KeyFrames.Add(keyFrame);
currentTime += frameDuration;
}
storyboard.Begin();
}
Code: Select all
<UserControl.Resources>
<Storyboard x:Key="SpinnerAnimation"
RepeatBehavior="Forever">
<ObjectAnimationUsingKeyFrames Storyboard.TargetName="SpinnerImage"
Storyboard.TargetProperty="Source"
RepeatBehavior="Forever">
</ObjectAnimationUsingKeyFrames>
</Storyboard>
</UserControl.Resources>Who is online
Users browsing this forum: No registered users and 8 guests