Click here to Skip to main content
13,559,015 members
Rate this:
Please Sign up or sign in to vote.
See more:
Hi all

I am using the below code to assign the barcode to be displayed in a canvas inside rectangle

for (int i = 0; i < len; i++)
               Rectangle rect = new Rectangle();
               rect.Height = 200;
               if (currentColor == 0)
                   currentColor = 1;
                   rect.Fill = new SolidColorBrush(Colors.Black);

                   currentColor = 0;
                   rect.Fill = new SolidColorBrush(Colors.White);

               Canvas.SetLeft(rect, currentPos);
               Canvas.SetTop(rect, currentTop);

               if (outputString[i] == 't')
                   rect.Width = thinWidth;
                   currentPos += thinWidth;

               else if (outputString[i] == 'w')
                   rect.Width = thickWidth;
                   currentPos += thickWidth;



Now i want to save that code as a image file.
Please tell me how to do that

Thank you
Posted 30-Jan-13 20:31pm
Rate this: bad
Please Sign up or sign in to vote.

Solution 3

As you already have a Canvas instance, the problem is reduced to producing a bitmap out of it. This is done using the class System.Windows.Media.Imaging.RenderTargetBitmap:[^].

You can find a complete code sample, for example, here:[^].

This solves your problem.


This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy |
Web04-2016 | 2.8.180515.1 | Last Updated 31 Jan 2013
Copyright © CodeProject, 1999-2018
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100