<?xml version="1.0" encoding="UTF-8"?><?xml-stylesheet type="text/xsl" media="screen" href="/App_Themes/default/rss.xslt"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:media="http://search.yahoo.com/mrss/" xmlns:evnet="http://www.mscommunities.com/rssmodule/"><channel><title>Comment Feed for Display and save image file to SQL Server simultaneously (TechOff on Channel 9)</title><atom:link rel="self" type="application/rss+xml" href="http://channel9.msdn.com/forums/techoff/258765-display-and-save-image-file-to-sql-server-simultaneously/rss/default.aspx" /><image><url>http://mschnlnine.vo.llnwd.net/d1/Dev/App_Themes/C9/images/feedimage.png</url><title>Comment Feed for Display and save image file to SQL Server simultaneously (TechOff on Channel 9)</title><link>http://channel9.msdn.com/forums/TechOff/258765-Display-and-save-image-file-to-SQL-Server-simultaneously/</link></image><description>Display and save image file to SQL Server simultaneously</description><link>http://channel9.msdn.com/forums/TechOff/258765-Display-and-save-image-file-to-SQL-Server-simultaneously/</link><language>en-us</language><pubDate>Tue, 06 Nov 2007 09:18:46 GMT</pubDate><lastBuildDate>Tue, 06 Nov 2007 09:18:46 GMT</lastBuildDate><generator>EvNet (EvNet, Version=1.0.3608.3122, Culture=neutral, PublicKeyToken=null)</generator><item><title>Re: Display and save image file to SQL Server simultaneously</title><description>Does that have an effect on the memory usage?</description><comments></comments><link>http://channel9.msdn.com/forums/TechOff/258765-Display-and-save-image-file-to-SQL-Server-simultaneously/?CommentID=361993</link><pubDate>Tue, 06 Nov 2007 09:18:46 GMT</pubDate><guid isPermaLink="false">http://channel9.msdn.com/forums/TechOff/258765-Display-and-save-image-file-to-SQL-Server-simultaneously/?CommentID=361993</guid><evnet:views>0</evnet:views><evnet:viewtrackingurl>http://channel9.msdn.com/361993/WebViewBug.aspx?EVT=0</evnet:viewtrackingurl><evnet:previewtext>Does that have an effect on the memory usage?</evnet:previewtext><dc:creator>stevo_</dc:creator><slash:comments>0</slash:comments><wfw:commentRss></wfw:commentRss><trackback:ping>http://channel9.msdn.com/361993/Trackback.aspx</trackback:ping></item><item><title>Re: Display and save image file to SQL Server simultaneously</title><description>Tommy, the method you're using to do this probably works in most cases, but it is not generically safe.&lt;BR&gt;&lt;BR&gt;You see, the reason Image.FromFile keeps the file locked is because GDI+ can (depending on the codec, the size of the file, and other factors) delay decoding (parts of) the image until they are actually needed (e.g. when you draw them). The Image.FromStream method will for the same reason keep a reference to the stream you passed it. If you close the stream and you run into one of these delayed-decoding scenarios, GDI+ will access the stream and fail with an ObjectDisposedException.&lt;BR&gt;&lt;BR&gt;The only way that I know of to achieve this that is 100% safe in all cases is to load the image from file, create a new image, draw the original image into the new image, and then close the original one (which unlocks the file).&lt;BR&gt;&lt;BR&gt;
&lt;P&gt;Public Module Utils&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;Public Function ImageFromFile(ByVal fileName As String) As Image&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;Using image As Image = image.FromFile(fileName)&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;Dim result As New Bitmap(image.Width, image.Height, Imaging.PixelFormat.Format32bppArgb)&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;Using g As Graphics = Graphics.FromImage(result)&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;g.DrawImage(image, 0, 0, image.Width, image.Height)&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;End Using&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;Return result&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;End Using&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;End Function&lt;BR&gt;End Module&lt;/P&gt;</description><comments></comments><link>http://channel9.msdn.com/forums/TechOff/258765-Display-and-save-image-file-to-SQL-Server-simultaneously/?CommentID=361975</link><pubDate>Tue, 06 Nov 2007 07:22:29 GMT</pubDate><guid isPermaLink="false">http://channel9.msdn.com/forums/TechOff/258765-Display-and-save-image-file-to-SQL-Server-simultaneously/?CommentID=361975</guid><evnet:views>0</evnet:views><evnet:viewtrackingurl>http://channel9.msdn.com/361975/WebViewBug.aspx?EVT=0</evnet:viewtrackingurl><evnet:previewtext>Tommy, the method you're using to do this probably works in most cases, but it is not generically safe.You see, the reason Image.FromFile keeps the file locked is because GDI+ can (depending on the codec, the size of the file, and other factors) delay decoding (parts of) the image until they are&amp;#8230;</evnet:previewtext><dc:creator>Sven Groot</dc:creator><slash:comments>0</slash:comments><wfw:commentRss></wfw:commentRss><trackback:ping>http://channel9.msdn.com/361975/Trackback.aspx</trackback:ping></item><item><title>Re: Display and save image file to SQL Server simultaneously</title><description>Finally, IT WORKS........... Thanks for your guide. &lt;br&gt;I only did a tiny modification in my code and it instantly worked. What I change is the declaration of FileStream, so now it looks like this:&lt;br&gt;&lt;br&gt;Dim fs As FileStream = New FileStream(FilePath, FileMode.Open, &lt;u&gt;&lt;b&gt;FileAccess.Read&lt;/b&gt;&lt;/u&gt;)&lt;br&gt;&lt;br&gt;The underlined words are all changes I've made to get it done. Thanks again, Tommy.......&lt;br&gt;</description><comments></comments><link>http://channel9.msdn.com/forums/TechOff/258765-Display-and-save-image-file-to-SQL-Server-simultaneously/?CommentID=361974</link><pubDate>Tue, 06 Nov 2007 07:12:50 GMT</pubDate><guid isPermaLink="false">http://channel9.msdn.com/forums/TechOff/258765-Display-and-save-image-file-to-SQL-Server-simultaneously/?CommentID=361974</guid><evnet:views>0</evnet:views><evnet:viewtrackingurl>http://channel9.msdn.com/361974/WebViewBug.aspx?EVT=0</evnet:viewtrackingurl><evnet:previewtext>Finally, IT WORKS........... Thanks for your guide. I only did a tiny modification in my code and it instantly worked. What I change is the declaration of FileStream, so now it looks like this:Dim fs As FileStream = New FileStream(FilePath, FileMode.Open, FileAccess.Read)The underlined words are all&amp;#8230;</evnet:previewtext><dc:creator>ed_de_wind</dc:creator><slash:comments>0</slash:comments><wfw:commentRss></wfw:commentRss><trackback:ping>http://channel9.msdn.com/361974/Trackback.aspx</trackback:ping></item><item><title>Re: Display and save image file to SQL Server simultaneously</title><description>Last year I wrote a blog post about this. The code is in C#, but I think it's not hard to translate to VB. It's only a few lines of code. http://tommycarlier.blogspot.com/2006/06/reading-image-from-file-without.html</description><comments></comments><link>http://channel9.msdn.com/forums/TechOff/258765-Display-and-save-image-file-to-SQL-Server-simultaneously/?CommentID=361970</link><pubDate>Tue, 06 Nov 2007 06:25:34 GMT</pubDate><guid isPermaLink="false">http://channel9.msdn.com/forums/TechOff/258765-Display-and-save-image-file-to-SQL-Server-simultaneously/?CommentID=361970</guid><evnet:views>0</evnet:views><evnet:viewtrackingurl>http://channel9.msdn.com/361970/WebViewBug.aspx?EVT=0</evnet:viewtrackingurl><evnet:previewtext>Last year I wrote a blog post about this. The code is in C#, but I think it's not hard to translate to VB. It's only a few lines of code. http://tommycarlier.blogspot.com/2006/06/reading-image-from-file-without.html</evnet:previewtext><dc:creator>Tommy Carlier</dc:creator><slash:comments>0</slash:comments><wfw:commentRss></wfw:commentRss><trackback:ping>http://channel9.msdn.com/361970/Trackback.aspx</trackback:ping></item></channel></rss>