OSDN Git Service

CachedImageでファイル読み書きする際、FileStreamの明示とFlushするよう変更
authorkiri_feather <kiri_feather@users.sourceforge.jp>
Fri, 10 Sep 2010 06:52:43 +0000 (06:52 +0000)
committerKimura Youichi <kim.upsilon@bucyou.net>
Sat, 18 Feb 2012 14:15:21 +0000 (23:15 +0900)
git-svn-id: http://svn.sourceforge.jp/svnroot/tween/trunk@844 e39ad16e-3079-482e-bb30-4b4d378143b6

Tween/ImageCacheDictionary.vb

index 34bd38a..30c4546 100644 (file)
@@ -179,7 +179,11 @@ Public Class ImageCacheDictionary
             Get
                 If Me.img Is Nothing Then
                     Try
-                        Me.img = Image.FromFile(Me.tmpFilePath)
+                        Dim tempImage As Image = Nothing
+                        Using fs As New FileStream(Me.tmpFilePath, FileMode.Open, FileAccess.Read)
+                            tempImage = Bitmap.FromStream(fs)
+                        End Using
+                        Me.img = New Bitmap(tempImage)
                     Catch ex As OutOfMemoryException
                         Dim filePath As String = Path.Combine(Application.StartupPath, Path.GetFileName(Me.tmpFilePath))
                         File.Copy(Me.tmpFilePath, filePath)
@@ -202,7 +206,10 @@ Public Class ImageCacheDictionary
                 Do
                     Try
                         err = False
-                        Me.img.Save(Me.tmpFilePath)
+                        Using fs As New FileStream(Me.tmpFilePath, FileMode.Open, FileAccess.Write)
+                            Me.img.Save(fs, Imaging.ImageFormat.Bmp)
+                            fs.Flush()
+                        End Using
                     Catch ex As InvalidOperationException
                         err = True
                     Catch ex As Exception