IMcRegionAccessGetPixel Method |
![]() |
Namespace: MediaCy.IQL.Engine
Function GetPixel ( <OutAttribute> ByRef pvPixel As Object, x As Integer, y As Integer ) As Integer
VERSION 5.00 Begin {C62A69F0-16DC-11CE-9E98-00AA00574A4F} SurfacePlot Caption = "SurfacePlot" ClientHeight = 7245 ClientLeft = 45 ClientTop = 435 ClientWidth = 8250 OleObjectBlob = "SurfacePlot.frx":0000 ShowModal = 0 'False StartUpPosition = 1 'CenterOwner End '****************************************************************** ' SurfacePlot.frm demonstarting McRegionAccess.GetPixel method '****************************************************************** Option Explicit 'limit maximum plot size Const MaxPlotSize = 50 'we use this object to track changes of active image Private WithEvents m_Images As McImages Attribute m_Images.VB_VarHelpID = -1 Private Sub SetImageToPlot(Image As McImage) If Image Is Nothing Then SurfacePlot.Caption = "Surface Plot - No Image" MSChart1.Visible = False Exit Sub End If SurfacePlot.Caption = "Surface Plot of " & Image.DisplayName Dim srcImage As McImage, MaxSize As Long, ResizeScale As Double MaxSize = McMax(Image.Width, Image.Height) If MaxSize > MaxPlotSize Then 'resize the image ResizeScale = MaxPlotSize / MaxSize 'create a new small hidden image Set srcImage = Image.Geometry.Resize(Image.Width * ResizeScale, Image.Height * ResizeScale, mcsmBicubic, mcicfNoAddToCollection Or mcicfNotVisible Or mcicfNoInit, Image) Else Set srcImage = Image End If Dim bUseGetPixel As Boolean 'set bUseGetPixel=false to use fast method (ChartData) bUseGetPixel = False If bUseGetPixel Then Dim srcRA As McRegionAccess 'get src McRegionAccess as 8-bit gray Set srcRA = srcImage.CreateRegionAccess(mciqtGray) Dim Row As Long, Column As Long, val With MSChart1 .ColumnCount = srcRA.Width .RowCount = srcRA.Height For Column = 1 To .ColumnCount .Column = Column For Row = 1 To .RowCount .Row = Row 'get data value from pixel position srcRA.GetPixel val, Column - 1, Row - 1 'set data value to plot .Data = val Next Row Next Column End With Else 'plot image using fast method PlotImageFast srcImage End If 'set color for every serie Dim vCol As Variant For Each vCol In MSChart1.Plot.SeriesCollection With vCol.DataPoints(-1) 'set red color to plot .Brush.FillColor.Set 255, 0, 0 'red color .Brush.Style = IIf(chTransparent.value, 0, 1) 'MSChart20Lib.VtBrushStyleNull, MSChart20Lib.VtBrushStyleSolid End With Next 'show graph MSChart1.Visible = True Set srcRA = Nothing End Sub 'fast method of plot image 'using McRegionAccess.GetArea and MSChart1.ChartData Private Function PlotImageFast(srcImage As McImage) Dim srcRA As McRegionAccess 'get src McRegionAccess as floating point to be compatible with MSChart data type (Byte can not be used with MSChart1.ChartData ) Set srcRA = srcImage.CreateRegionAccess(mciqtFloat) Dim vAr() As Single 'allocate data array ReDim vAr(1 To srcRA.Width, 1 To srcRA.Height) As Single 'get all pixels within area srcRA.GetArea vAr 'set data array to chart MSChart1.ChartData = vAr End Function Private Sub chTransparent_Click() 'rebuild graph with new transparency SetImageToPlot ActiveImage End Sub 'new image is activated Private Sub m_Images_Activate(ByVal Image As McImage) SetImageToPlot Image 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 SetImageToPlot Nothing End If End Sub 'example demonstrates using McRegionAccess.GetPixel method Private Sub UserForm_Initialize() 'load demo image Images.Open (Path & "Images\AFM_SURF.tif") 'sync McImages collection to monitor the events Set m_Images = Images SetImageToPlot ActiveImage End Sub