This project is read-only.

Copy BMP into WPF image, from C++ land, using shader

Apr 26, 2010 at 3:19 AM

There may be a way to do this already....

At this site

there is a pixel shader example of updating a writeable bitmap.

I want to do almost the exact same thing, using a pixel shader.


I want to COPY a bitmap that was created or built in c++ (the code can not be translated into C# )

So basically, I want to have

1) Texture to be updated (the writeable bitmap, just as in pixel shader example at above listed site.

2) A SECOND Texture, but this texture lives in C++ land inside a COM object.

My problem, it may or may not be very easy to solve, is to reference this second texture in the pixel shader. How do I do this?

(I basically want to copy bmp, using a pixel shader, rather than via SetPixel api or something like that)

So basically I'm copying using the GPU rather than the CPU....


Apr 26, 2010 at 9:03 AM

This is the project site of the WriteableBitmapEx project, the extension methods for the WriteableBitmap. I don't know if I got your question right, but what you're trying to achieve sounds like Blitting. See the extension method.

But since I'm also the author of the blog post you are referring, I try to answer your shader question. You can combine two input textures easily with pixel shaders, you just have to add a second sampler. Then in the code behind you assign an ImageBrush. I use this for the noise texture in this blog post. just download the source from there and see how it's done.

Apr 26, 2010 at 12:44 PM

Here is the setup, so to speak...



.... code...

create WriteableBitmap...

assign shader...

.... code......


C++ component

... create my bitmap (this is created from images received from over network)....

.... etc...more code....


I understand about second sampler....

What I'm not sure about is, how do I setup my C++ created bitmap as the second sampler?

Does your noise texture example show this? (will check it out later today)


Apr 26, 2010 at 4:09 PM

You can't access native C++ code from within Silverlight. You have to expose the Bitmap that was created in the C++ app. You can use a Webservice to send the Bitmap over to the Silverlight app. Then you can create an ImageBrush that uses the Bitmap.

In WPF you can access the native c++ component through P/Invoke. But again, this project is about the WriteableBitmapEx library for Silverlight, not about WPF or shaders. You should ask your question over at