ZioGio
Topic Author
Posts: 2
Joined: 01 Nov 2023, 17:46

Weird behavior with WPF Image and ImageBrush in Unity

11 Dec 2023, 23:55

I need assistance figuring out why a WPF image with 736x411 dimensions is rendering in Unity as 411x411. The dimensions of the PNG are 736x411.

Below is the XAML (the redundant Widths and Heights were added to this sample to show that forced adherence to the desired dimensions appears to not be honored).
<UserControl x:Class="Unity.Assets.UI.View.TabControlTest2"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
             xmlns:local="clr-namespace:Unity.Assets.UI.View"
             mc:Ignorable="d" Width="736" Height="411">
    <Grid Width="736" Height="411">
        <Image Source="JapaneseFlag.png" Width="736" Height="411"/>
        
        <!-- I get the same result with a Rectangle and ImageBrush
        <Rectangle Width="736" Height="411">
            <Rectangle.Fill>
                <ImageBrush ImageSource="JapaneseFlag.png" Stretch="Uniform"/>
            </Rectangle.Fill>
        </Rectangle>-->
    </Grid>
</UserControl>
Steps taken in Unity:
1. File >> New Scene >> Basic (Built-in)
2. Add Component >> NoesisGUI >> Noesis View
3. Select XAML file
4. Play

The result renders in Unity as 411x411:
Image

If I change the XAML to this:
<Grid Width="736" Height="411">
    <Rectangle Width="736" Height="411" Fill="White"/>
    <Ellipse Width="300" Height="300" Fill="Blue"/>
</Grid>
Then I get the expected 736x411 result in Unity:
(Note that if you're looking for the bottom half of the Inspector from the above screen shot, I included it in this screen shot)
Image

So, what is it about using an Image that causes it to render as a square?

Thank you for your time and assistance!
 
User avatar
sfernandez
Site Admin
Posts: 3005
Joined: 22 Dec 2011, 19:20

Re: Weird behavior with WPF Image and ImageBrush in Unity

14 Dec 2023, 10:25

Hi,

Is it possible that the image settings in Unity are configured to resize the texture to the next/nearest power of 2?
Noesis uses the texture dimensions, not the original image bytes, so you should configure your texture to keep the original size.

Also remember to assign the Noesis label in order to preprocess it as a premultiplied alpha texture, to correctly render semi-transparent pixels.

Who is online

Users browsing this forum: Ahrefs [Bot] and 2 guests