Public Overloads Function CheckValidImage(ByVal img As Image, ByVal width As Integer, ByVal height As Integer) As Image
If img Is Nothing Then Return Nothing
- 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
- Return img
- Catch ex As Exception
- '不正な画像の場合は、bitmapに書き直し
- Dim bmp As New Bitmap(width, height)
- Dim tag As Object = img.Tag
- Using g As Graphics = Graphics.FromImage(bmp)
- g.InterpolationMode = Drawing2D.InterpolationMode.High
- g.DrawImage(img, 0, 0, width, height)
- End Using
- img.Dispose()
- bmp.Tag = tag
- Return bmp
- End Try
- Else
- Return img
- End If
- Else
- Return img
- End If
+ Dim bmp As New Bitmap(width, height)
+ Dim tag As Object = img.Tag
+ Using g As Graphics = Graphics.FromImage(bmp)
+ g.InterpolationMode = Drawing2D.InterpolationMode.High
+ g.DrawImage(img, 0, 0, width, height)
+ End Using
+ img.Dispose()
+ bmp.Tag = tag
+ Return bmp
End Function
End Class