<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Farooq Azam &#187; application</title>
	<atom:link href="http://www.farooqazam.net/tag/application/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.farooqazam.net</link>
	<description>C# &#38; .NET Programming Blog</description>
	<lastBuildDate>Fri, 23 Jul 2010 20:15:42 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0</generator>
		<item>
		<title>Image Viewer application using C#</title>
		<link>http://www.farooqazam.net/image-viewer-application-using-c-sharp/</link>
		<comments>http://www.farooqazam.net/image-viewer-application-using-c-sharp/#comments</comments>
		<pubDate>Fri, 25 Sep 2009 17:38:45 +0000</pubDate>
		<dc:creator>Farooq Azam</dc:creator>
				<category><![CDATA[C#]]></category>
		<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[application]]></category>
		<category><![CDATA[c sharp]]></category>
		<category><![CDATA[image viewer]]></category>
		<category><![CDATA[picturebox]]></category>
		<category><![CDATA[rotate]]></category>

		<guid isPermaLink="false">http://www.farooqazam.net/?p=126</guid>
		<description><![CDATA[A detailed tutorial about creating an Image Viewer or Picture Viewer application in C#. This application also converts Images from one type to another. Following are the features of this application: Open / Save images. Convert images. Rotate Images. All popular image formats are supported. Let&#8217;s get started! Setting up the Designer For this application [...]]]></description>
			<content:encoded><![CDATA[<div class="tweetmeme_button" style="float: right; margin-left: 10px; margin-top: 10px;">
			<a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fwww.farooqazam.net%2Fimage-viewer-application-using-c-sharp%2F"><br />
				<img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fwww.farooqazam.net%2Fimage-viewer-application-using-c-sharp%2F&amp;source=farooqaaa&amp;style=normal" height="61" width="50" /><br />
			</a>
		</div>
<p><a title="Image Viewer" href="http://www.farooqazam.net/wp-content/uploads/2009/09/image-viewer.gif"><img class="alignnone size-full wp-image-127" title="image-viewer" src="http://www.farooqazam.net/wp-content/uploads/2009/09/image-viewer.gif" alt="image-viewer" width="469" height="411" /></a></p>
<p>A detailed tutorial about creating an Image Viewer or Picture Viewer application in C#. This application also converts Images from one type to another.</p>
<p>Following are the features of this application:</p>
<ul>
<li>Open / Save images.</li>
<li>Convert images.</li>
<li>Rotate Images.</li>
<li>All popular image formats are supported.</li>
</ul>
<p>Let&#8217;s get started!<span id="more-126"></span></p>
<h3>Setting up the Designer</h3>
<p>For this application you will need an openFileDialog, saveFileDialog, pictureBox and a few buttons.</p>
<ol>
<li>Add openFileDialog and saveFileDialog to the form.</li>
<li>Use this filter for the openFileDialog and saveFileDialog: &#8221; JPEG File|*.jpg|GIF File|*.gif|PNG File|*.png|BMP File|*.bmp &#8220;</li>
<li>Add 4 buttons (<a title="Image Viewer" href="http://www.farooqazam.net/wp-content/uploads/2009/09/image-viewer.gif">refer to the image above</a>). Name the buttons just like I&#8217;ve did in that image.</li>
<li>Set the &#8220;Enabled&#8221; property for &#8220;Save&#8221; button to &#8220;False&#8221;. And set &#8220;Visible&#8221; to &#8220;False&#8221; for &#8220;RotateClockwise&#8221; and &#8220;RotateCounterclockwise&#8221; buttons.</li>
<li>Add a pictureBox and place it under the buttons (refer to the image above).</li>
</ol>
<p>That&#8217;s it. Now lets get on with the code.</p>
<h3>The Code</h3>
<p>First of all, add this code to the very top of your form:</p>
<pre class="brush: csharp;">
using System.Drawing.Imaging;
</pre>
<p>Declare these methods after the &#8220;public Form1() { &#8230;.&#8221; method:</p>
<pre class="brush: csharp;">// This method will be used to save the image
private void saveImage(string ext)
{
   ImageFormat format = null;

   if(ext == &quot;.gif&quot;)
      format = ImageFormat.Gif;
   else if(ext == &quot;.jpg&quot; || ext == &quot;.jpeg&quot;)
      format = ImageFormat.Jpeg;
   else if(ext == &quot;png&quot;)
      format = ImageFormat.Png;
   else if(ext == &quot;.bmp&quot;)
      format = ImageFormat.Bmp;

   pictureBox1.Image.Save(saveFileDialog1.FileName, format);

}

// This method will be used for rotating the image.
private void rotateImage(int angle)
{
   Bitmap img = new Bitmap(pictureBox1.Image);

   // 0 = Clockwise, 1 = counter-clockwise

   if (angle == 0)
      img.RotateFlip(RotateFlipType.Rotate90FlipNone);
   else if (angle == 1)
      img.RotateFlip(RotateFlipType.Rotate90FlipXY);

   pictureBox1.Size = img.Size;
   pictureBox1.Image = img;
}
</pre>
<p>Double-click the &#8220;Open&#8221; button to add the &#8220;Click()&#8221; event for it and use this code:</p>
<pre class="brush: csharp;">private void openBtn_Click(object sender, EventArgs e)
{
   DialogResult result = openFileDialog1.ShowDialog();
   if (result == DialogResult.OK)
   {
      Image img = Image.FromFile(openFileDialog1.FileName);

      // Assigns the opened image to picturebox.
      pictureBox1.Image = img;

      // Makes the pictureBox width/height same as the opened image.
      pictureBox1.Width = img.Width;
      pictureBox1.Height = img.Height;
   }

   // Enables the Save button.
   saveBtn.Enabled = true;

   // Shows the RotateClockwise and Counterclockwise buttons.
   rotateClockwise.Show();
   rotateCounter.Show();
 }</pre>
<p>Double-click the Save button and use this code:</p>
<pre class="brush: csharp;">private void saveBtn_Click(object sender, EventArgs e)
{
   DialogResult res = saveFileDialog1.ShowDialog();
   if (res == DialogResult.OK)
   {
      // Extracts the extension from the opened file.
      string ext = System.IO.Path.GetExtension(saveFileDialog1.FileName);
      ext = ext.ToLower();

      saveImage(ext);
   }
}</pre>
<p>Double-click the RotateClockwise button and use this code:</p>
<pre class="brush: csharp;">private void rotateClockwise_Click(object sender, EventArgs e)
{
   // Calls the rotateImage method and passes the parameter &quot;0&quot;
   // Refer to the rotateImage method to see how it works.
   rotateImage(0);
}
</pre>
<p>And lastly, double-click the Rotate Counterclockwise button and use this code:</p>
<pre class="brush: csharp;"> private void rotateCounter_Click(object sender, EventArgs e)
{
   // 1 = counter-clockwise
   rotateImage(1);
}
</pre>
<p>That&#8217;s it! We are done.</p>
<h3>Source Code</h3>
<p>ImageViewer Source – <a title="Download ScreenCapture class" href="../source/ImageViewer.zip"><strong>Download Now</strong></a> (42 Kb)</p>
<p>&#8212;&#8212;</p>
<p>Feedback and comments are warmly welcome.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.farooqazam.net/image-viewer-application-using-c-sharp/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>Screen Capture Application using C#</title>
		<link>http://www.farooqazam.net/screen-capture-application-using-c-sharp/</link>
		<comments>http://www.farooqazam.net/screen-capture-application-using-c-sharp/#comments</comments>
		<pubDate>Fri, 11 Sep 2009 16:51:31 +0000</pubDate>
		<dc:creator>Farooq Azam</dc:creator>
				<category><![CDATA[C#]]></category>
		<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[application]]></category>
		<category><![CDATA[c sharp]]></category>
		<category><![CDATA[screen capture]]></category>
		<category><![CDATA[tutorial]]></category>

		<guid isPermaLink="false">http://www.farooqazam.net/?p=77</guid>
		<description><![CDATA[This is a detailed tutorial about making a simple Screen Capture (Screenshot Capture) application in C#. The features are: Take screenshot, view it and save it. We will be making a simple application but if you are little bit good with C# then you can enhance it and make it much better. Setting up the [...]]]></description>
			<content:encoded><![CDATA[<div class="tweetmeme_button" style="float: right; margin-left: 10px; margin-top: 10px;">
			<a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fwww.farooqazam.net%2Fscreen-capture-application-using-c-sharp%2F"><br />
				<img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fwww.farooqazam.net%2Fscreen-capture-application-using-c-sharp%2F&amp;source=farooqaaa&amp;style=normal" height="61" width="50" /><br />
			</a>
		</div>
<p><a title="Click to enlarge" href="../wp-content/uploads/2009/09/form1.gif"><img title="Screen Capture Application" src="../wp-content/uploads/2009/09/form1.gif" alt="Screen Capture Application" width="411" height="380" /></a></p>
<p>This is a detailed tutorial about making a simple Screen Capture (Screenshot Capture) application in C#. The features are: Take screenshot, view it and save it. We will be making a simple application but if you are little bit good with C# then you can enhance it and make it much better.</p>
<h3>Setting up the Form</h3>
<p>For this tutorial we will need 2 buttons, a timer, SaveFileDialog and a PictureBox. Here&#8217;s the info:<span id="more-77"></span></p>
<ol>
<li>Add a button first and set its &#8220;Text&#8221; property to &#8220;Take Screenshot&#8221; and &#8220;Name&#8221; property to &#8220;button1&#8243;.</li>
<li>Add another button and set &#8220;Text&#8221; property to &#8220;Save Screenshot&#8221;, set its &#8220;Enabled&#8221; property to &#8220;False&#8221; and &#8220;Name&#8221; property to &#8220;button2&#8243;.</li>
<li>Add a timer and set it &#8220;Interval&#8221; to &#8220;500&#8243; and make sure its &#8220;Enabled&#8221; property is set to &#8220;False&#8221;..</li>
<li>Now add SaveFileDialog and set &#8220;Filter&#8221; to &#8221; JPEG Files|*.jpg|GIF Files|*.gif|PNG Files|*.png &#8220;.</li>
<li>Finally, add a Picturebox.</li>
</ol>
<p>That&#8217;s it. The form is now set-up. Lets get on with the coding.</p>
<h3>The Coding</h3>
<p>First of all, declare these variables at the top of the form; i.e: just above &#8220;public form1() { &#8230;&#8230; &#8220;.</p>
<pre class="brush: csharp;">Graphics g;

// This will get the Size (width &amp;amp; height) of the screen.
Size screenBounds = Screen.PrimaryScreen.Bounds.Size;

public Form1()
 {
 InitializeComponent();
 }
</pre>
<p>Okay. Now double-click &#8220;Take Screenshot&#8221; button which will automatically add the &#8220;Click&#8221; event for it. Use this code:</p>
<pre class="brush: csharp;">private void button1_Click(object sender, EventArgs e)
{
   // We need to hide the form so that we can
   // capture the area behind it.
   this.Hide();
   timer1.Start();
}
</pre>
<p>We started the Timer in the above code. Now lets put it to some use.</p>
<p>Double-click the timer which will automatically add the &#8220;Tick&#8221; event for it. Use this code:</p>
<pre class="brush: csharp;">private void timer1_Tick(object sender, EventArgs e)
{
   // The screenshot will be stored in this bitmap.
   Bitmap capture = new Bitmap(screenBounds.Width, screenBounds.Height);

   // The code below takes the screenshot and
   // saves it in &quot;capture&quot; bitmap.
   g = Graphics.FromImage(capture);
   g.CopyFromScreen(Point.Empty, Point.Empty, screenBounds);

   // This code assigns the screenshot
   // to the Picturebox so that we can view it
   pictureBox1.Image = capture;

   // The code below make the form visible again, enables the &quot;Save&quot; button and stops the timer.
   this.Show();
   button2.Enabled = true;
   timer1.Stop();
}</pre>
<p>The Screenshot capturing and showing it on the picturebox part is done now. Now let&#8217;s add the code for the &#8220;Save Screenshot&#8221; button.</p>
<p>Double-click the Save Screenshot button which adds the &#8220;Click&#8221; event. Use this code:</p>
<pre class="brush: csharp;">private void button2_Click(object sender, EventArgs e)
{
// Show the SaveFileDialog
DialogResult res = saveFileDialog1.ShowDialog();

// Saves the screenshot if the OK button is clicked.
if (res == DialogResult.OK)
{
// This will get the extension of the saved file
string ext = System.IO.Path.GetExtension(saveFileDialog1.FileName);

if(ext == &quot;.jpg&quot;)
pictureBox1.Image.Save(saveFileDialog1.FileName, System.Drawing.Imaging.ImageFormat.Jpeg);
else if(ext == &quot;.gif&quot;)
pictureBox1.Image.Save(saveFileDialog1.FileName, System.Drawing.Imaging.ImageFormat.Gif);
else if(ext == &quot;.png&quot;)
pictureBox1.Image.Save(saveFileDialog1.FileName, System.Drawing.Imaging.ImageFormat.Png);
}
}</pre>
<p>That&#8217;s it! We are done.</p>
<h3>Source Code</h3>
<p><a title="Download Source Code" href="/source/ScreenCapture.rar"><strong>Download Now</strong></a> (36 Kb)</p>
<p>Feedback and comments are warmly welcome <img src='http://www.farooqazam.net/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> .</p>
]]></content:encoded>
			<wfw:commentRss>http://www.farooqazam.net/screen-capture-application-using-c-sharp/feed/</wfw:commentRss>
		<slash:comments>9</slash:comments>
		</item>
	</channel>
</rss>
