Thursday, July 15, 2010

Image data from Viewport

Link : http://www.grasshopper3d.com/forum/topics/how-to-get-the-image-data-such

Private Sub RunScript(ByRef A As Object)
RMA.Rhino.RhUtil.RhinoApp().RunScript("-_ViewCaptureToClipboard _Enter")

Dim img As Image = Windows.Forms.Clipboard.GetImage()

Dim bmp As New Bitmap(20, 20, Imaging.PixelFormat.Format24bppRgb)
Dim grp As Graphics = Graphics.FromImage(bmp)
grp.InterpolationMode = Drawing2D.InterpolationMode.HighQualityBicubic
grp.DrawImage(img, 0, 0, 20, 20)

Dim R As int32 = 0
Dim G As int32 = 0
Dim B As Int32 = 0

For i As Int32 = 0 To bmp.Width - 1
For j As Int32 = 0 To bmp.Height - 1
Dim col As Color = bmp.GetPixel(i, j)
R += col.R
G += col.G
B += col.B
Next
Next

R = Convert.ToInt32(R / 400)
G = Convert.ToInt32(G / 400)
B = Convert.ToInt32(B / 400)

A = Color.FromArgb(R, G, B)
End Sub


Screen Capture a Viewport
http://wiki.mcneel.com/developer/sdksamples/screencaptureview

No comments:

Post a Comment