| 日時: 2007/09/14 20:16名前: 花ちゃん
 
************************************************************************************ カテゴリー:[ファイル][描画・画像][]                                            *
 * キーワード:リストビュー,イメージリスト,,,,                                  *
 ***********************************************************************************
 
 元質問:画像をどのくらいの量なら、読み.. - はるか  2007/08/18-01:32No.9916
 
 imageboxにフォルダの中にあるたくさんのjpg写真を読込んで、サムネイルを取り扱う動作をやりたいのですが
 ◆画像のサイズやパソコンの環境によっては、数が多すぎると重くなって動かないかもしれな
 ということを懸念しています。
 ◆現在たくさんの写真を重ねて表示して、上の写真をドラッグで移動すると、写真が再表示sれようとして、画面がちらつきます。
 
 1.実際のところ何メガ程度までなら問題なく動くのか
 2.サムネイルファイルを作成して、再度、読み込むほうが、動作は軽くなるのか
 3.bmpとjpgで「画像の形状大きさ」が同じ場合はjpgのほうが軽いのか?
 4.画像がちらつかない方法はあるのか
 
 -----------------------------------------------------------------------------------
 Re^3: 画像をどのくらいの量なら.. - Starfish  2007/08/19-10:37 No.9923
 -----------------------------------------------------------------------------------
 
 イメージリスト、リストビュー、ピクチャボックス(2個)、コマンドボタンを貼り付けて、
 
 
 Private Sub Command1_Click()
 Dim lngImageSize        As Long
 Dim strFolder           As String
 Dim strFileType         As String
 Dim strFileName         As String
 Dim imgX                As ListImage
 Dim itmX                As ListItem
 Dim sngPosX             As Single
 Dim sngPosY             As Single
 Dim sngWidth            As Single
 Dim sngHeight           As Single
 
 ' 設定部分
 lngImageSize = 64           ' サムネイルのサイズ
 strFolder = "C:\Temp\"      ' 対象のフォルダ
 strFileType = "jpg"         ' ファイルタイプ
 
 ' 実サイズで表示するコントロール
 Picture1.BorderStyle = vbBSNone
 Picture1.AutoSize = True
 Picture1.Visible = False
 
 ' サムネイルのサイズで表示するコンロトール
 Picture2.BorderStyle = vbBSNone
 Picture2.Width = lngImageSize * Screen.TwipsPerPixelX
 Picture2.Height = lngImageSize * Screen.TwipsPerPixelY
 Picture2.AutoRedraw = True
 Picture2.BackColor = vbWhite
 Picture2.Visible = False
 
 ' リストビューとイメージリストの初期化
 ListView1.Arrange = lvwAutoTop
 ListView1.ListItems.Clear
 Set ListView1.Icons = Nothing
 ImageList1.ListImages.Clear
 ImageList1.ImageHeight = lngImageSize
 ImageList1.ImageWidth = lngImageSize
 Picture2.Picture = Picture1.Image
 Set imgX = ImageList1.ListImages.Add(, "Dummy", Picture2.Picture)
 Set ListView1.Icons = ImageList1
 
 On Error Resume Next
 
 ' 全てのファイルを繰り返し
 strFileName = Dir(strFolder & "*." & strFileType)
 While strFileName <> ""
 Set itmX = ListView1.ListItems.Add(, , strFileName)
 Picture1.Picture = LoadPicture("")
 Picture1.Picture = LoadPicture(strFolder & strFileName)
 If Err.Number = 0 Then
 If Picture1.ScaleWidth <= lngImageSize * Screen.TwipsPerPixelX And _
 Picture1.ScaleHeight <= lngImageSize * Screen.TwipsPerPixelY Then
 sngPosX = (lngImageSize * Screen.TwipsPerPixelX -  _
 Picture1.ScaleWidth) / 2
 sngWidth = Picture1.ScaleWidth
 sngPosY = (lngImageSize * Screen.TwipsPerPixelY - _
 Picture1.ScaleHeight) / 2
 sngHeight = Picture1.ScaleHeight
 Else
 If Picture1.ScaleWidth > Picture1.ScaleHeight Then
 sngWidth = lngImageSize * Screen.TwipsPerPixelX
 sngPosX = 0
 sngHeight = lngImageSize * Screen.TwipsPerPixelY * _
 Picture1.ScaleHeight / Picture1.ScaleWidth
 sngPosY = (lngImageSize * Screen.TwipsPerPixelY - sngHeight) / 2
 Else
 sngHeight = lngImageSize * Screen.TwipsPerPixelY
 sngPosY = 0
 sngWidth = lngImageSize * Screen.TwipsPerPixelX * _
 Picture1.ScaleWidth / Picture1.ScaleHeight
 sngPosX = (lngImageSize * Screen.TwipsPerPixelX - sngWidth) / 2
 End If
 End If
 If sngWidth < Screen.TwipsPerPixelX Then sngWidth = Screen.TwipsPerPixelX
 If sngHeight < Screen.TwipsPerPixelY Then sngHeight = Screen.TwipsPerPixelY
 Picture2.Width = lngImageSize * Screen.TwipsPerPixelX
 Picture2.Height = lngImageSize * Screen.TwipsPerPixelY
 Picture2.Picture = LoadPicture("")
 Picture2.PaintPicture Picture1.Image, sngPosX, sngPosY, sngWidth, sngHeight
 Picture2.Picture = Picture2.Image
 Set imgX = ImageList1.ListImages.Add(, , Picture2.Picture)
 If Err.Number = 0 Then
 itmX.Icon = ImageList1.ListImages.Count
 Else
 If Err.Number = 7 Then
 MsgBox "メモリ不足です。" & _
 "イメージの表示サイズを小さくしてください。", vbCritical
 End If
 End If
 End If
 
 strFileName = Dir()
 Wend
 
 On Error Goto 0
 
 End Sub
 
 ---------------------------------------------------------------------------
 上記実行画面(画像をクリックすると元のサイズで見られます。)
 
 
 |