473,387 Members | 1,863 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Using WPF to Generate an Image

Tem
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);
}

Nov 2 '07 #1
5 2847
"Tem" <te*****@yahoo.comwrote in message
news:u9*************@TK2MSFTNGP06.phx.gbl...
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.

Nov 3 '07 #2
Tem
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);
}

Nov 5 '07 #3
"Tem" <te*****@yahoo.comwrote in message
news:OK**************@TK2MSFTNGP05.phx.gbl...
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.
Nov 5 '07 #4
Hello,
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
Nov 15 '07 #5
Hi,

Serge Baltic wrote:
Hello,
>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
Nov 15 '07 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

15
by: Uncle_Alias | last post by:
I would like use some of the GD image functions, so I ran a couple of short scripts to see if it worked, such as: <?php /* Create a red square */ $image = imagecreate(200, 200); $colorRed =...
3
by: Rithish | last post by:
I have a set of images on a server. I want to pick these from the database without creating a temporary file on the server; and also have some text alongwith it. Something like, ...
4
by: Doug R | last post by:
I'm trying to create an anti-automation feature to prevent scripts from running reports on our website by requiring users to enter a code from an image (like Yahoo e-mail sign-up, or Network...
12
by: jaapkramer | last post by:
I have a page with 641 images in it. Each image can be clicked with as result that the image source will be changed. For this the images need to have a unique ID. But to do this manually for 641 is...
2
by: Paolo Pignatelli | last post by:
I am trying to get an output/file like this (below) in an XML file (MyXmlFile.xml) (which I will use for a slide show) -- <gallery timer="3" order="sequential" fadetime="2" looping="yes"...
4
by: Karthik Seetharaman | last post by:
I have to aspx pages default.aspx and imagegen.aspx default.aspx has an image webcontrol whose imageurl property is set to imagegen.aspx. imagegen.aspx generates a bitmap image and writes it to...
4
by: John.Arthur | last post by:
Hello, I need to create picture containing number that I will write in the picture. I need it to show it to the users of my application and they will write the number in a textBox, so this is to...
25
by: Mark Harrison | last post by:
I would like to try and build a queuing mechanism on top of Postgresql. Imagine an application where a large number of processes generate images and queue up thumbnail requests. A smaller number...
4
by: e_matthes | last post by:
Hello everyone, I'm trying to make a class that will generate images. I can get it to work if the class and the instance of the class is in the same file. However, I can't get it to work if I...
2
by: shotokan99 | last post by:
hi, i wanted to accomplish these task: 1. from that webservice get a certain set of strings from the header 2. next, generate the image. and these 2 steps will be done at the same time. to...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.