In xaml create an image and ask him the desired height:

 <Image x:Name="CatView" Height="38" Source="_мое_изображение"> 

How to get the image in the code, which is obtained after recalculating the size?

Ie, where is my image with the size equal to CatView.RenderSize ?

    1 answer 1

    Well, the picture itself can be nowhere and not stored, or stored in an inaccessible place. But you can easily get a snapshot of any control in the picture. For example:

     // получаем изображение var rtb = new RenderTargetBitmap( (int)control.ActualWidth, (int)control.ActualHeight, 96, 96, PixelFormats.Pbgra32); rtb.Render(control); // сохраняем в PNG var png = new PngBitmapEncoder() { Frames = { BitmapFrame.Create(rtb) } }; using (var file = File.Create(path)) png.Save(file); 

    Documentation: How to: Encode a Visual to an Image File .

    • Your code does not give me my thumbnail image. I get a blank image size of 1kb - kovdryavlad
    • @kovdryavlad: Do you show a window with a picture? - VladD
    • Yes, the picture is always on the form. And the form is one - kovdryavlad
    • @kovdryavlad: Strange, it works for me. And you do not call this code, for example, in the designer? - VladD