Windows Vista Forums
Vista Forums Home Join Vista Forums Windows 7 Forum Vista Tutorials Tags
Welcome to Windows Vista Forums. Our forum is dedicated to helping you find solutions with any problems, errors or issues you are experiencing with Windows Vista. The Vista forum also covers news and updates and has an extensive Windows Vista tutorial section that covers a wide range of tips and tricks.

Go Back   Vista Forums > Misc Newsgroups > Avalon

Vista - How to get the bitmap image of a control

 
 
Old 10-31-2007   #1 (permalink)
Patrice


 
 

How to get the bitmap image of a control

Hi all

How to retrieve the bitmap image of a given WPF control (or
visualtree) ?

I'd like to be able to insert a kind of control "screen copy" in an
arbitrary destination (a Word document for instance). Is there an easy
way to do that ? I think I've seen that somewhere but I can't remember
where.

Thanx in advance.


My System SpecsSystem Spec
Old 10-31-2007   #2 (permalink)
Laurent Bugnion, MVP


 
 

Re: How to get the bitmap image of a control

Hi,

Patrice wrote:
Quote:

> Hi all
>
> How to retrieve the bitmap image of a given WPF control (or
> visualtree) ?
>
> I'd like to be able to insert a kind of control "screen copy" in an
> arbitrary destination (a Word document for instance). Is there an easy
> way to do that ? I think I've seen that somewhere but I can't remember
> where.
>
> Thanx in advance.
Check the thread named "Draw a circle in WPF" earlier in this very forum.

Greetings,
Laurent
--
Laurent Bugnion [MVP ASP.NET]
Software engineering, Blog: http://www.galasoft.ch
PhotoAlbum: http://www.galasoft.ch/pictures
Support children in Calcutta: http://www.calcutta-espoir.ch
My System SpecsSystem Spec
Old 10-31-2007   #3 (permalink)
Patrice


 
 

Re: How to get the bitmap image of a control

On 31 oct, 23:25, "Laurent Bugnion, MVP" <galasoft...@xxxxxx>
wrote:
Quote:

> Hi,
>
> Patrice wrote:
Quote:

> > Hi all
>
Quote:

> > How to retrieve the bitmap image of a given WPF control (or
> > visualtree) ?
>
Quote:

> > I'd like to be able to insert a kind of control "screen copy" in an
> > arbitrary destination (a Word document for instance). Is there an easy
> > way to do that ? I think I've seen that somewhere but I can't remember
> > where.
>
Quote:

> > Thanx in advance.
>
> Check the thread named "Draw a circle in WPF" earlier in this very forum.
>
> Greetings,
> Laurent
> --
> Laurent Bugnion [MVP ASP.NET]
> Software engineering, Blog:http://www.galasoft.ch
> PhotoAlbum:http://www.galasoft.ch/pictures
> Support children in Calcutta:http://www.calcutta-espoir.ch
Yeah, I've seen it just after having posted my message. It seems it
answers perfectly my question. thnax a lot !

My System SpecsSystem Spec
Old 11-01-2007   #4 (permalink)
Patrice


 
 

Re: How to get the bitmap image of a control

On 31 oct, 23:32, Patrice <contact-on...@xxxxxx-si.com> wrote:
Quote:

> On 31 oct, 23:25, "Laurent Bugnion, MVP" <galasoft...@xxxxxx>
> wrote:
>
>
>
>
>
Quote:

> > Hi,
>
Quote:

> > Patrice wrote:
Quote:

> > > Hi all
>
Quote:
Quote:

> > > How to retrieve the bitmap image of a given WPF control (or
> > > visualtree) ?
>
Quote:
Quote:

> > > I'd like to be able to insert a kind of control "screen copy" in an
> > > arbitrary destination (a Word document for instance). Is there an easy
> > > way to do that ? I think I've seen that somewhere but I can't remember
> > > where.
>
Quote:
Quote:

> > > Thanx in advance.
>
Quote:

> > Check the thread named "Draw a circle in WPF" earlier in this very forum.
>
Quote:

> > Greetings,
> > Laurent
> > --
> > Laurent Bugnion [MVP ASP.NET]
> > Software engineering, Blog:http://www.galasoft.ch
> > PhotoAlbum:http://www.galasoft.ch/pictures
> > Support children in Calcutta:http://www.calcutta-espoir.ch
>
> Yeah, I've seen it just after having posted my message. It seems it
> answers perfectly my question. thnax a lot !- Masquer le texte des messages précédents -
>
> - Afficher le texte des messages précédents -
Salut Laurent,

I tried to use your code but I got the same issue described in the
last post of the thread you mentioned (empty image).

And I can't figure what I'im doing wrong.

Here is my code (vb sorry )

Public Function GetImageFromVisual(ByVal Target As Visual, ByVal
width As Integer, ByVal height As Integer) As RenderTargetBitmap

Dim bounds As Rect =
VisualTreeHelper.GetDescendantBounds(Target)

Dim renderBitmap As New RenderTargetBitmap(width, height, 96,
96, PixelFormats.Pbgra32)

Dim visual As New DrawingVisual()
Dim context As DrawingContext = visual.RenderOpen
With context
Dim brush As New VisualBrush(Target)
context.DrawRectangle(brush, Nothing, New Rect(New
Point(), bounds.Size))
End With
renderBitmap.Render(visual)
Return renderBitmap

End Function

If ever you can see something...

Thanx in advance

My System SpecsSystem Spec
Old 11-01-2007   #5 (permalink)
Laurent Bugnion, MVP


 
 

Re: How to get the bitmap image of a control

Salut,

I don't have time to debug it, but I can send you a working example per
email if you want, and you can build on that.

My example will be in C# though :-(

Let me know

Greetings,
Laurent

Patrice wrote:
Quote:

> On 31 oct, 23:32, Patrice <contact-on...@xxxxxx-si.com> wrote:
Quote:

>> On 31 oct, 23:25, "Laurent Bugnion, MVP" <galasoft...@xxxxxx>
>> wrote:
>>
>>
>>
>>
>>
Quote:

>>> Hi,
>>> Patrice wrote:
>>>> Hi all
>>>> How to retrieve the bitmap image of a given WPF control (or
>>>> visualtree) ?
>>>> I'd like to be able to insert a kind of control "screen copy" in an
>>>> arbitrary destination (a Word document for instance). Is there an easy
>>>> way to do that ? I think I've seen that somewhere but I can't remember
>>>> where.
>>>> Thanx in advance.
>>> Check the thread named "Draw a circle in WPF" earlier in this very forum.
>>> Greetings,
>>> Laurent
>>> --
>>> Laurent Bugnion [MVP ASP.NET]
>>> Software engineering, Blog:http://www.galasoft.ch
>>> PhotoAlbum:http://www.galasoft.ch/pictures
>>> Support children in Calcutta:http://www.calcutta-espoir.ch
>> Yeah, I've seen it just after having posted my message. It seems it
>> answers perfectly my question. thnax a lot !- Masquer le texte des messages précédents -
>>
>> - Afficher le texte des messages précédents -
>
> Salut Laurent,
>
> I tried to use your code but I got the same issue described in the
> last post of the thread you mentioned (empty image).
>
> And I can't figure what I'im doing wrong.
>
> Here is my code (vb sorry )
>
> Public Function GetImageFromVisual(ByVal Target As Visual, ByVal
> width As Integer, ByVal height As Integer) As RenderTargetBitmap
>
> Dim bounds As Rect =
> VisualTreeHelper.GetDescendantBounds(Target)
>
> Dim renderBitmap As New RenderTargetBitmap(width, height, 96,
> 96, PixelFormats.Pbgra32)
>
> Dim visual As New DrawingVisual()
> Dim context As DrawingContext = visual.RenderOpen
> With context
> Dim brush As New VisualBrush(Target)
> context.DrawRectangle(brush, Nothing, New Rect(New
> Point(), bounds.Size))
> End With
> renderBitmap.Render(visual)
> Return renderBitmap
>
> End Function
>
> If ever you can see something...
>
> Thanx in advance
>
--
Laurent Bugnion [MVP ASP.NET]
Software engineering, Blog: http://www.galasoft.ch
PhotoAlbum: http://www.galasoft.ch/pictures
Support children in Calcutta: http://www.calcutta-espoir.ch
My System SpecsSystem Spec
 

Thread Tools


Similar Threads
Thread Forum
bitmap Vista file management
The AXIS Media Control, which enables you to view live image streams in Microsoft Internet Explorer, could not be registered on your computer. Vista security
I want to be able to create a new bitmap... Vista General


Vista Forums is an independent web site and has not been authorized,
sponsored, or otherwise approved by Microsoft Corporation.
"Windows Vista", the Start Orb, and related materials are trademarks of Microsoft Corp.
© Designer Media Ltd

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46