New Sub-Forum

In an effort to help make sure there are appropriate categories for topics of discussion that are happening, there is now a sub-forum for databases and database programming under Special Interest groups. Please direct questions, etc., about this topic to that sub-forum moving forward. Thank you.
See more
See less

Displaying Film Strip Images (Thumbnails)

  • Filter
  • Time
  • Show
Clear All
new posts

  • Displaying Film Strip Images (Thumbnails)

    Another member asked me about how to display a sequence of images captured from a video source. Here's a first pass of how that might look ...

    Images, source code and EXE here.

    The code assumes there are an unspecified number of same-size images in a subfolder "images". The code loads all the images into a memory bitmap array, then displays as many images as will fit along the bottom of the dialog. A caption is written to each, over the image. Buttons are provided to scroll left/right one image. I've set the image display areas to be 100x100 but the code allows for other sizes (untested). The full images are resized to fit the image display area, keeping the same aspect ratio.

    Click image for larger version

Name:	pb_2195.jpg
Views:	141
Size:	26.2 KB
ID:	788672

    'Compilable Example:
    #Compiler PBWin 10
    #Compile Exe
    #Dim All
    %Unicode = 1
    #Include ""
    #Include ""
    %IDC_Graphic = 500
    %IDC_Left = 501
    %IDC_Right = 502
    %IDC_Label = 503
    Type FilmImageType
    hBMP As Dword
    w As Long
    h As Long
    End Type
    Global hDlg As Dword, Images() As FilmImageType
    Global LeftFrame, wFilm, hFilm As Long 'film strip size
    Function PBMain() As Long
    Dialog Default Font "Tahoma", 36,1
    Dialog New Pixels, 0, "Video Frame Images",300,300,500,200, %WS_OverlappedWindow To hDlg
    Control Add Label, hDlg, %IDC_Label, "Film Strip Images", 0,0,500,400, %SS_Center
    Control Add Graphic, hDlg, %IDC_Graphic,"", 0,100,400,200, %WS_Border
    Graphic Attach hdlg, %IDC_Graphic, ReDraw
    Control Add Button, hDlg, %IDC_Left, "<", 0,100,50,100
    Control Add Button, hDlg, %IDC_Right, ">", 350,100,50,100
    Dialog Show Modal hDlg Call DlgProc
    End Function
    CallBack Function DlgProc() As Long
    Local w,h As Long
    Select Case Cb.Msg
    Case %WM_InitDialog
    Randomize Timer : CreateBMPArray("images\")
    LeftFrame = 1
    wFilm = 100 : hFilm = 100
    Case %WM_Command
    Select Case Cb.Ctl
    Case %IDC_Left : LeftFrame = Max(1,LeftFrame-1) : DrawImages
    Case %IDC_Right : LeftFrame = Min(UBound(Images),LeftFrame+1) : DrawImages
    End Select
    Case %WM_Size
    Dialog Get Client hDlg To w,h
    Control Set Size hDlg, %IDC_Label, w, 75
    Control Set Loc hDlg, %IDC_Graphic, 50, h-hFilm
    Control Set Size hDlg, %IDC_Graphic, w-100, h-hFilm
    Control Set Loc hDlg, %IDC_Right, w-50, h-hFilm
    Control Set Loc hDlg, %IDC_Left, 0, h-hFilm
    End Select
    End Function
    Sub CreateBMPArray(folder$)
    Local temp$, iCount As Long
    ReDim Images(1000)
    temp$ = Dir$(folder$ + "*.*")
    While Len(temp$)
    Incr iCount
    LoadImageToMemoryBitmap folder$ + temp$, Images(iCount).hBMP, Images(iCount).w, Images(iCount).h
    '? folder$ + temp$ + " " + Str$(Images(iCount).hBMP) + Str$(Images(iCount).w) + Str$(Images(iCount).h)
    temp$ = Dir$(Next)
    ReDim Preserve Images(iCount)
    End Sub
    Sub LoadImageToMemoryBitmap (ImgName As String, hBMP As Dword, w As Long, h As Long)
    Local pGraphics,pImage,hDC,token As Dword, StartupInput As GdiplusStartupInput
    'initialize GDI
    StartupInput.GdiplusVersion = 1 'initialize GDIPlus
    GdiplusStartup(token, StartupInput, ByVal %NULL) 'initialize GDIPlus
    GdipLoadImageFromFile((ImgName), pImage) 'load image
    GdipGetImageWidth(pImage,w) 'get width
    GdipGetImageHeight(pImage, h) 'get height
    Graphic Bitmap New w,h To hBMP
    Graphic Attach hBMP, 0
    Graphic Get DC To hDC
    GdipCreateFromHDC(hDC, pGraphics) ' Create the Graphic object
    GdipDrawImageRect(pGraphics, pImage,0,0,w,h) ' Draw the image
    If pImage Then GdipDisposeImage(pImage) 'cleanup
    If pGraphics Then GdipDeleteGraphics(pGraphics) 'cleanup
    GdiplusShutdown token 'shutdown GDI+
    End Sub
    Sub DrawImages
    Local iCount,i,x,y,w,h,Frames As Long
    Control Get Size hDlg, %IDC_Graphic To w,h
    'draw squares
    Graphic Attach hDlg, %IDC_Graphic
    Graphic Set StretchMode %HalfTone
    Graphic Clear
    Frames = Ceil(w/wFilm)
    For i = LeftFrame To Min(LeftFrame+Frames-1,UBound(Images))
    Incr iCount
    x = (iCount-1) * wFilm
    y = 0
    Graphic Box (x,y)-(x+wFilm,y+hFilm),,%Black
    DrawImage i,x,y
    Graphic Set Pos (x,y) : Graphic Print i
    Next i
    Graphic ReDraw
    End Sub
    Sub DrawImage(i As Long, x As Long, y As Long)
    Local wNew,hNew,wCont,hCont,xOffset,yOffset As Long, Factor As Single
    Factor = 0.95
    wCont = wFilm
    hCont = hFilm
    wCont = Factor * wCont
    hCont = Factor * hCont
    wNew = Images(i).w / Max(Images(i).w / wCont, Images(i).h / hCont)
    hNew = Images(i).h / Max(Images(i).w / wCont, Images(i).h / hCont)
    xOffset = (wCont-wNew)/2 + (1-Factor)*wCont/2
    yOffset = (hCont-hNew)/2 + (1-Factor)*hCont/2 'upper/left position so resized image is centered
    Graphic Stretch Images(i).hBMP, 0, (0,0)-(Images(i).w,Images(i).h) To (x+xOffSet,y+yOffset)-(x+xOffSet+wNew,y+yOffset+hNew) 'copy (resized) from memory bitmap to visible image
    End Sub