<?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/"
	
	xmlns:georss="http://www.georss.org/georss"
	xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#"
	>

<channel>
	<title>bitmap &#8211; MaxVergelli.com</title>
	<atom:link href="https://www.maxvergelli.com/tag/bitmap/feed/" rel="self" type="application/rss+xml" />
	<link>https://www.maxvergelli.com</link>
	<description>sourcecode repository</description>
	<lastBuildDate>Tue, 07 Apr 2020 13:41:18 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	

<image>
	<url>https://i2.wp.com/www.maxvergelli.com/wp-content/uploads/2020/04/wp-1586823685141.png?fit=32%2C32&#038;ssl=1</url>
	<title>bitmap &#8211; MaxVergelli.com</title>
	<link>https://www.maxvergelli.com</link>
	<width>32</width>
	<height>32</height>
</image> 
<site xmlns="com-wordpress:feed-additions:1">34603511</site>	<item>
		<title>vb.net Bitmap object locks images (impossible to move/delete jpg/gif files) &#8211; .Dispose() Method common problem</title>
		<link>https://www.maxvergelli.com/vb-net-bitmap-object-locks-images-impossible-to-move-delete-jpg-gif-files-dispose-method-common-problem/</link>
					<comments>https://www.maxvergelli.com/vb-net-bitmap-object-locks-images-impossible-to-move-delete-jpg-gif-files-dispose-method-common-problem/#respond</comments>
		
		<dc:creator><![CDATA[Max]]></dc:creator>
		<pubDate>Tue, 14 Jan 2020 15:47:04 +0000</pubDate>
				<category><![CDATA[ASP.NET]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[VB.Net]]></category>
		<category><![CDATA[.net]]></category>
		<category><![CDATA[algorithm]]></category>
		<category><![CDATA[bitmap]]></category>
		<category><![CDATA[c#]]></category>
		<category><![CDATA[class]]></category>
		<category><![CDATA[code]]></category>
		<category><![CDATA[coding]]></category>
		<category><![CDATA[dispose]]></category>
		<category><![CDATA[file]]></category>
		<category><![CDATA[function]]></category>
		<category><![CDATA[method]]></category>
		<category><![CDATA[object]]></category>
		<category><![CDATA[programming]]></category>
		<category><![CDATA[vb.net]]></category>
		<guid isPermaLink="false">http://www.maxvergelli.com/?p=74</guid>

					<description><![CDATA[Many people are in trouble and on forums asking why the .Net Bitmap object does not release an image with its .Dispose() method. The Bitmap object (after its destruction too) seems to lock the image file, then we are not &#8230; <a class="kt-excerpt-readmore" href="https://www.maxvergelli.com/vb-net-bitmap-object-locks-images-impossible-to-move-delete-jpg-gif-files-dispose-method-common-problem/" aria-label="vb.net Bitmap object locks images (impossible to move/delete jpg/gif files) &#8211; .Dispose() Method common problem">Read More</a>]]></description>
										<content:encoded><![CDATA[<p>Many people are in trouble and on forums asking why the .Net Bitmap object does not release an image with its .Dispose() method. The Bitmap object (after its destruction too) seems to lock the image file, then we are not able to move or delete that image file through the file system.</p>
<p>This is a known problem and it occurs when we declare and instantiate a Bitmap object and destruct that like in the following code:</p>
[sourcecode language=&#8221;vb&#8221;]
<p>                &#8216;create a bitmap object<br />
                Dim myBitmap As New Bitmap(&quot;c:myimage.jpg&quot;)</p>
<p>                &#8216;editing image routines, right here<br />
                &#8216;&#8230;</p>
<p>                &#8216;release all Bitmap object resources<br />
                myBitmap.Dispose()</p>
[/sourcecode]
<p>The above code it is formally correct, however in same circumstances the .net garbage collector cannot recognize bitmap&#8217;s disposing; Dispose() method leaves the image file in an unusable state, then as <a href="http://msdn.microsoft.com/en-us/library/8th8381z.aspx">MSDN</a> said, we MUST release explicitly any reference after a Dispose() call;</p>
<p>with the following code, You will not encounter any problem, and after Dispose() You can edit, move, delete the image file by the filesystem functions&#8230;</p>
[sourcecode language=&#8221;vb&#8221;]
                &#8216;create a bitmap object<br />
                Dim myBitmap As New Bitmap(&quot;c:myimage.jpg&quot;)</p>
<p>                &#8216;editing image routines, right here<br />
                &#8216;&#8230;</p>
<p>                &#8216;release image reference<br />
                While myBitmap IsNot Nothing<br />
                    myBitmap.Dispose()<br />
                    myBitmap = Nothing  &#8216;&lt;&#8211; tells .net garbage collector to release resources<br />
                End While</p>
[/sourcecode]
<p>Happy image editing! 🙂</p>
]]></content:encoded>
					
					<wfw:commentRss>https://www.maxvergelli.com/vb-net-bitmap-object-locks-images-impossible-to-move-delete-jpg-gif-files-dispose-method-common-problem/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
		<post-id xmlns="com-wordpress:feed-additions:1">74</post-id>	</item>
		<item>
		<title>How to draw a shadow for a bitmap (Drop Shadow Effect in VB.NET / ASP.NET)</title>
		<link>https://www.maxvergelli.com/how-to-draw-a-shadow-for-a-bitmap-drop-shadow-effect-in-vb-net-asp-net/</link>
					<comments>https://www.maxvergelli.com/how-to-draw-a-shadow-for-a-bitmap-drop-shadow-effect-in-vb-net-asp-net/#respond</comments>
		
		<dc:creator><![CDATA[Max]]></dc:creator>
		<pubDate>Thu, 09 Jan 2020 15:41:16 +0000</pubDate>
				<category><![CDATA[ASP.NET]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[VB.Net]]></category>
		<category><![CDATA[algorithm]]></category>
		<category><![CDATA[asp.net]]></category>
		<category><![CDATA[backcolor]]></category>
		<category><![CDATA[background-color]]></category>
		<category><![CDATA[bitamp-library]]></category>
		<category><![CDATA[bitmap]]></category>
		<category><![CDATA[bitmap-effect]]></category>
		<category><![CDATA[bitmap-fx]]></category>
		<category><![CDATA[bitmap-manipulation]]></category>
		<category><![CDATA[bitmap-processing]]></category>
		<category><![CDATA[bitmap-programming]]></category>
		<category><![CDATA[c#]]></category>
		<category><![CDATA[class]]></category>
		<category><![CDATA[code]]></category>
		<category><![CDATA[coding]]></category>
		<category><![CDATA[color]]></category>
		<category><![CDATA[digital-image-processing]]></category>
		<category><![CDATA[draw]]></category>
		<category><![CDATA[draw-bitmap]]></category>
		<category><![CDATA[drawing]]></category>
		<category><![CDATA[drop-shadow]]></category>
		<category><![CDATA[filter]]></category>
		<category><![CDATA[filtering]]></category>
		<category><![CDATA[function]]></category>
		<category><![CDATA[fx]]></category>
		<category><![CDATA[graphic-manipulation]]></category>
		<category><![CDATA[helper-class]]></category>
		<category><![CDATA[image-filter]]></category>
		<category><![CDATA[image-fx]]></category>
		<category><![CDATA[image-height]]></category>
		<category><![CDATA[image-library]]></category>
		<category><![CDATA[image-manipulation]]></category>
		<category><![CDATA[image-manipulation-algorithm]]></category>
		<category><![CDATA[image-matrix]]></category>
		<category><![CDATA[image-processing]]></category>
		<category><![CDATA[image-processing-algorithm]]></category>
		<category><![CDATA[image-width]]></category>
		<category><![CDATA[library]]></category>
		<category><![CDATA[matrix-manipulation]]></category>
		<category><![CDATA[method]]></category>
		<category><![CDATA[module]]></category>
		<category><![CDATA[opacity]]></category>
		<category><![CDATA[programming]]></category>
		<category><![CDATA[shadow]]></category>
		<category><![CDATA[shadow-effect]]></category>
		<category><![CDATA[thread-safe]]></category>
		<category><![CDATA[vb.net]]></category>
		<category><![CDATA[wrapper-class]]></category>
		<guid isPermaLink="false">http://www.maxvergelli.com/?p=72</guid>

					<description><![CDATA[I wrote a vb.net subroutine to draw easly a shadow for a Bitmap object; It is possible get a charming shadow in different ways&#8230; Normal black shadow to the bottom right corner Red shadow to the bottom right corner Shadow &#8230; <a class="kt-excerpt-readmore" href="https://www.maxvergelli.com/how-to-draw-a-shadow-for-a-bitmap-drop-shadow-effect-in-vb-net-asp-net/" aria-label="How to draw a shadow for a bitmap (Drop Shadow Effect in VB.NET / ASP.NET)">Read More</a>]]></description>
										<content:encoded><![CDATA[<p>I wrote a vb.net subroutine to draw easly a shadow for a Bitmap object; It is possible get a charming shadow in different ways&#8230;</p>
<table>
<tbody>
<tr>
<td>Normal black shadow to the bottom right corner</td>
<td><img src="https://i1.wp.com/www.maxvergelli.com/wp-content/uploads/2016/06/test_shadow_01_black_to_white.jpg?w=1140" data-recalc-dims="1" /></td>
</tr>
<tr>
<td>Red shadow to the bottom right corner</td>
<td><img src="https://i1.wp.com/www.maxvergelli.com/wp-content/uploads/2016/06/test_shadow_02_red_to_white.jpg?w=1140" data-recalc-dims="1" /></td>
</tr>
<tr>
<td>Shadow to the bottom left corner</td>
<td><img src="https://i2.wp.com/www.maxvergelli.com/wp-content/uploads/2016/06/test_shadow_04_d_bottomleft.jpg?w=1140" data-recalc-dims="1" /></td>
</tr>
<tr>
<td>Shadow to the top left corner</td>
<td><img src="https://i0.wp.com/www.maxvergelli.com/wp-content/uploads/2016/06/test_shadow_05_d_topleft.jpg?w=1140" data-recalc-dims="1" /></td>
</tr>
<tr>
<td>Shadow to the top right corner</td>
<td><img src="https://i0.wp.com/www.maxvergelli.com/wp-content/uploads/2016/06/test_shadow_06_d_topright.jpg?w=1140" data-recalc-dims="1" /></td>
</tr>
<tr>
<td>Shadow with Opacity: &#8220;128&#8221;</td>
<td><img src="https://i2.wp.com/www.maxvergelli.com/wp-content/uploads/2016/06/test_shadow_07_opacity.jpg?w=1140" data-recalc-dims="1" /></td>
</tr>
<tr>
<td>Shadow with Opacity: &#8220;128&#8221; and Softness: &#8220;8&#8221;</td>
<td><img src="https://i1.wp.com/www.maxvergelli.com/wp-content/uploads/2016/06/test_shadow_08_opacityandsoftness.jpg?w=1140" data-recalc-dims="1" /></td>
</tr>
<tr>
<td>Shadow with Opacity: &#8220;128&#8221;, Softness: &#8220;8&#8221; and Distance: &#8220;10&#8221;</td>
<td><img src="https://i1.wp.com/www.maxvergelli.com/wp-content/uploads/2016/06/test_shadow_09_opacitysoftnessanddistance.jpg?w=1140" data-recalc-dims="1" /></td>
</tr>
<tr>
<td>Shadow without rounded edges</td>
<td><img src="https://i0.wp.com/www.maxvergelli.com/wp-content/uploads/2016/06/test_shadow_10_noroundededges.jpg?w=1140" data-recalc-dims="1" /></td>
</tr>
</tbody>
</table>
<p>Copy and paste my following vb.net code in your application. it does all the hard job&#8230;</p>
[sourcecode language=&#8221;vb&#8221;]
<p>    &#8216;ShadowDirection:<br />
    &#8216;       TOP_RIGHT = 1<br />
    &#8216;       BOTTOM_RIGHT = 2<br />
    &#8216;       BOTTOM_LEFT = 3<br />
    &#8216;       TOP_LEFT = 4<br />
    &#8216;ShadowOpacity: from 0 to 255<br />
    &#8216;ShadowSoftness: from 1 to 30<br />
    &#8216;ShadowDistance: from 1 to 50<br />
    &#8216;ShadowRoundedEdges: True or False</p>
<p>    &#8216;Note:<br />
    &#8216;If You set &quot;transparent&quot; as background color, this is replaced with white color.</p>
<p>    Public Enum ShadowDirections As Integer<br />
        TOP_RIGHT = 1<br />
        BOTTOM_RIGHT = 2<br />
        BOTTOM_LEFT = 3<br />
        TOP_LEFT = 4<br />
    End Enum</p>
<p>    &lt;STAThread()&gt; _<br />
    Public Sub DropShadow(ByRef SourceImage As Drawing.Bitmap, _<br />
                            ByVal ShadowColor As Drawing.Color, _<br />
                            ByVal BackgroundColor As Drawing.Color, _<br />
                            Optional ByVal ShadowDirection As ShadowDirections = _<br />
                                                  ShadowDirections.BOTTOM_RIGHT, _<br />
                            Optional ByVal ShadowOpacity As Integer = 190, _<br />
                            Optional ByVal ShadowSoftness As Integer = 4, _<br />
                            Optional ByVal ShadowDistance As Integer = 5, _<br />
                            Optional ByVal ShadowRoundedEdges As Boolean = True)<br />
        Dim ImgTarget As Bitmap = Nothing<br />
        Dim ImgShadow As Bitmap = Nothing<br />
        Dim g As Graphics = Nothing<br />
        Try<br />
            If SourceImage IsNot Nothing Then<br />
                If ShadowOpacity &lt; 0 Then<br />
                    ShadowOpacity = 0<br />
                ElseIf ShadowOpacity &gt; 255 Then<br />
                    ShadowOpacity = 255<br />
                End If<br />
                If ShadowSoftness &lt; 1 Then<br />
                    ShadowSoftness = 1<br />
                ElseIf ShadowSoftness &gt; 30 Then<br />
                    ShadowSoftness = 30<br />
                End If<br />
                If ShadowDistance &lt; 1 Then<br />
                    ShadowDistance = 1<br />
                ElseIf ShadowDistance &gt; 50 Then<br />
                    ShadowDistance = 50<br />
                End If<br />
                If ShadowColor = Color.Transparent Then<br />
                    ShadowColor = Color.Black<br />
                End If<br />
                If BackgroundColor = Color.Transparent Then<br />
                    BackgroundColor = Color.White<br />
                End If</p>
<p>                &#8216;get shadow<br />
                Dim shWidth As Integer = CInt(SourceImage.Width / ShadowSoftness)<br />
                Dim shHeight As Integer = CInt(SourceImage.Height / ShadowSoftness)<br />
                ImgShadow = New Bitmap(shWidth, shHeight)<br />
                g = Graphics.FromImage(ImgShadow)<br />
                g.Clear(Color.Transparent)<br />
                g.InterpolationMode = InterpolationMode.HighQualityBicubic<br />
                g.SmoothingMode = SmoothingMode.AntiAlias<br />
                Dim sre As Integer = 0<br />
                If ShadowRoundedEdges = True Then sre = 1<br />
                g.FillRectangle(New SolidBrush(Color.FromArgb(ShadowOpacity, ShadowColor)), _<br />
                                      sre, sre, shWidth, shHeight)<br />
                g.Dispose()</p>
<p>                &#8216;draw shadow<br />
                Dim d_shWidth As Integer = SourceImage.Width + ShadowDistance<br />
                Dim d_shHeight As Integer = SourceImage.Height + ShadowDistance<br />
                ImgTarget = New Bitmap(d_shWidth, d_shHeight)<br />
                g = Graphics.FromImage(ImgTarget)<br />
                g.Clear(BackgroundColor)<br />
                g.InterpolationMode = InterpolationMode.HighQualityBicubic<br />
                g.SmoothingMode = SmoothingMode.AntiAlias<br />
                g.DrawImage(ImgShadow, New Rectangle(0, 0, d_shWidth, d_shHeight), _<br />
                                        0, 0, ImgShadow.Width, ImgShadow.Height, GraphicsUnit.Pixel)<br />
                Select Case ShadowDirection<br />
                    Case ShadowDirections.BOTTOM_RIGHT<br />
                        g.DrawImage(SourceImage, _<br />
                            New Rectangle(0, 0, SourceImage.Width,SourceImage.Height), _<br />
                               0, 0, SourceImage.Width, SourceImage.Height, GraphicsUnit.Pixel)<br />
                    Case ShadowDirections.BOTTOM_LEFT<br />
                        g.Dispose()<br />
                        ImgTarget.RotateFlip(RotateFlipType.RotateNoneFlipX)<br />
                        g = Graphics.FromImage(ImgTarget)<br />
                        g.DrawImage(SourceImage, _<br />
                             New Rectangle(ShadowDistance, 0, SourceImage.Width, SourceImage.Height), _<br />
                                    0, 0, SourceImage.Width, SourceImage.Height, GraphicsUnit.Pixel)<br />
                    Case ShadowDirections.TOP_LEFT<br />
                        g.Dispose()<br />
                        ImgTarget.RotateFlip(RotateFlipType.Rotate180FlipNone)<br />
                        g = Graphics.FromImage(ImgTarget)<br />
                        g.DrawImage(SourceImage, _<br />
                                      New Rectangle(ShadowDistance, ShadowDistance, _<br />
                                                        SourceImage.Width, SourceImage.Height), _<br />
                                      0, 0, SourceImage.Width, SourceImage.Height, GraphicsUnit.Pixel)<br />
                    Case ShadowDirections.TOP_RIGHT<br />
                        g.Dispose()<br />
                        ImgTarget.RotateFlip(RotateFlipType.RotateNoneFlipY)<br />
                        g = Graphics.FromImage(ImgTarget)<br />
                        g.DrawImage(SourceImage, _<br />
                           New Rectangle(0, ShadowDistance, SourceImage.Width, SourceImage.Height), _<br />
                                  0, 0, SourceImage.Width, SourceImage.Height, GraphicsUnit.Pixel)<br />
                End Select</p>
<p>                g.Dispose()<br />
                g = Nothing<br />
                ImgShadow.Dispose()<br />
                ImgShadow = Nothing</p>
<p>                SourceImage = New Bitmap(ImgTarget)<br />
                ImgTarget.Dispose()<br />
                ImgTarget = Nothing<br />
            End If</p>
<p>        Catch ex As Exception<br />
            If g IsNot Nothing Then<br />
                g.Dispose()<br />
                g = Nothing<br />
            End If<br />
            If ImgShadow IsNot Nothing Then<br />
                ImgShadow.Dispose()<br />
                ImgShadow = Nothing<br />
            End If<br />
            If ImgTarget IsNot Nothing Then<br />
                ImgTarget.Dispose()<br />
                ImgTarget = Nothing<br />
            End If<br />
        End Try</p>
<p>    End Sub<br />
[/sourcecode]
<p>Besides, You can use this sub as in the following example (take a look at the comments&#8230;) :</p>
[sourcecode language=&#8221;vb&#8221;]
        Dim file_input As String = &quot;c:myfile.jpg&quot;<br />
        Dim file_output As String = &quot;c:myfilewithshadow.jpg&quot;</p>
<p>        &#8216;get bitmap&#8230;<br />
        Dim sourceImage As System.Drawing.Image = System.Drawing.Image.FromFile(file_input)<br />
        Dim format As System.Drawing.Imaging.ImageFormat = sourceImage.RawFormat<br />
        Dim bmpOut As System.Drawing.Bitmap = New Bitmap(sourceImage)</p>
<p>        &#8216;release any reference to the original file&#8230;<br />
        While sourceImage IsNot Nothing<br />
            sourceImage.Dispose()<br />
            sourceImage = Nothing<br />
        End While</p>
<p>        &#8216;drop black shadow on new bitmap with white background&#8230;<br />
        DropShadow(bmpOut, Color.Black, Color.White)</p>
<p>        &#8216;save file&#8230;<br />
        If bmpOut IsNot Nothing Then<br />
            bmpOut.Save(file_output, format)<br />
            bmpOut.Dispose()<br />
            bmpOut = Nothing<br />
        End If<br />
[/sourcecode]
<p>PS:<br />
The subroutine executes only in &#8220;STAThread&#8221; so it&#8217;s thread-safe drawing.</p>
<p>Happy coding&#8230;</p>
<p>Max 🙂</p>
]]></content:encoded>
					
					<wfw:commentRss>https://www.maxvergelli.com/how-to-draw-a-shadow-for-a-bitmap-drop-shadow-effect-in-vb-net-asp-net/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
		<post-id xmlns="com-wordpress:feed-additions:1">72</post-id>	</item>
	</channel>
</rss>
