System.Drawing/GDI+http://forums.asp.net/150.aspx/1?System+Drawing+GDI+Discuss manipulating and creating graphics using the System.Drawing namespace and GDI+.Tue, 18 Jun 2013 00:02:59 -0400urn:uuid:00000000-0000-0000-0000-000000000150urn:uuid:00000000-0000-0000-0000-000005427972http://forums.asp.net/p/1915615/5427972.aspx/1?Gets+the+percentage+of+picture+color+Gets the percentage of picture color <p>I think obtained through c# percentage of picture Color&nbsp;</p> <p>If the PHP program&nbsp;<a href="http://www.coolphptools.com/color_extract">http://www.coolphptools.com/color_extract</a></p> <p><img src="http://24.media.tumblr.com/752f3552c16d95c2dac6537a3c693c32/tumblr_mokm1cVu581rtkucho1_500.png" width="453" height="305"></p> <p>This is the PHP code, but I'm not putting it into c#</p> <pre class="prettyprint">&lt;?php class GetMostCommonColors { var $PREVIEW_WIDTH = 150; var $PREVIEW_HEIGHT = 150; var $error; /** * Returns the colors of the image in an array, ordered in descending order, where the keys are the colors, and the values are the count of the color. * * @return array */ function Get_Color( $img, $count=20, $reduce_brightness=true, $reduce_gradients=true, $delta=16 ) { if (is_readable( $img )) { if ( $delta &gt; 2 ) { $half_delta = $delta / 2 - 1; } else { $half_delta = 0; } // WE HAVE TO RESIZE THE IMAGE, BECAUSE WE ONLY NEED THE MOST SIGNIFICANT COLORS. $size = GetImageSize($img); $scale = 1; if ($size[0]&gt;0) $scale = min($this-&gt;PREVIEW_WIDTH/$size[0], $this-&gt;PREVIEW_HEIGHT/$size[1]); if ($scale &lt; 1) { $width = floor($scale*$size[0]); $height = floor($scale*$size[1]); } else { $width = $size[0]; $height = $size[1]; } $image_resized = imagecreatetruecolor($width, $height); if ($size[2] == 1) $image_orig = imagecreatefromgif($img); if ($size[2] == 2) $image_orig = imagecreatefromjpeg($img); if ($size[2] == 3) $image_orig = imagecreatefrompng($img); // WE NEED NEAREST NEIGHBOR RESIZING, BECAUSE IT DOESN'T ALTER THE COLORS imagecopyresampled($image_resized, $image_orig, 0, 0, 0, 0, $width, $height, $size[0], $size[1]); $im = $image_resized; $imgWidth = imagesx($im); $imgHeight = imagesy($im); $total_pixel_count = 0; for ($y=0; $y &lt; $imgHeight; $y&#43;&#43;) { for ($x=0; $x &lt; $imgWidth; $x&#43;&#43;) { $total_pixel_count&#43;&#43;; $index = imagecolorat($im,$x,$y); $colors = imagecolorsforindex($im,$index); // ROUND THE COLORS, TO REDUCE THE NUMBER OF DUPLICATE COLORS if ( $delta &gt; 1 ) { $colors['red'] = intval((($colors['red'])&#43;$half_delta)/$delta)*$delta; $colors['green'] = intval((($colors['green'])&#43;$half_delta)/$delta)*$delta; $colors['blue'] = intval((($colors['blue'])&#43;$half_delta)/$delta)*$delta; if ($colors['red'] &gt;= 256) { $colors['red'] = 255; } if ($colors['green'] &gt;= 256) { $colors['green'] = 255; } if ($colors['blue'] &gt;= 256) { $colors['blue'] = 255; } } $hex = substr(&quot;0&quot;.dechex($colors['red']),-2).substr(&quot;0&quot;.dechex($colors['green']),-2).substr(&quot;0&quot;.dechex($colors['blue']),-2); if ( ! isset( $hexarray[$hex] ) ) { $hexarray[$hex] = 1; } else { $hexarray[$hex]&#43;&#43;; } } } // Reduce gradient colors if ( $reduce_gradients ) { // if you want to *eliminate* gradient variations use: // ksort( &amp;$hexarray ); arsort( &amp;$hexarray, SORT_NUMERIC ); $gradients = array(); foreach ($hexarray as $hex =&gt; $num) { if ( ! isset($gradients[$hex]) ) { $new_hex = $this-&gt;_find_adjacent( $hex, $gradients, $delta ); $gradients[$hex] = $new_hex; } else { $new_hex = $gradients[$hex]; } if ($hex != $new_hex) { $hexarray[$hex] = 0; $hexarray[$new_hex] &#43;= $num; } } } // Reduce brightness variations if ( $reduce_brightness ) { // if you want to *eliminate* brightness variations use: // ksort( &amp;$hexarray ); arsort( &amp;$hexarray, SORT_NUMERIC ); $brightness = array(); foreach ($hexarray as $hex =&gt; $num) { if ( ! isset($brightness[$hex]) ) { $new_hex = $this-&gt;_normalize( $hex, $brightness, $delta ); $brightness[$hex] = $new_hex; } else { $new_hex = $brightness[$hex]; } if ($hex != $new_hex) { $hexarray[$hex] = 0; $hexarray[$new_hex] &#43;= $num; } } } arsort( &amp;$hexarray, SORT_NUMERIC ); // convert counts to percentages foreach ($hexarray as $key =&gt; $value) { $hexarray[$key] = (float)$value / $total_pixel_count; } if ( $count &gt; 0 ) { // only works in PHP5 // return array_slice( $hexarray, 0, $count, true ); $arr = array(); foreach ($hexarray as $key =&gt; $value) { if ($count == 0) { break; } $count--; $arr[$key] = $value; } return $arr; } else { return $hexarray; } } else { $this-&gt;error = &quot;Image &quot;.$img.&quot; does not exist or is unreadable&quot;; return false; } } function _normalize( $hex, $hexarray, $delta ) { $lowest = 255; $highest = 0; $colors['red'] = hexdec( substr( $hex, 0, 2 ) ); $colors['green'] = hexdec( substr( $hex, 2, 2 ) ); $colors['blue'] = hexdec( substr( $hex, 4, 2 ) ); if ($colors['red'] &lt; $lowest) { $lowest = $colors['red']; } if ($colors['green'] &lt; $lowest ) { $lowest = $colors['green']; } if ($colors['blue'] &lt; $lowest ) { $lowest = $colors['blue']; } if ($colors['red'] &gt; $highest) { $highest = $colors['red']; } if ($colors['green'] &gt; $highest ) { $highest = $colors['green']; } if ($colors['blue'] &gt; $highest ) { $highest = $colors['blue']; } // Do not normalize white, black, or shades of grey unless low delta if ( $lowest == $highest ) { if ($delta &lt;= 32) { if ( $lowest == 0 || $highest &gt;= (255 - $delta) ) { return $hex; } } else { return $hex; } } for (; $highest &lt; 256; $lowest &#43;= $delta, $highest &#43;= $delta) { $new_hex = substr(&quot;0&quot;.dechex($colors['red'] - $lowest),-2).substr(&quot;0&quot;.dechex($colors['green'] - $lowest),-2).substr(&quot;0&quot;.dechex($colors['blue'] - $lowest),-2); if ( isset( $hexarray[$new_hex] ) ) { // same color, different brightness - use it instead return $new_hex; } } return $hex; } function _find_adjacent( $hex, $gradients, $delta ) { $red = hexdec( substr( $hex, 0, 2 ) ); $green = hexdec( substr( $hex, 2, 2 ) ); $blue = hexdec( substr( $hex, 4, 2 ) ); if ($red &gt; $delta) { $new_hex = substr(&quot;0&quot;.dechex($red - $delta),-2).substr(&quot;0&quot;.dechex($green),-2).substr(&quot;0&quot;.dechex($blue),-2); if ( isset($gradients[$new_hex]) ) { return $gradients[$new_hex]; } } if ($green &gt; $delta) { $new_hex = substr(&quot;0&quot;.dechex($red),-2).substr(&quot;0&quot;.dechex($green - $delta),-2).substr(&quot;0&quot;.dechex($blue),-2); if ( isset($gradients[$new_hex]) ) { return $gradients[$new_hex]; } } if ($blue &gt; $delta) { $new_hex = substr(&quot;0&quot;.dechex($red),-2).substr(&quot;0&quot;.dechex($green),-2).substr(&quot;0&quot;.dechex($blue - $delta),-2); if ( isset($gradients[$new_hex]) ) { return $gradients[$new_hex]; } } if ($red &lt; (255 - $delta)) { $new_hex = substr(&quot;0&quot;.dechex($red &#43; $delta),-2).substr(&quot;0&quot;.dechex($green),-2).substr(&quot;0&quot;.dechex($blue),-2); if ( isset($gradients[$new_hex]) ) { return $gradients[$new_hex]; } } if ($green &lt; (255 - $delta)) { $new_hex = substr(&quot;0&quot;.dechex($red),-2).substr(&quot;0&quot;.dechex($green &#43; $delta),-2).substr(&quot;0&quot;.dechex($blue),-2); if ( isset($gradients[$new_hex]) ) { return $gradients[$new_hex]; } } if ($blue &lt; (255 - $delta)) { $new_hex = substr(&quot;0&quot;.dechex($red),-2).substr(&quot;0&quot;.dechex($green),-2).substr(&quot;0&quot;.dechex($blue &#43; $delta),-2); if ( isset($gradients[$new_hex]) ) { return $gradients[$new_hex]; } } return $hex; } } ?&gt;</pre> <p></p> 2013-06-18T04:02:59-04:002013-06-18T04:02:59.103-04:00urn:uuid:00000000-0000-0000-0000-000005420966http://forums.asp.net/p/1913205/5420966.aspx/1?Maintaining+TransparencyMaintaining Transparency <p>I’d like to write to an image file that has a transparent background but get the message:</p> <p>A Graphics object cannot be created from an image that has an indexed pixel format.</p> <p>&nbsp;</p> <p><a href="http://getlara.com/north-america/canada/alberta/edmonton/post/2008/10/13/png-jpg-gif-image-resize-with-net-with-transparency">http://getlara.com/north-america/canada/alberta/edmonton/post/2008/10/13/png-jpg-gif-image-resize-with-net-with-transparency</a></p> <p>&nbsp;</p> <p>According to the info in the link above, you can maintain transparency.</p> <p>“The key to success in this method (and how it differs from the microsoft examples) is in the declaration of the Bitmap object with the pixel format parameter as the OriginalImage pixel format. The following code has been tested with transparent PNGs, GIFs and with JPG formats and should work for other formats as well.”</p> <p>The code below is a slightly modified version of getlara’s example. However,&nbsp; on</p> <pre>using (Graphics Canvas = Graphics.FromImage(NewImage))</pre> <p>I’m still getting the indexed pixel format error message.&nbsp; Am I doing something wrong?</p> <p>&nbsp;</p> <p>Thanks,</p> <p>&nbsp;</p> <p>Robin</p> <p>*******************************************************************</p> <p>&lt;%@ Page Language=&quot;C#&quot; Debug = &quot;true&quot;%&gt;</p> <p>&lt;%@ Import Namespace=&quot;System.IO&quot; %&gt;</p> <p>&lt;%@ Import Namespace=&quot;System.Drawing&quot; %&gt;</p> <p>&lt;%@ Import Namespace=&quot;System.Drawing.Drawing2D&quot; %&gt;</p> <p>&lt;%@ Import Namespace=&quot;System.Drawing.Text&quot; %&gt;</p> <p>&lt;%@ Import Namespace=&quot;System.Drawing.Imaging&quot; %&gt;</p> <p>&lt;script runat=&quot;server&quot;&gt;</p> <p>&nbsp;</p> <p>void Page_Load(Object Sender,EventArgs e)</p> <p>&nbsp;</p> <p>{</p> <p>&nbsp;&nbsp;&nbsp; int Height;</p> <p>&nbsp;&nbsp;&nbsp; int Width;</p> <p>&nbsp;</p> <p>&nbsp;&nbsp;&nbsp; Height = 100;</p> <p>&nbsp;&nbsp;&nbsp; Width = 400;</p> <p>&nbsp;</p> <p>&nbsp;&nbsp;&nbsp; Size NewSize = new Size(Width, Height);</p> <p>&nbsp;</p> <p>&nbsp;&nbsp;&nbsp; using (System.Drawing.Image OriginalImage = System.Drawing.Image.FromFile(Server.MapPath(&quot;generic.gif&quot;)))</p> <p>&nbsp;&nbsp;&nbsp; {</p> <p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; //Graphics objects can not be created from bitmaps with an Indexed Pixel Format, use RGB instead.</p> <p>&nbsp;</p> <p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; PixelFormat Format = OriginalImage.PixelFormat;</p> <p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if (Format.ToString().Contains(&quot;Indexed&quot;))</p> <p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Format = PixelFormat.Format24bppRgb;</p> <p>&nbsp;</p> <p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; using (Bitmap NewImage = new Bitmap(NewSize.Width, NewSize.Height, OriginalImage.PixelFormat))</p> <p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {</p> <p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; using (Graphics Canvas = Graphics.FromImage(NewImage))</p> <p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {</p> <p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Canvas.SmoothingMode = SmoothingMode.AntiAlias;</p> <p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Canvas.InterpolationMode = InterpolationMode.HighQualityBicubic;</p> <p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Canvas.PixelOffsetMode = PixelOffsetMode.HighQuality;</p> <p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Canvas.DrawImage(OriginalImage, new Rectangle(new Point(0, 0), NewSize));</p> <p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; NewImage.Save(&quot;generic2.gif&quot;, OriginalImage.RawFormat);</p> <p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }</p> <p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }</p> <p>&nbsp;&nbsp;&nbsp; }</p> <p>&nbsp;</p> <p>}</p> <p>&lt;/script&gt;</p> <p>&nbsp;</p> <p>&nbsp;</p> 2013-06-11T15:08:11-04:002013-06-11T15:08:11.443-04:00urn:uuid:00000000-0000-0000-0000-000002920851http://forums.asp.net/p/1381087/2920851.aspx/1?Image+gets+saved+10x+bigger+than+the+original+file+sizeImage gets saved 10x bigger than the original file size <p>&nbsp;Hi,</p> <p>I've created an image upload section, which allows the user to upload an image, which then creates a thumbnail version, and resizes the original too. However when the user uploads an image which is around 600KB, the main image gets resized to about 7MB. I've attached my source, any help would be most appreciated.</p> <p>&nbsp;&nbsp;</p> <pre class="prettyprint">Sub SaveImage(ByVal ImageID As String) Dim DisplaySizeWidth As Integer = 572 FU1.SaveAs(Server.MapPath(&quot;/Uploads/Gallery/Temp/&quot; &#43; ImageID &#43; &quot;.jpg&quot;)) Dim Bmp As New Bitmap(Server.MapPath(&quot;/Uploads/Gallery/Temp/&quot; &#43; ImageID &#43; &quot;.jpg&quot;)) Dim OriginalWidth As Integer = Bmp.Width Dim SizeToResize_Width As Integer = DisplaySizeWidth * 3 Dim Height As Decimal = Bmp.Height * (SizeToResize_Width / OriginalWidth) Dim Bmp_G As Graphics = Graphics.FromImage(Bmp) Bmp_G.InterpolationMode = InterpolationMode.Low Bmp_G.CompositingQuality = CompositingQuality.Invalid Bmp_G.SmoothingMode = SmoothingMode.None Bmp = img.thumb(Bmp, SizeToResize_Width, Height) Bmp.Save(Server.MapPath(&quot;/Uploads/Gallery/&quot; &#43; ImageID &#43; &quot;.jpg&quot;)) 'Save Thumbnail Image Dim Th_Height As Integer = 82 Dim Th_Width As Integer = SizeToResize_Width * (Th_Height / Height) If Th_Width &amp;gt; 106 Then Th_Width = 106 End If Bmp = img.thumb(Bmp, Th_Width, Th_Height) Bmp.Save(Server.MapPath(&quot;/Uploads/Gallery/Thumb/&quot; &#43; ImageID &#43; &quot;.jpg&quot;)) Bmp.Dispose() Bmp_G.Dispose() Utils.DeleteFile(&quot;/Uploads/Gallery/Temp/&quot; &#43; ImageID &#43; &quot;.jpg&quot;) End Sub</pre>&nbsp; <br> 2009-02-06T08:12:28-05:002009-02-06T08:12:28.27-05:00urn:uuid:00000000-0000-0000-0000-000000453912http://forums.asp.net/p/453912/453912.aspx/1?System+Drawing+Namespace+cannot+be+found+System.Drawing Namespace "cannot be found" Hi, I wonder if anyone can help. I have placed the following in one of my code behind files: Imports System.Drawing Imports System.Drawing.Imaging When I compile I get the following error: Namespace or type 'Drawing' for the imports 'System.Drawing' cannot be found I don't understand why this is happening. When I import other namespaces I don't have any problems. Do I have to install something else to enable me to use the drawing namespace? I'm totaly lost! cheers 2004-01-26T06:07:37-05:002004-01-26T06:07:37.45-05:00urn:uuid:00000000-0000-0000-0000-000005412795http://forums.asp.net/p/1911314/5412795.aspx/1?How+To+Set+BackGround+Color+of+image+using+image+processing+How To Set BackGround Color of image ,using image processing <p>I&nbsp; have image&nbsp; format of&nbsp; .Png , I done compression of image using image.Thumbnail() to 180X35 size but after compress,I am getting gray color image ....of that original one...but same image background color is white ...I am getting good result means..no gray color image .....exactly what i need&nbsp; that only i am,getting so at&nbsp; i want to change the ,background color&nbsp; image of ..at run-time ..how to do that one....any one can you replay me....&nbsp;</p> 2013-06-03T14:01:50-04:002013-06-03T14:01:50.673-04:00urn:uuid:00000000-0000-0000-0000-000005126380http://forums.asp.net/p/1838561/5126380.aspx/1?printing+in+asp+netprinting in asp.net <p>How can i implement printing in asp.net to print my web form</p> 2012-08-29T15:16:53-04:002012-08-29T15:16:53.903-04:00urn:uuid:00000000-0000-0000-0000-000005405498http://forums.asp.net/p/1909647/5405498.aspx/1?The+process+cannot+access+the+file+C+BLAHWEB+www+Uploads+Products+2+c2+jpg+because+it+is+being+used+by+another+process+The process cannot access the file 'C:\BLAHWEB\www\Uploads\Products\2\c2.jpg' because it is being used by another process. <p>This is my method working on localhost but not on webhosting.</p> <p>stuck at the error :</p> <p><strong><span style="text-decoration:underline">The process cannot access the file 'C:\BLAHWEB\www\Uploads\Products\2\c2.jpg' because it is being used by another process.</span></strong></p> <p></p> <p>cant fix this problem albeit already surrounded objects via &quot;<span style="text-decoration:underline"><strong>using</strong></span>&quot; reserver word.</p> <p></p> <p>this is my method working on local but not on web.</p> <p>I can upload files to Upload directory. so I dont think this is a security issue.</p> <p>Im using asp.net 4</p> <p></p> <p>what do you prefer for me ?</p> <p></p> <pre style="font-family:Consolas; font-size:13; color:black; background:white">&nbsp;&nbsp;<span style="color:blue">public</span>&nbsp;<span style="color:blue">void</span>&nbsp;CropImage(<span style="color:blue">string</span>&nbsp;path,&nbsp;<span style="color:blue">int</span>&nbsp;X,&nbsp;<span style="color:blue">int</span>&nbsp;Y,&nbsp;<span style="color:blue">int</span>&nbsp;Width,&nbsp;<span style="color:blue">int</span>&nbsp;Height) &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{ &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color:blue">using</span>&nbsp;(System.Drawing.<span style="color:#2b91af">Image</span>&nbsp;img&nbsp;=&nbsp;System.Drawing.<span style="color:#2b91af">Image</span>.FromFile(path)) &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{ &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color:blue">string</span>&nbsp;ImgName&nbsp;=&nbsp;System.IO.<span style="color:#2b91af">Path</span>.GetFileName(path); &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color:blue">using</span>&nbsp;(<span style="color:#2b91af">Bitmap</span>&nbsp;bmpCropped&nbsp;=&nbsp;<span style="color:blue">new</span>&nbsp;<span style="color:#2b91af">Bitmap</span>(Width,&nbsp;Height)) &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{ &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color:blue">using</span>&nbsp;(<span style="color:#2b91af">Graphics</span>&nbsp;g&nbsp;=&nbsp;<span style="color:#2b91af">Graphics</span>.FromImage(bmpCropped)) &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{ &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color:#2b91af">Rectangle</span>&nbsp;rectDestination&nbsp;=&nbsp;<span style="color:blue">new</span>&nbsp;<span style="color:#2b91af">Rectangle</span>(0,&nbsp;0,&nbsp;bmpCropped.Width,&nbsp;bmpCropped.Height); &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color:#2b91af">Rectangle</span>&nbsp;rectCropArea&nbsp;=&nbsp;<span style="color:blue">new</span>&nbsp;<span style="color:#2b91af">Rectangle</span>(X,&nbsp;Y,&nbsp;Width,&nbsp;Height); &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;g.DrawImage(img,&nbsp;rectDestination,&nbsp;rectCropArea,&nbsp;<span style="color:#2b91af">GraphicsUnit</span>.Pixel); &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color:blue">string</span>&nbsp;FileNameAndExt&nbsp;=&nbsp;System.IO.<span style="color:#2b91af">Path</span>.GetFileName(path); &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;bmpCropped.Save(path&nbsp;&#43;&nbsp;<span style="color:#a31515">&quot;.tmp&quot;</span>); &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; //System.Threading.<span style="color:#2b91af">Thread</span>.Sleep(1000); &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;g.Dispose(); &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;} &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; //System.Threading.<span style="color:#2b91af">Thread</span>.Sleep(1000); &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;bmpCropped.Dispose(); &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;} &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ///System.Threading.<span style="color:#2b91af">Thread</span>.Sleep(1000); &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;img.Dispose(); &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}</pre> 2013-05-26T17:09:17-04:002013-05-26T17:09:17.88-04:00urn:uuid:00000000-0000-0000-0000-000005374766http://forums.asp.net/p/1901587/5374766.aspx/1?solusion+A+generic+error+occurred+in+GDI+solusion:A generic error occurred in GDI+. <p>my code here:</p> <p>protected void crop(decimal imagewidthm, decimal maxwidthm, decimal imageheightm, decimal maxheightm, Stream sourcePathm, string output)<br> &nbsp;&nbsp;&nbsp; {<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if (imagewidthm &gt; maxwidthm)<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ratio = maxwidthm / imagewidthm;<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; imagewidthm = imagewidthm * ratio;<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; imageheightm = imageheightm * ratio;<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if (imageheightm &gt; maxheightm)<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ratio = maxheightm / imageheightm;<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; imageheightm = maxheightm;<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; imagewidthm = imagewidthm * ratio;<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; using (var image = System.Drawing.Image.FromStream(sourcePathm))<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; var newWidth = (int)(imagewidthm);<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; var newHeight = (int)(imageheightm);<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; var thumbnailImg = new Bitmap(newWidth, newHeight);<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; var thumbGraph = Graphics.FromImage(thumbnailImg);<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; thumbGraph.CompositingQuality = CompositingQuality.HighQuality;<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; thumbGraph.SmoothingMode = SmoothingMode.HighQuality;<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; thumbGraph.InterpolationMode = InterpolationMode.HighQualityBicubic;<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; var imageRectangle = new Rectangle(0, 0, newWidth, newHeight);<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; thumbGraph.DrawImage(image, imageRectangle);<br> <strong>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; thumbnailImg.Save(output, image.RawFormat);</strong> <strong> // ERROR HERE</strong><br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<br> &nbsp;&nbsp;&nbsp; }</p> <p>how to solve it.....</p> 2013-04-25T09:51:40-04:002013-04-25T09:51:40.303-04:00urn:uuid:00000000-0000-0000-0000-000005401264http://forums.asp.net/p/1908554/5401264.aspx/1?Resize+imageResize image <p>Hello All,</p> <p>I am uploading images in my project... Now i want to resize image to some fixed width and height...</p> <p>For i.e. whatever the size of image is, if it is more than 160*120 then I want to resize it to fixed pixels of 160*120...</p> <p>How to do it ???</p> 2013-05-21T17:21:26-04:002013-05-21T17:21:26.07-04:00urn:uuid:00000000-0000-0000-0000-000005398853http://forums.asp.net/p/1908001/5398853.aspx/1?Creating+Clickable+Lines+on+PolygonsCreating Clickable Lines on Polygons <p>Hello All,</p> <p>I would like to create rectangles whose colors, dimensions, line thickness, and locations I can manipulate after they are created using the mouse. Basically I would like to be able to change the thickness, size, and color of their sides by clicking on any side then editing it. I'd also like to be able to move each rectangle as a whole to any location on the panel. Currently, rectangles drawn using the DrawRectangle method do not have the ability to do what I've just described. Any help will be appreciated, thanks.</p> 2013-05-19T05:25:53-04:002013-05-19T05:25:53.843-04:00urn:uuid:00000000-0000-0000-0000-000005269053http://forums.asp.net/p/1874769/5269053.aspx/1?Image+Uploading+ProblemImage Uploading Problem <p>Hi all,</p> <p>This might not be the correct forum to post this in for which I apologise in advance. I urgently need some assistance with resizing and uploading images (JPG files) to my web server (Windows Web Server 2008 R2 with IIS 7).</p> <p>I have a routine whereby users can select any number of images (JPG files) using an Obout File Upload control and then upload the selected images to the web server. Prior to uploading the images are resized according to specification and subsequently stored in the appropriate folder on the server.</p> <p>This process works perfectly in the development environment: the images are resized according to specification and saved in the correct folders. However, in the production environment the images are not saved, despite it appearing that the resizing processes are completed without error (no error messages are displayed) the images are not saved in the correct folders.</p> <p>The above leads me to believe that the problem resides on Windows Web Server and, or, IIS 7. I have triple-checked user permissions and can confirm that the relevant user account does have reading and writing permissions to the particular parent and child folders. In support consider that another process in the app has to affect that for each new record 2 new child folders (1 folder wherein images are stored and another folder wherein PDF files are stored) are created in 2 separate parent folders. The permissions on both parent folders are exactly the same. The process to create the new folders works perfectly in the production environment so too the process to upload PDF files.</p> <p>The code being used is:</p> <pre class="prettyprint">If fuPhotosAdd.PostedFiles.Count &gt; 0 Then Do Until TempCounter = fuPhotosAdd.PostedFiles.Count Dim TempImage As New System.Drawing.Bitmap(fuPhotosAdd.PostedFiles(TempCounter).InputStream) Dim NewImage As New System.Drawing.Bitmap(TempImage, TempImageWidth, TempImageHeight) If Not Directory.Exists(&quot;~/Photos/&quot; &amp; txtRecordNumber.Text) Then Directory.CreateDirectory(Server.MapPath(&quot;~/Photos/&quot; &amp; txtRecordNumber.Text)) TempPath = &quot;~/Photos/&quot; &amp; txtRecordNumber.Text &amp; &quot;/&quot; TempPath = TempPath &amp; txtRecordNumber.Text &amp; &quot; &quot; &amp; FormatDateTime(txtPhotoDate.Text, DateFormat.ShortDate) &amp; &quot; (&quot; &amp; Format(TempPhotoCounter, &quot;000&quot;) &amp; &quot;).jpg&quot; NewImage.Save(Page.MapPath(TempPath), System.Drawing.Imaging.ImageFormat.Jpeg) NewImage.Dispose() TempImage.Dispose() TempCounter = TempCounter &#43; 1 TempPhotoCounter = TempPhotoCounter &#43; 1 Loop End If</pre> <p><br> Any advice?</p> 2013-01-13T13:59:11-05:002013-01-13T13:59:11.65-05:00urn:uuid:00000000-0000-0000-0000-000004708863http://forums.asp.net/p/1745033/4708863.aspx/1?How+to+Create+Thumbnail+of+an+imageHow to Create Thumbnail of an image <p>Hi to all,</p> <p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; I want to create the thumbnail of uploaded image and want to save this thumbnail at my given destination</p> <p>I have need of VB.net Code for this plz Help me</p> <p>Regards</p> <p>Ahsan</p> 2011-11-30T15:56:11-05:002011-11-30T15:56:11.82-05:00urn:uuid:00000000-0000-0000-0000-000005381593http://forums.asp.net/p/1903143/5381593.aspx/1?Need+help+in+Moveable+MaskNeed help in Moveable Mask <p>hi everybody,</p> <p>i need help in masking. i have an image and client want me to highlight specific portion on image by clicking on it. i mean when user click on image, a pre defined mask (a predefined and presized simple yellow transparent&nbsp; box) apperas on clicked area. and if he clicks on some other place of same image. old mask should be moved to new place....</p> <p>any ideas for it??</p> <p>i shall be thankfull to you.</p> 2013-05-02T04:55:14-04:002013-05-02T04:55:14.96-04:00urn:uuid:00000000-0000-0000-0000-000004503850http://forums.asp.net/p/1699175/4503850.aspx/1?+A+generic+error+occurred+in+GDI+while+trying+to+render+a+PNG+image"A generic error occurred in GDI+." while trying to render a PNG image <p>I have a weird thing going on. I'm trying to generate an image in the C# code like this:</p> <pre class="prettyprint">Response.ContentType = &quot;image/png&quot;; bmp.Save(Response.OutputStream, ImageFormat.Png); //Exception happens here</pre> <p>One one computer with the same exact installation of VS2010 and ,net framework 4 it works fine, but on another one I get an exception with the following message: &quot;A generic error occurred in GDI&#43;.&quot;</p> <p>How can I fix it?&nbsp;</p> 2011-07-12T18:28:00-04:002011-07-12T18:28:00.78-04:00urn:uuid:00000000-0000-0000-0000-000005372570http://forums.asp.net/p/1901097/5372570.aspx/1?Memory+clearing+after+using+InputStream+and+sending+image+as+Parameter+to+a+FunctionMemory clearing after using InputStream and sending image as Parameter to a Function <p>Hi,</p> <p>Please can anyone check the following code, I'd like to see if I missed anything in order to clear the memory, tried to use dispose()</p> <p>thanks in advance.</p> <pre class="prettyprint">'--- CREATING THUMBNAILS /---- Dim imgStream As System.Drawing.Image = System.Drawing.Image.FromStream(uploadImage.PostedFile.InputStream) Site_Core_.Forum_Core_.SaveThumbnails(150, 75, iUploadDir &amp; iMedia_Id &amp; &quot;.jpg&quot;, imgStream) imgStream.Dispose() '--- FUNCTION /---- Public Shared Function SaveThumbnails(ByVal iWidth As Integer, ByVal iHeight As Integer, ByVal iUploadDir As String, ByVal ImageStream As Image) As Integer Dim srcWidth As Integer = ImageStream.Width Dim srcHeight As Integer = ImageStream.Height Dim iImage As New Bitmap(iWidth, iHeight) Dim gr As System.Drawing.Graphics = System.Drawing.Graphics.FromImage(iImage) gr.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality gr.CompositingQuality = System.Drawing.Drawing2D.CompositingQuality.HighQuality gr.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.HighQualityBicubic Dim rectDestination As New System.Drawing.Rectangle(0, 0, iWidth, iHeight) gr.DrawImage(ImageStream, rectDestination, 0, 0, srcWidth, srcHeight, GraphicsUnit.Pixel) Try iImage.Save(iUploadDir, System.Drawing.Imaging.ImageFormat.Jpeg) Finally iImage.Dispose() gr.Dispose() ImageStream.Dispose() End Try End Function</pre> <p><br> <br> </p> <p></p> <p></p> <p></p> 2013-04-23T13:26:34-04:002013-04-23T13:26:34.863-04:00urn:uuid:00000000-0000-0000-0000-000002769212http://forums.asp.net/p/1353341/2769212.aspx/1?System+Runtime+InteropServices+ExternalException+A+generic+error+occurred+in+GDI+System.Runtime.InteropServices.ExternalException: A generic error occurred in GDI+. <p>First of all </p> <p>good evenning all.</p> <p>I am facing an&nbsp;error --System.Runtime.InteropServices.ExternalException: A generic error occurred in GDI&#43;.</p> <p>its very strange that locally&nbsp;my code working fine my code is&nbsp;</p> <font size="2"> <p></font><font color="#808080" size="2">///</font><font color="#008000" size="2"> </font><font color="#808080" size="2">&lt;summary&gt;</p> </font><font size="2"> <p></font><font color="#808080" size="2">///</font><font color="#008000" size="2"> This method upload a file in a folder and return the path of file</p> </font><font size="2"> <p></font><font color="#808080" size="2">///</font><font color="#008000" size="2"> </font><font color="#808080" size="2">&lt;/summary&gt;</p> </font><font size="2"> <p></font><font color="#808080" size="2">///</font><font color="#008000" size="2"> </font><font color="#808080" size="2">&lt;param name=&quot;filename&quot;&gt;&lt;/param&gt;</p> </font><font size="2"> <p></font><font color="#808080" size="2">///</font><font color="#008000" size="2"> </font><font color="#808080" size="2">&lt;param name=&quot;fileUpload&quot;&gt;&lt;/param&gt;</p> </font><font size="2"> <p></font><font color="#808080" size="2">///</font><font color="#008000" size="2"> </font><font color="#808080" size="2">&lt;returns&gt;&lt;/returns&gt;</p> </font><font size="2"></font><font color="#0000ff" size="2">private</font><font size="2"> </font><font color="#0000ff" size="2">string</font><font size="2"> UploadImage(</font><font color="#2b91af" size="2">FileUpload</font><font size="2"> fileUpload)</font><font size="2"> <p>{</p> </font><font color="#0000ff" size="2">string</font><font size="2"> strFilePath = </font> <font color="#a31515" size="2">&quot;&quot;</font><font size="2">;</font><font size="2"> <p></font><font color="#0000ff" size="2">try</p> </font><font size="2"> <p>{</p> </font><font color="#0000ff" size="2">string</font><font size="2"> fullPath = </font> <font color="#2b91af" size="2">ConfigurationManager</font><font size="2">.AppSettings[</font><font color="#a31515" size="2">&quot;SaveNewsImages&quot;</font><font size="2">];&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;-----In webConfig&nbsp;folder setting has been given like it&nbsp;&nbsp;<strong> &lt;<font color="#a31515" size="2">add</font><font color="#0000ff" size="2"> </font><font color="#ff0000" size="2">key</font><font color="#0000ff" size="2">=</font><font size="2">&quot;</font><font color="#a31515" size="2">SaveNewsImages</font><font size="2">&quot;</font><font color="#0000ff" size="2"> </font><font color="#ff0000" size="2">value</font><font color="#0000ff" size="2">=</font><font size="2">&quot;</font><font color="#0000ff" size="2">UploadImages/</font><font size="2">&quot;</font><font color="#0000ff" size="2">/&gt;</font></strong></font><font size="2"><strong><font color="#0000ff" size="2"></font><font color="#0000ff" size="2"></font></strong> <p></font><font color="#0000ff" size="2">string</font><font size="2"> tempPath = </font> <font color="#2b91af" size="2">ConfigurationManager</font><font size="2">.AppSettings[</font><font color="#a31515" size="2">&quot;TempImages&quot;</font><font size="2">];</p> </font><font color="#2b91af" size="2">Random</font><font size="2"> rd = </font><font color="#0000ff" size="2">new</font><font size="2"> </font><font color="#2b91af" size="2">Random</font><font size="2">();</font><font size="2"></font><font color="#0000ff" size="2">string</font><font size="2"> s = rd.Next().ToString();</font><font size="2"> <p>strFilePath = fullPath;</p> <p>strFilePath &#43;= s &#43; </font><font color="#a31515" size="2">&quot;.jpg&quot;</font><font size="2">;</p> </font><font color="#0000ff" size="2">string</font><font size="2"> strTempPath = tempPath &#43; s &#43; </font><font color="#a31515" size="2">&quot;.jpg&quot;</font><font size="2">;</font><font size="2"> <p>fileUpload.PostedFile.SaveAs(Server.MapPath(</font><font color="#a31515" size="2">&quot;~/&quot;</font><font size="2">&#43;strTempPath));</p> System.Drawing.</font><font color="#2b91af" size="2">Image</font><font size="2"> fullSizeImg = System.Drawing.</font><font color="#2b91af" size="2">Image</font><font size="2">.FromFile(Server.MapPath(</font><font color="#a31515" size="2">&quot;~/&quot;</font><font size="2">&#43;strTempPath));</font><font size="2"> <p>System.Drawing.</font><font color="#2b91af" size="2">Image</font><font size="2"> shortImg = ResizeImage(fullSizeImg,75);</p> </font><font color="#0000ff" size="2">string</font><font size="2"> realPath = strFilePath;</font><font size="2"> <p>shortImg.Save(Server.MapPath(</font><font color="#a31515" size="2">&quot;~/&quot;</font><font size="2"> &#43; realPath));</p> </font><font color="#0000ff" size="2">return</font><font size="2"> s &#43; </font><font color="#a31515" size="2">&quot;.jpg&quot;</font><font size="2">;</font><font size="2"> <p>}</p> </font><font color="#0000ff" size="2">catch</font><font size="2"> (</font><font color="#2b91af" size="2">Exception</font><font size="2"> ex)</font><font size="2"> <p>{</p> </font><font color="#0000ff" size="2">throw</font><font size="2"> ex;</font><font size="2"> <p>}</p> </font><font color="#008000" size="2">/*</font><font color="#008000" size="2"> <p>* Return the filename to be stored in the DB</p> <p>*/</p> </font><font size="2"> <p>}</p> </font><font size="2"></font><font size="2"></font><font color="#0000ff" size="2">private</font><font size="2"> System.Drawing.</font><font color="#2b91af" size="2">Image</font><font size="2"> ResizeImage(System.Drawing.</font><font color="#2b91af" size="2">Image</font><font size="2"> fullSizeImg, </font><font color="#0000ff" size="2">int</font><font size="2"> imageWidth)</font><font size="2"> <p>{</p> <p>System.Drawing.</font><font color="#2b91af" size="2">Image</font><font size="2"> image;</p> image = fullSizeImg.GetThumbnailImage(imageWidth, 60, </font><font color="#0000ff" size="2">null</font><font size="2">, </font><font color="#2b91af" size="2">IntPtr</font><font size="2">.Zero);</font><font size="2"> <p></font><font color="#0000ff" size="2">return</font><font size="2"> image;</p> <p></font><font color="#008000" size="2">//image = fullSizeImg.GetThumbnailImage(imageWidth, fullSizeImg.Height * imageWidth / fullSizeImg.Width, null, IntPtr.Zero); </p> </font><font size="2"> <p>}</p> </font> <p>&nbsp;</p> <p><strong><font color="#0000ff">&quot;UploadImages&quot;&nbsp; named folder is in my application.&nbsp;this code&nbsp;working fine on my local machine but after uploading on server it have the following error.</font></strong></p> <p>System.Runtime.InteropServices.ExternalException: A generic error occurred in GDI&#43;.</p> <p>I&nbsp;will be so thanks full for all of you.<br> &nbsp;.&nbsp;</p> <p>&nbsp;</p> 2008-11-26T11:36:20-05:002008-11-26T11:36:20.54-05:00urn:uuid:00000000-0000-0000-0000-000005357935http://forums.asp.net/p/1896874/5357935.aspx/1?Image+save+filename+ErrorImage.save(filename) Error <p>Hi Friends,</p> <p>FtpWebResponse response;<br> FtpWebRequest request = (FtpWebRequest)WebRequest.Create(path);<br> request.KeepAlive = false;</p> <p>request.Method = WebRequestMethods.Ftp.DownloadFile;<br> // This example assumes the FTP site uses anonymous logon.<br> request.Credentials = new NetworkCredential(userId, password);<br> response = (FtpWebResponse)request.GetResponse();</p> <p>Stream responseStream = response.GetResponseStream();<br> var image = Image.FromStream(responseStream);<br> image.Save(tempfileloc,);<br> image.Dispose();<br> responseStream.Close();<br> responseStream.Dispose();<br> response.Close();</p> <p>I am using the above code to download Images from remote server.</p> <p>I can getting above 30k images from remote server, i can download images but for some images when saving i am getting such error</p> <p>System.Runtime.InteropServices.ExternalException: A generic error occurred in GDI&#43;.<br> at System.Drawing.Image.Save(String filename, ImageCodecInfo encoder, EncoderParameters encoderParams)<br> at System.Drawing.Image.Save(String filename, ImageFormat format)<br> at System.Drawing.Image.Save(String filename)</p> <p>Please help me out&nbsp;</p> <p>Thank you.</p> 2013-04-09T20:09:16-04:002013-04-09T20:09:16.977-04:00urn:uuid:00000000-0000-0000-0000-000005347708http://forums.asp.net/p/1894250/5347708.aspx/1?Image+Processing+Control+DevelopmentImage Processing Control Development <p>I want To develop A control Which Help me&nbsp; To provide Facilities Like Image Brightness ,Contrast,Cropping etc. features ..So Can anybody Help me Please...</p> <p></p> 2013-03-30T05:52:18-04:002013-03-30T05:52:18.63-04:00urn:uuid:00000000-0000-0000-0000-000005335801http://forums.asp.net/p/1891346/5335801.aspx/1?Hot+to+Add+Logo+in+PDF+using+iTextSharpHot to Add Logo in PDF using iTextSharp <p>Hello,</p> <p>&nbsp; &nbsp;I am using itextsharp to generate PDF reports but facing problem to add perfect logo locatioin with high resolution.</p> <p>Could any one help me.</p> 2013-03-18T11:58:48-04:002013-03-18T11:58:48-04:00urn:uuid:00000000-0000-0000-0000-000005181668http://forums.asp.net/p/1851762/5181668.aspx/1?c+Resize+image+and+upload+to+dbc# Resize image and upload to db <p>Hi,</p> <p></p> <p>I have the following code to resize an image and send it back as an array to be uploaded to a sql db image field.</p> <p>The upload works fine but I'm having trouble to resize the image.</p> <p>Any idea what is wrong?</p> <p>Here is the class to resize the image</p> <pre class="prettyprint">public byte[] CreateThumbnail(byte[] PassedImage, int imgWidth, int imgHeight) { MemoryStream StartMemoryStream = new MemoryStream(PassedImage); System.Drawing.Image fullSizeImg = System.Drawing.Image.FromStream(StartMemoryStream); System.Drawing.Image newImg = fullSizeImg.GetThumbnailImage(imgWidth, imgHeight, null, IntPtr.Zero); System.IO.MemoryStream myResult = new System.IO.MemoryStream(); newImg.Save(myResult, System.Drawing.Imaging.ImageFormat.Jpeg); return myResult.ToArray(); }</pre> <pre class="prettyprint">I'm getting the following error code:</pre> <pre class="prettyprint">Server Error in '/' Application. Parameter is not valid. Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. Exception Details: System.ArgumentException: Parameter is not valid.</pre> <pre class="prettyprint"><b>Source Error:</b><span>&nbsp;</span><br><br></pre> <table width="100%" bgcolor="#ffffcc"> <tbody> <tr> <td> <pre>Line 59: { Line 60: MemoryStream StartMemoryStream = new MemoryStream(PassedImage); <span color="red" style="color:red">Line 61: System.Drawing.Image fullSizeImg = System.Drawing.Image.FromStream(StartMemoryStream);&nbsp;<br></span>Line 62: System.Drawing.Image newImg = fullSizeImg.GetThumbnailImage(imgWidth, imgHeight, null, IntPtr.Zero);<br>Line 63: System.IO.MemoryStream myResult = new System.IO.MemoryStream();</pre> &lt;div&gt;&lt;/div&gt; </td> </tr> </tbody> </table> <p><br> <br> </p> 2012-10-16T20:13:21-04:002012-10-16T20:13:21.89-04:00