OSDN Git Service

DrawImageでのOverflowException回避。不正なアイコン?
authorkiri_feather <kiri_feather@users.sourceforge.jp>
Thu, 27 May 2010 10:48:56 +0000 (10:48 +0000)
committerKimura Youichi <kim.upsilon@bucyou.net>
Sat, 18 Feb 2012 14:12:52 +0000 (23:12 +0900)
git-svn-id: http://svn.sourceforge.jp/svnroot/tween/trunk@383 e39ad16e-3079-482e-bb30-4b4d378143b6

Tween/Twitter.vb

index daa96d8..d5d44ab 100644 (file)
@@ -367,50 +367,49 @@ Public Class Twitter
 
             If _endingFlag Then Exit Sub
 
-            bmp2 = New Bitmap(_iconSz, _iconSz)
-            Using g As Graphics = Graphics.FromImage(bmp2)
-                g.InterpolationMode = Drawing2D.InterpolationMode.High
-                g.DrawImage(img, 0, 0, _iconSz, _iconSz)
-                g.Dispose()
-            End Using
-
             SyncLock LockObj
-                post.ImageIndex = _lIcon.Images.IndexOfKey(post.ImageUrl)
-                If post.ImageIndex = -1 Then
-                    Try
-                        If img.RawFormat.Guid = Imaging.ImageFormat.Gif.Guid Then
-                            Dim fd As New System.Drawing.Imaging.FrameDimension(img.FrameDimensionsList(0))
-                            Dim fd_count As Integer = img.GetFrameCount(fd)
-                            If fd_count > 1 Then
-                                Try
-                                    For i As Integer = 0 To fd_count - 1
-                                        img.SelectActiveFrame(fd, i)
-                                    Next
-                                    _dIcon.Add(post.ImageUrl, img)  '詳細表示用ディクショナリに追加
-                                Catch ex As Exception
-                                    Dim bmp As New Bitmap(48, 48)
-                                    Using g As Graphics = Graphics.FromImage(bmp)
-                                        g.InterpolationMode = Drawing2D.InterpolationMode.High
-                                        g.DrawImage(img, 0, 0, 48, 48)
-                                    End Using
-                                    _dIcon.Add(post.ImageUrl, bmp)  '詳細表示用ディクショナリに追加
-                                    img.Dispose()
-                                End Try
-                            Else
+                Try
+                    bmp2 = New Bitmap(_iconSz, _iconSz)
+                    Using g As Graphics = Graphics.FromImage(bmp2)
+                        g.InterpolationMode = Drawing2D.InterpolationMode.High
+                        g.DrawImage(img, 0, 0, _iconSz, _iconSz)
+                        g.Dispose()
+                    End Using
+
+                    If img.RawFormat.Guid = Imaging.ImageFormat.Gif.Guid Then
+                        Dim fd As New System.Drawing.Imaging.FrameDimension(img.FrameDimensionsList(0))
+                        Dim fd_count As Integer = img.GetFrameCount(fd)
+                        If fd_count > 1 Then
+                            Try
+                                For i As Integer = 0 To fd_count - 1
+                                    img.SelectActiveFrame(fd, i)
+                                Next
                                 _dIcon.Add(post.ImageUrl, img)  '詳細表示用ディクショナリに追加
-                            End If
-                            _lIcon.Images.Add(post.ImageUrl, bmp2)
-                            post.ImageIndex = _lIcon.Images.IndexOfKey(post.ImageUrl)
+                            Catch ex As Exception
+                                Dim bmp As New Bitmap(48, 48)
+                                Using g As Graphics = Graphics.FromImage(bmp)
+                                    g.InterpolationMode = Drawing2D.InterpolationMode.High
+                                    g.DrawImage(img, 0, 0, 48, 48)
+                                End Using
+                                _dIcon.Add(post.ImageUrl, bmp)  '詳細表示用ディクショナリに追加
+                                img.Dispose()
+                            End Try
                         Else
-                            _dIcon.Add(post.ImageUrl, img)
-                            _lIcon.Images.Add(post.ImageUrl, bmp2)
-                            post.ImageIndex = _lIcon.Images.IndexOfKey(post.ImageUrl)
+                            _dIcon.Add(post.ImageUrl, img)  '詳細表示用ディクショナリに追加
                         End If
-                    Catch ex As InvalidOperationException
-                        'タイミングにより追加できない場合がある?(キー重複ではない)
-                        post.ImageIndex = -1
-                    End Try
-                End If
+                        _lIcon.Images.Add(post.ImageUrl, bmp2)
+                        post.ImageIndex = _lIcon.Images.IndexOfKey(post.ImageUrl)
+                    Else
+                        _dIcon.Add(post.ImageUrl, img)
+                        _lIcon.Images.Add(post.ImageUrl, bmp2)
+                        post.ImageIndex = _lIcon.Images.IndexOfKey(post.ImageUrl)
+                    End If
+                Catch ex As InvalidOperationException
+                    'タイミングにより追加できない場合がある?(キー重複ではない)
+                    post.ImageIndex = -1
+                Catch ex As System.OverflowException
+                    '不正なアイコン?DrawImageに失敗する場合あり
+                End Try
             End SyncLock
             TabInformations.GetInstance.AddPost(post)
         Catch ex As ArgumentException