Click or drag to resize

McRegionAccess Interface

The image pixel access interface. This interface provides access to the image. It will automatically translate image pixels into different color models. If the user modifies the translated image, the original image will also be updated.

Namespace:  MediaCy.IQL.Engine
Assembly:  MediaCy.IQL.Engine (in MediaCy.IQL.Engine.dll) Version: 10.0.6912.0
Syntax
VB
Public Interface McRegionAccess
	Inherits IMcRegionAccess
Examples
VB
VERSION 5.00
Begin {C62A69F0-16DC-11CE-9E98-00AA00574A4F} frmMosaic 
   Caption         =   "Mosaic"
   ClientHeight    =   6900
   ClientLeft      =   45
   ClientTop       =   435
   ClientWidth     =   6090
   OleObjectBlob   =   "frmMosaic.frx":0000
   StartUpPosition =   1  'CenterOwner
End





'*************************************
'example of McView
'that create a mosaic image of a sequence
'Clicking on mosaic image changes the active frame of the parent sequence
'*************************************

'with will use this object to track changes of active image
Private WithEvents m_Images As McImages
Attribute m_Images.VB_VarHelpID = -1
'track active frame index on the active image
Private WithEvents m_ActiveImage As McImage
'local mosaic image
Private m_MosaicImage As McImage

'size of image on mosaic
Private m_w As Long, m_h As Long
'number of image rows and columns
Private m_FramesInRow As Long, m_FramesInCol As Long

'update caption and draw rectangle around
Private Function UpdateFrame()
    If m_ActiveImage Is Nothing Then Exit Function
    'update frame number
    frmMosaic.Caption = "Mosaic View - " & m_ActiveImage.DisplayName & "(" & (m_ActiveImage.ActiveFrameIndex + 1) & ":" & m_ActiveImage.FrameCount & ")"

    'draw a rect around active frame
    Dim Row As Long, Col As Long
    Row = Int(m_ActiveImage.ActiveFrameIndex / m_FramesInRow)
    Col = Int(m_ActiveImage.ActiveFrameIndex Mod m_FramesInRow)
    'remove existing rect
    m_MosaicImage.AnnotationOverlay.RemoveAll
    Set ActiveGraphicObject = m_MosaicImage.AnnotationOverlay.Add("McGraphObjRect")
    With ActiveGraphicObject
        'set position
        .SetHandle 1, Col * m_w, Row * m_h
        .SetHandle 5, (Col + 1) * m_w - 1, (Row + 1) * m_h - 1
        .FillStyle = mcgfsBorderNoFill
        .BorderColor = RGB(255, 255, 0)
        .NotifyCreationComplete
    End With
End Function

'track frame change event
Private Sub m_ActiveImage_PropertyChanged(ByVal Image As McImage, ByVal Property As Long)
    If Property = ID_IMcImage_ActiveFrameIndex Then
        UpdateFrame
    End If
End Sub

'new image is activated
Private Sub m_Images_Activate(ByVal Image As McImage)
    'set new image
    Set m_ActiveImage = Image
    UpdateFromNewImage
End Sub

'image is deactivated
Private Sub m_Images_Deactivate(ByVal Image As McImage)
    If Images.Count = 0 Then
        'it is the last image, clean up the form
        Set m_ActiveImage = Nothing
        UpdateFromNewImage
    End If
End Sub

Private Sub sbFrameNumber_Change()
    'frame number changed, update view
    UpdateFrame
End Sub

Private Sub sbFrameNumber_Scroll()
    'frame number changed, update view
    UpdateFrame
End Sub

Private Sub UpdateFromNewImage()
    'get active image and set paramaters
    If m_ActiveImage Is Nothing Then
        'no image
        frmMosaic.Caption = "Mosaic View - No Image"
        Set m_MosaicImage = Nothing
        MosaicView.ImageToDisplay = Nothing
        Exit Sub
    End If

    'calculate number of images in rows and columns trying to have a square mosaic image
    m_FramesInRow = McSqrt(m_ActiveImage.Width * m_ActiveImage.Height * m_ActiveImage.FrameCount) / m_ActiveImage.Width 'round up
    m_FramesInCol = Int((m_ActiveImage.FrameCount + m_FramesInRow - 1) / m_FramesInRow)

    Dim i As Long
    m_w = m_ActiveImage.Width
    m_h = m_ActiveImage.Height

    'create a mosaic image as one-frame hidden image
    'using type of the source image
    Set m_MosaicImage = Images.Add(, m_w * m_FramesInRow, m_h * m_FramesInCol, 1, m_ActiveImage.Type, mcicfNoAddToCollection Or mcicfNotVisible)

    'set the same display range as on the original image
    m_MosaicImage.ImportProperties m_ActiveImage, mcipfLookupTables 'import LUT

    Dim srcRA As McRegionAccess, destRA As McRegionAccess
    'copy frames to mosaic image
    For i = 0 To m_ActiveImage.FrameCount - 1
        Dim Row As Long, Col As Long
        Row = Int(i / m_FramesInRow)
        Col = Int(i Mod m_FramesInRow)
        Set srcRA = m_ActiveImage.CreateRegionAccess(, , i)
        srcRA.FastAccess = True
        Set destRA = m_MosaicImage.CreateRegionAccess(, , , Col * m_w, Row * m_h, (Col + 1) * m_w - 1, (Row + 1) * m_h - 1)
        'copy area
        Dim v
        srcRA.GetArea v
        destRA.PutArea v
    Next i

    'set parameters of McView
    With MosaicView
        .AutoZoomMode = mazmBestFit
        'tell window to show all standard overlays
        .ViewerGroup = vgMDIImageWindow
        'attach active image
        .ImageToDisplay = m_MosaicImage
        'show image with overlay
        .Display.DisplayWhat = mcdwBothImageAndOverlays
    End With
    UpdateFrame
End Sub

'click on mosaic view
Private Sub MosaicView_MouseDown(ByVal lMouseButton As Long, ByVal lShift As Long, ByVal lMouseX As Long, ByVal lMouseY As Long, bHandled As Boolean)
    'get row/col from X and Y
    Dim r As Long, c As Long, fr As Long
    Dim clCoords(1) As Long, imCoords
    clCoords(0) = lMouseX
    clCoords(1) = lMouseY
    'convert client to image coordinates
    MosaicView.MapZoomedToImage clCoords, imCoords
    c = Int(imCoords(0, 0) / m_w)
    r = Int(imCoords(1, 0) / m_h)
    fr = r * m_FramesInRow + c
    If Not m_ActiveImage Is Nothing Then
        If fr >= 0 And fr < m_ActiveImage.FrameCount Then
            m_ActiveImage.ActiveFrameIndex = fr
            UpdateFrame
        End If
    End If
End Sub

'init
Private Sub UserForm_Initialize()
    'sync McImages collection to monitor the events
    Set m_Images = Images
    'set image
    Set m_ActiveImage = ActiveImage
    Set m_MosaicImage = Nothing
    UpdateFromNewImage
End Sub

'cleanup
Private Sub UserForm_Terminate()
   MosaicView.ImageToDisplay = Nothing
   Set m_Images = Nothing
   Set m_MosaicImage = Nothing
   Set m_ActiveImage = Nothing
End Sub
See Also