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 - Using WPF to Generate an Image

 
 
Old 11-02-2007   #1 (permalink)
Tem


 
 

Using WPF to Generate an Image

I'm still trying to figure out how to do this simple task with WPF.
I need to draw a black circle using WPF and generate an image file. (gif or
png)

Any help is greatly appreciated.

Tem





I used the following but it resulted in a blank file. I cannot figure out
what is wrong with it.

RenderTargetBitmap rtb = new RenderTargetBitmap(200, 200, 96, 96,
PixelFormats.Pbgra32);

Ellipse cir = new Ellipse();
cir.Height = 50;
cir.Width = 50;
cir.Stroke = Brushes.Black;
cir.StrokeThickness = 1.0;

rtb.Render(cir);

PngBitmapEncoder png = new PngBitmapEncoder();
png.Frames.Add(BitmapFrame.Create(rtb));
using (Stream fs= File.Create("test.png"))
{
png.Save(fs);
}


My System SpecsSystem Spec
Old 11-03-2007   #2 (permalink)
Willy Denoyette [MVP]


 
 

Re: Using WPF to Generate an Image

"Tem" <tem1232@xxxxxx> wrote in message
news:u9g8U5ZHIHA.536@xxxxxx
Quote:

> I'm still trying to figure out how to do this simple task with WPF.
> I need to draw a black circle using WPF and generate an image file. (gif
> or png)
>
> Any help is greatly appreciated.
>
> Tem
>
>
>
>
>
> I used the following but it resulted in a blank file. I cannot figure out
> what is wrong with it.
>
> RenderTargetBitmap rtb = new RenderTargetBitmap(200, 200, 96, 96,
> PixelFormats.Pbgra32);
>
> Ellipse cir = new Ellipse();
> cir.Height = 50;
> cir.Width = 50;
> cir.Stroke = Brushes.Black;
> cir.StrokeThickness = 1.0;
>
> rtb.Render(cir);
>
> PngBitmapEncoder png = new PngBitmapEncoder();
> png.Frames.Add(BitmapFrame.Create(rtb));
> using (Stream fs= File.Create("test.png"))
> {
> png.Save(fs);
> }
>


You are missing something like:

cir.Arrange(new Rect(new Size(50, 50)));

Note that you might get quicker answers when you consult (and post) to the
msdn WPF forum first
http://forums.microsoft.com/MSDN/Sho...D=119&SiteID=1

Willy.

My System SpecsSystem Spec
Old 11-04-2007   #3 (permalink)
Tem


 
 

Re: Using WPF to Generate an Image

Thank you so much, I got it to work.

Another simple question:
I need to add another circle, slightly smaller, 45 in diameter to the same
image. the final image should be a ring.
What would be the command to add another shape?



Here's my code:

RenderTargetBitmap rtb = new RenderTargetBitmap(200, 200, 96,
96,PixelFormats.Pbgra32);

Ellipse cir = new Ellipse();
cir.Height = 50;
cir.Width = 50;
cir.Stroke = Brushes.Black;
cir.StrokeThickness = 1.0;

cir.Arrange(new Rect(new Size(50, 50)));

rtb.Render(cir);

PngBitmapEncoder png = new PngBitmapEncoder();
png.Frames.Add(BitmapFrame.Create(rtb));
using (Stream fs= File.Create("test.png"))
{
png.Save(fs);
}

My System SpecsSystem Spec
Old 11-05-2007   #4 (permalink)
Willy Denoyette [MVP]


 
 

Re: Using WPF to Generate an Image

"Tem" <tem1232@xxxxxx> wrote in message
news:OKfsEb0HIHA.1208@xxxxxx
Quote:

> Thank you so much, I got it to work.
>
> Another simple question:
> I need to add another circle, slightly smaller, 45 in diameter to the same
> image. the final image should be a ring.
> What would be the command to add another shape?
>
>
>
> Here's my code:
>
> RenderTargetBitmap rtb = new RenderTargetBitmap(200, 200, 96,
> 96,PixelFormats.Pbgra32);
>
> Ellipse cir = new Ellipse();
> cir.Height = 50;
> cir.Width = 50;
> cir.Stroke = Brushes.Black;
> cir.StrokeThickness = 1.0;
>
> cir.Arrange(new Rect(new Size(50, 50)));
>
> rtb.Render(cir);
>
> PngBitmapEncoder png = new PngBitmapEncoder();
> png.Frames.Add(BitmapFrame.Create(rtb));
> using (Stream fs= File.Create("test.png"))
> {
> png.Save(fs);
> }

Draw a new ellipse inside the first one and render.

...
rtb.Render(cir);
cir.Height = 45;
cir.Width = 45;
cir.Arrange(new Rect(new Size(50, 50)));
rtb.Render(cir);
....

Willy.


My System SpecsSystem Spec
Old 11-15-2007   #5 (permalink)
Serge Baltic


 
 

Re: Using WPF to Generate an Image

Hello,
Quote:

> Note that you might get quicker answers when you consult (and post)
> to the msdn WPF forum first
> http://forums.microsoft.com/MSDN/Sho...D=119&SiteID=1
What's the NNTP address for that forum?

(H) Serge


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


 
 

Re: Using WPF to Generate an Image

Hi,

Serge Baltic wrote:
Quote:

> Hello,
>
Quote:

>> Note that you might get quicker answers when you consult (and post)
>> to the msdn WPF forum first
>> http://forums.microsoft.com/MSDN/Sho...D=119&SiteID=1
>
> What's the NNTP address for that forum?
>
> (H) Serge
There is none. It's unfortunate, but Microsoft is slowly pulling out of
NNTP and keeping all the forums on the web. There is a RSS feed though.

HTH,
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
 

Thread Tools


Similar Threads
Thread Forum
Hibernate Warning. How Do I Generate One? General Discussion
Image thumbnails generate then disappear Vista General
Generate script VB Script
cannot generate thumbnail view of image 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