Z
Z
Zulkund2017-03-01 15:30:56
WPF
Zulkund, 2017-03-01 15:30:56

How to bind a Bitmap class object to a component in WPF?

Good afternoon! Tell me how to bind an object of the Bitmap class to the component?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
T
Tom Nolane, 2017-03-01
@Zulkund

one)

// image создаю программно, но можно и из x:Name использовать аналогично (без var image = new System.Windows.Controls.Image();)
                        var image = new System.Windows.Controls.Image();
                        BitmapImage bitmap = new BitmapImage();
                        bitmap.BeginInit();
                        bitmap.UriSource = new Uri(path, UriKind.Absolute);
                        bitmap.EndInit();
                        Image.Source = bitmap;

2)
[SerializableAttribute]
[ComVisibleAttribute(true)]
public sealed class Bitmap : Image

3) tyk
4)
<Image Width="90" Height="90" 
       Source="{Binding Path=ImageSource}"
       Margin="0,0,0,5" />

public object ImageSource {
    get {
        BitmapImage image = new BitmapImage();

        try {
            image.BeginInit();
            image.CacheOption = BitmapCacheOption.OnLoad;
            image.CreateOptions = BitmapCreateOptions.IgnoreImageCache;
            image.UriSource = new Uri( FullPath, UriKind.Absolute );
            image.EndInit();
        }
        catch{
            return DependencyProperty.UnsetValue;
        }

        return image;
    }
}

5)
<Image>
    <Image.Source>
        <BitmapImage UriSource="{Binding Path=ImagePath, Converter=...}" />
    </Image.Source>
</Image>

BitmapImage image = new BitmapImage();
image.BeginInit();
image.UriSource = new Uri(value as string);
image.EndInit();

return image;

6)
img.Source = (ImageSource)new ImageSourceConverter().ConvertFromString("/www/image.png");

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question