473,769 Members | 2,643 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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.

RenderTargetBit map rtb = new RenderTargetBit map(200, 200, 96, 96,
PixelFormats.Pb gra32);

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

rtb.Render(cir) ;

PngBitmapEncode r png = new PngBitmapEncode r();
png.Frames.Add( BitmapFrame.Cre ate(rtb));
using (Stream fs= File.Create("te st.png"))
{
png.Save(fs);
}

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

RenderTargetBit map rtb = new RenderTargetBit map(200, 200, 96, 96,
PixelFormats.Pb gra32);

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

rtb.Render(cir) ;

PngBitmapEncode r png = new PngBitmapEncode r();
png.Frames.Add( BitmapFrame.Cre ate(rtb));
using (Stream fs= File.Create("te st.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:

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

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

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

rtb.Render(cir) ;

PngBitmapEncode r png = new PngBitmapEncode r();
png.Frames.Add( BitmapFrame.Cre ate(rtb));
using (Stream fs= File.Create("te st.png"))
{
png.Save(fs);
}

Nov 5 '07 #3
"Tem" <te*****@yahoo. comwrote in message
news:OK******** ******@TK2MSFTN GP05.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:

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

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

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

rtb.Render(cir) ;

PngBitmapEncode r png = new PngBitmapEncode r();
png.Frames.Add( BitmapFrame.Cre ate(rtb));
using (Stream fs= File.Create("te st.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
19103
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 = imagecolorallocate($image, 255, 0, 0); imagefill($image, 0, 0, $colorRed);
3
2337
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, ImageViewer.php <?
4
2447
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 Solutions WHOIS search). I'm using Python as the scripting language in the ASP page, and using PIL to generate the image. The code is stored into a session variable, which is used to check the user's entry. It works fine the first time around, but...
12
12300
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 just too much. Is there a way to give each image his own unique id without setting them myself? The image: <img src="images/hokje.gif" id="" onClick="javascript:veranderKeuze(this.id);" alt="">
2
2510
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" xpos="0" ypos="0"> <image path="images2/Test1.jpg" />
4
6079
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 outputstream and this image is then displayed in default.aspx Now i would like to generate a map for this image so i can have different regions of the image hyperlink to some urls. How to accomplish this ?
4
10652
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 prevent automatic activities with my application and to keep bots away. But I have no idea how can I create a picture containing number or text. Can someone help please?
25
2787
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 of processes (running on a dedicated set of machines) generate thumbnails for those images. Adding entries to the queue from multiple processes is easy, by executing statements such as: insert into nameq(action,name) values('add','foo');
4
1716
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 save the class as its own file, and try to make an instance of it in another file. Any thoughts? Here is the working version: <?php
2
1659
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 get the header value: $ch = curl_init();
0
9423
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10047
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9995
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8872
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6674
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5304
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5447
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3962
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2815
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.