From: kiri_feather Date: Sun, 6 Jun 2010 11:20:04 +0000 (+0000) Subject: 不正GIFチェックを画像取得通信部へ移動 X-Git-Tag: Tween_v0.9.2.3-beta~10 X-Git-Url: http://git.osdn.net/view?a=commitdiff_plain;h=441712f102bd14cf65465d9c1ed4df8c7a7dc5e9;p=opentween%2Fopen-tween.git 不正GIFチェックを画像取得通信部へ移動 git-svn-id: http://svn.sourceforge.jp/svnroot/tween/trunk@456 e39ad16e-3079-482e-bb30-4b4d378143b6 --- diff --git a/Tween/Connection/HttpVarious.vb b/Tween/Connection/HttpVarious.vb index 1365b30c..ec09d059 100644 --- a/Tween/Connection/HttpVarious.vb +++ b/Tween/Connection/HttpVarious.vb @@ -26,26 +26,17 @@ Public Class HttpVarious End Function Public Overloads Function GetImage(ByVal url As String) As Image - Try - Dim req As HttpWebRequest = CreateRequest(GetMethod, New Uri(url), Nothing, False) - req.Timeout = 5000 - Dim img As Bitmap = Nothing - Dim ret As HttpStatusCode = GetResponse(req, img, Nothing, False) - If ret = HttpStatusCode.OK Then Return img - Return Nothing - Catch ex As Exception - Return Nothing - End Try + Return GetImage(url, "") End Function Public Overloads Function GetImage(ByVal url As String, ByVal referer As String) As Image Try Dim req As HttpWebRequest = CreateRequest(GetMethod, New Uri(url), Nothing, False) - req.Referer = referer + If Not String.IsNullOrEmpty(referer) Then req.Referer = referer req.Timeout = 5000 Dim img As Bitmap = Nothing Dim ret As HttpStatusCode = GetResponse(req, img, Nothing, False) - If ret = HttpStatusCode.OK Then Return img + If ret = HttpStatusCode.OK Then Return CheckValidImage(img) Return Nothing Catch ex As Exception Return Nothing @@ -123,4 +114,35 @@ Public Class HttpVarious Return False End Try End Function + + Private Function CheckValidImage(ByVal img As Image) 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(48, 48) + Using g As Graphics = Graphics.FromImage(bmp) + g.InterpolationMode = Drawing2D.InterpolationMode.High + g.DrawImage(img, 0, 0, 48, 48) + End Using + img.Dispose() + Return bmp + End Try + Else + Return img + End If + Else + Return img + End If + End Function + End Class diff --git a/Tween/MyCommon.vb b/Tween/MyCommon.vb index b2ddc74c..707716f4 100644 --- a/Tween/MyCommon.vb +++ b/Tween/MyCommon.vb @@ -542,33 +542,4 @@ retry: Public fileVersion As String - Public Function CheckValidImage(ByVal img As Image) 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(48, 48) - Using g As Graphics = Graphics.FromImage(bmp) - g.InterpolationMode = Drawing2D.InterpolationMode.High - g.DrawImage(img, 0, 0, 48, 48) - End Using - img.Dispose() - Return bmp - End Try - Else - Return img - End If - Else - Return img - End If - End Function End Module diff --git a/Tween/Tween.resx b/Tween/Tween.resx index ae45a5bb..6f972d32 100644 --- a/Tween/Tween.resx +++ b/Tween/Tween.resx @@ -147,25 +147,25 @@ 237, 17 - 237, 22 + 280, 22 URLからの全角文字列の切り離し - 237, 22 + 280, 22 APIコマンドを回避する - 237, 22 + 280, 22 自動的にURLを短縮する - 237, 22 + 280, 22 全角スペースを半角スペースにする @@ -174,19 +174,19 @@ Ctrl+Y - 237, 22 + 280, 22 発言欄複数行入力(&M) - 234, 6 + 277, 6 Ctrl+Shift+T - 237, 22 + 280, 22 ハッシュタグ自動付加 @@ -195,13 +195,13 @@ Ctrl+T - 237, 22 + 280, 22 ハッシュタグ設定 - 238, 164 + 281, 164 ContextMenuStripPostMode @@ -268,28 +268,28 @@ 411, 54 - 188, 22 + 226, 22 タブ作成(&N)... - 188, 22 + 226, 22 タブ名の変更(&R) - 185, 6 + 223, 6 - 188, 22 + 226, 22 未読管理(&U) - 188, 22 + 226, 22 新着通知表示(&Q) @@ -301,34 +301,34 @@ 再生するwavファイルを指定してください - 185, 6 + 223, 6 - 188, 22 + 226, 22 振り分けルール編集(&F)... - 185, 6 + 223, 6 - 188, 22 + 226, 22 このタブの発言をクリア(&C) - 185, 6 + 223, 6 - 188, 22 + 226, 22 タブ削除(&D) - 189, 206 + 227, 212 ContextMenuTabProperty @@ -457,22 +457,22 @@ 498, 91 - 120, 22 + 136, 22 IconName - 117, 6 + 133, 6 - 120, 22 + 136, 22 保存(&I)... - 121, 54 + 137, 54 ContextMenuStrip3 @@ -550,37 +550,37 @@ 17, 91 - 195, 22 + 220, 22 フォローする - 195, 22 + 220, 22 フォロー解除 - 195, 22 + 220, 22 相互フォロー状態表示 - 195, 22 + 220, 22 プロフィール表示 - 195, 22 + 220, 22 このユーザーの発言を検索 - 196, 114 + 221, 114 ContextMenuStripDetailName @@ -661,16 +661,16 @@ 現在のタブ(&L) - 195, 22 + 220, 22 選択文字列で検索(&S) - 192, 6 + 217, 6 - 195, 22 + 220, 22 選択文字列をコピー(&C) @@ -679,70 +679,70 @@ False - 195, 22 + 220, 22 URLをコピー(&U) - 195, 22 + 220, 22 すべて選択(&A) - 192, 6 + 217, 6 - 195, 22 + 220, 22 フォローする(&F) - 195, 22 + 220, 22 フォロー解除(&N) - 195, 22 + 220, 22 相互フォロー状態表示(&R) - 195, 22 + 220, 22 プロフィール表示 - 195, 22 + 220, 22 このユーザーの発言を検索 - 192, 6 + 217, 6 - 195, 22 + 220, 22 ID振分ルール作成(&I) - 192, 6 + 217, 6 - 195, 22 + 220, 22 ハッシュタグを固定(&H) - 196, 270 + 221, 270 ContextMenuStrip4 @@ -1828,58 +1828,58 @@ 163, 54 - 182, 22 + 202, 22 @返信(&R) - 182, 22 + 202, 22 @返信ALL(&E) - 182, 22 + 202, 22 DM送信(&M) - 182, 22 + 202, 22 Re&tweet - 182, 22 + 202, 22 Retweet(U&nofficial) - 182, 22 + 202, 22 &Quote - 179, 6 + 199, 6 - 182, 22 + 202, 22 Fav追加(&F) - 182, 22 + 202, 22 Fav削除(&V) - 182, 22 + 202, 22 プロフィール表示 @@ -1927,7 +1927,7 @@ RTした人のホームを開く(&R) - 182, 22 + 202, 22 開く(&O) @@ -1945,13 +1945,13 @@ ID振り分けルール作成... - 182, 22 + 202, 22 振り分けルール作成(&C) - 179, 6 + 199, 6 154, 22 @@ -1966,46 +1966,46 @@ 未読にする - 182, 22 + 202, 22 未読状態変更(&H) - 182, 22 + 202, 22 未読へジャンプ(&J) - 179, 6 + 199, 6 - 182, 22 + 202, 22 全て選択(&A) - 182, 22 + 202, 22 削除(&D) - 182, 22 + 202, 22 更新(&U) - 182, 22 + 202, 22 前データを取得(&I) - 183, 396 + 203, 396 ContextMenuStrip2 @@ -2017,55 +2017,55 @@ 17, 54 - 168, 22 + 189, 22 設定(&O)... - 165, 6 + 186, 6 - 168, 22 + 189, 22 ファイル保存(&S)... - 165, 6 + 186, 6 - 168, 22 + 189, 22 新着通知(&Q) - 168, 22 + 189, 22 サウンド再生(&P) - 168, 22 + 189, 22 新着時リスト固定(&L) - 165, 6 + 186, 6 False - 168, 22 + 189, 22 終了(&X) - 169, 154 + 190, 154 ContextMenuStrip1 diff --git a/Tween/Tween.vb b/Tween/Tween.vb index d47e90c4..a8e8135c 100644 --- a/Tween/Tween.vb +++ b/Tween/Tween.vb @@ -8267,7 +8267,7 @@ RETRY: ' 画像直リンク Dim img As Image = http.GetImage(url.Value, url.Key) If img Is Nothing Then Continue For - arg.pics.Add(New KeyValuePair(Of String, Image)(url.Key, CheckValidImage(img))) + arg.pics.Add(New KeyValuePair(Of String, Image)(url.Key, img)) arg.tooltiptext.Add(New KeyValuePair(Of String, String)(url.Key, "")) ElseIf url.Key.StartsWith("http://www.pixiv.net/") Then Dim src As String = "" @@ -8282,7 +8282,7 @@ RETRY: If _mc.Success Then Dim _img As Image = http.GetImage(_mc.Value, url.Key) If _img Is Nothing Then Continue For - arg.pics.Add(New KeyValuePair(Of String, Image)(url.Key, CheckValidImage(_img))) + arg.pics.Add(New KeyValuePair(Of String, Image)(url.Key, _img)) arg.tooltiptext.Add(New KeyValuePair(Of String, String)(url.Key, "")) End If End If @@ -8297,7 +8297,7 @@ RETRY: If _mc.Count > 1 Then Dim _img As Image = http.GetImage(_mc.Item(1).Value, url.Key) If _img Is Nothing Then Continue For - arg.pics.Add(New KeyValuePair(Of String, Image)(url.Key, CheckValidImage(_img))) + arg.pics.Add(New KeyValuePair(Of String, Image)(url.Key, _img)) arg.tooltiptext.Add(New KeyValuePair(Of String, String)(url.Key, "")) End If End If @@ -8315,7 +8315,7 @@ RETRY: Dim min_img_url As String = r.Replace(_mc.Value, "_0120_0120") Dim _img As Image = http.GetImage(min_img_url, url.Key) If _img Is Nothing Then Continue For - arg.pics.Add(New KeyValuePair(Of String, Image)(url.Key, CheckValidImage(_img))) + arg.pics.Add(New KeyValuePair(Of String, Image)(url.Key, _img)) arg.tooltiptext.Add(New KeyValuePair(Of String, String)(url.Key, "")) End If End If @@ -8338,7 +8338,7 @@ RETRY: If String.IsNullOrEmpty(thumbnail_url) Then Continue For Dim _img As Image = http.GetImage(thumbnail_url, url.Key) If _img Is Nothing Then Continue For - arg.pics.Add(New KeyValuePair(Of String, Image)(url.Key, CheckValidImage(_img))) + arg.pics.Add(New KeyValuePair(Of String, Image)(url.Key, _img)) arg.tooltiptext.Add(New KeyValuePair(Of String, String)(url.Key, "")) Continue For End If @@ -8371,7 +8371,7 @@ RETRY: If Not String.IsNullOrEmpty(imgurl) Then Dim _img As Image = http.GetImage(imgurl, url.Key) If _img Is Nothing Then Continue For - arg.pics.Add(New KeyValuePair(Of String, Image)(url.Key, CheckValidImage(_img))) + arg.pics.Add(New KeyValuePair(Of String, Image)(url.Key, _img)) arg.tooltiptext.Add(New KeyValuePair(Of String, String)(url.Key, "")) End If End If @@ -8479,7 +8479,7 @@ RETRY: If Not String.IsNullOrEmpty(imgurl) Then Dim _img As Image = http.GetImage(imgurl, url.Key) If _img Is Nothing Then Continue For - arg.pics.Add(New KeyValuePair(Of String, Image)(url.Key, CheckValidImage(_img))) + arg.pics.Add(New KeyValuePair(Of String, Image)(url.Key, _img)) arg.tooltiptext.Add(New KeyValuePair(Of String, String)(url.Key, sb.ToString.Trim())) End If End If @@ -8505,7 +8505,7 @@ RETRY: If String.IsNullOrEmpty(thumbnail_url) Then Continue For Dim _img As Image = http.GetImage(thumbnail_url, url.Key) If _img Is Nothing Then Continue For - arg.pics.Add(New KeyValuePair(Of String, Image)(url.Key, CheckValidImage(_img))) + arg.pics.Add(New KeyValuePair(Of String, Image)(url.Key, _img)) arg.tooltiptext.Add(New KeyValuePair(Of String, String)(url.Key, "")) Continue For End If @@ -8515,7 +8515,7 @@ RETRY: ' 直リンクでなく、パターンに合致しない Dim img As Image = http.GetImage(url.Value, url.Key) If img Is Nothing Then Continue For - arg.pics.Add(New KeyValuePair(Of String, Image)(url.Key, CheckValidImage(img))) + arg.pics.Add(New KeyValuePair(Of String, Image)(url.Key, img)) arg.tooltiptext.Add(New KeyValuePair(Of String, String)(url.Key, "")) End If Next diff --git a/Tween/Twitter.vb b/Tween/Twitter.vb index 43ff2cdd..3548293c 100644 --- a/Tween/Twitter.vb +++ b/Tween/Twitter.vb @@ -378,7 +378,7 @@ Public Class Twitter g.Dispose() End Using - _dIcon.Add(post.ImageUrl, CheckValidImage(img)) + _dIcon.Add(post.ImageUrl, img) _lIcon.Images.Add(post.ImageUrl, bmp2) post.ImageIndex = _lIcon.Images.IndexOfKey(post.ImageUrl) Catch ex As InvalidOperationException