Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 561713
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T12:28:42+00:00 2026-05-13T12:28:42+00:00

I have a custom wpf control to do an arbitrary reverse image warp, that

  • 0

I have a custom wpf control to do an arbitrary reverse image warp, that use a Viewport3D and custom matrix, and a mesh with an ImageBrush…

I’m trying to render this to a bitmap entirely off screen. I am able to render a bitmap fine (I found to call .Measure() .Arrange(new Rectangle(…)) and .UpdateLayout()) before rendering, but the binding hasn’t completed yet so the mesh is invisible (the image brush source hasn’t loaded yet)…

What am I missing? is there a blocking way to wait for binding to complete?

[My attempts to handle the “Loaded” event haven’t been successful…]

Update, sample code:

Sample code is below. The expected output is a 300×300 blue rectangle with the stack overflow logo squashed/rotated in a diamond. (try opening the DiamondControl.xaml designer, and changing the code to have the image url hard coded… interestingly, this variation continues to not be in the rendered bitmap suggesting my problem isn’t related to the image url being bound, but the image not yet being loaded)

Program.cs (a console app with added references to System.Windows.Presentation)

using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Media;
using System.Windows.Media.Imaging;

namespace ConsoleApplication3 {
    class Program {
        [STAThread]
        static void Main(string[] args) {
            // try exporting a bitmap...
            var content = new DiamondControl();
            content.DataContext = new Uri("http://sstatic.net/so/img/logo.png");
            //content.ApplyTemplate(); // this doesn't seem to work

            int width = 300, height = 300;

            var rect = new Rect(0, 0, width, height);
            content.Measure(new Size(width, height));
            content.Arrange(rect);
            //content.UpdateLayout(); // not required in this case, seems to be required if I render the control more than once

            PngBitmapEncoder encoder = new PngBitmapEncoder();
            RenderTargetBitmap render = new RenderTargetBitmap(
                width,
                height,
                96,
                96,
                PixelFormats.Pbgra32);

            render.Render(content);
            encoder.Frames.Add(BitmapFrame.Create(render));
            using (Stream s = File.Open("outputfile.png", FileMode.Create)) {
                encoder.Save(s);
            }
        }
    }
}

DiamondControl.xaml:

<UserControl x:Class="ConsoleApplication3.DiamondControl"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    Height="300" Width="300">
    <Grid>
        <Rectangle Fill="CornflowerBlue" />
        <Viewport3D>
            <ModelVisual3D>
                <ModelVisual3D.Content>
                    <Model3DGroup>
                        <GeometryModel3D>
                            <GeometryModel3D.Geometry>
                                <!-- simple diamond -->
                                <MeshGeometry3D x:Name="mesh"
                            Positions="-.5 0 0, 0 .5 0, 0 -.5 0, .5 0 0"
                            TextureCoordinates="0 1, 0 0, 1 1, 1 0" 
                            TriangleIndices="0 2 1, 2 3 1" />
                            </GeometryModel3D.Geometry>

                            <GeometryModel3D.Material>
                                <DiffuseMaterial>
                                    <DiffuseMaterial.Brush>
                                        <!--<SolidColorBrush Color="Red" />-->
                                        <ImageBrush ImageSource="{Binding}" />
                                        <!--<ImageBrush ImageSource="http://sstatic.net/so/img/logo.png" />-->
                                    </DiffuseMaterial.Brush>
                                </DiffuseMaterial>
                            </GeometryModel3D.Material>
                        </GeometryModel3D>

                        <!-- Light source. -->
                        <AmbientLight Color="White" />
                    </Model3DGroup>
                </ModelVisual3D.Content>
            </ModelVisual3D>

            <!-- Camera. -->
            <Viewport3D.Camera>
                <OrthographicCamera Position="0 0 1"
                        LookDirection="0 0 -1"
                        UpDirection="0 1 0"
                        Width="1" />
            </Viewport3D.Camera>
        </Viewport3D>
    </Grid>
</UserControl>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-13T12:28:43+00:00Added an answer on May 13, 2026 at 12:28 pm

    If your bitmap corresponds to a web address, you use the solution in How to render an <image> in a background WPF process?

    Also, include an <image> element (even if sized 0x0) in your control. I’m not sure why this works and it seems like a total kludge.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 382k
  • Answers 382k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer The git-archive manpage contains the following example: git archive --format=tar… May 14, 2026 at 10:24 pm
  • Editorial Team
    Editorial Team added an answer You could use whatever ps uses, though it isn't cocoa… May 14, 2026 at 10:24 pm
  • Editorial Team
    Editorial Team added an answer Lets make some denotations: n - number of elements in… May 14, 2026 at 10:24 pm

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.