algorithmic modeling for Rhino
Tags:
Hey David,
Any chance you or someone else could post the above component? The one where you state
"GetPixel and SetPixel are the slowest possible calls. What I do in the Image sampler is to copy the entire bitmap data into a ByteArray, then directly access the elements. It's even faster than Marshal.ReadByte, provided you sample it a lot. There is of course plenty of overhead in copying the image data.
If you wrote the script in C#, you could use the unsafe keyword to get the best of both worlds."
I need a component like the get pixel that I specify the file type that works faster then the get pixel method.I would be extremely helped out of a tough spot for a workshop I've been preparing. Thank you so much.
Best,
Rob
Hi Rob,
if you're to do this within Grasshopper, just use the Grasshopper.Kernel.GH_MemoryBitmap class. It has the ultra fast sampling build in, as well as a bunch of pixel effects I need left and right.
When you create a new instance of the GH_MemoryBitmap class, it will lock the bitmap bytes into memory, meaning the image becomes just so much ones-and-zeros. Then when you're done sampling/changing the bitmap, you need to call the Release() method to make sure the bits become unlocked again and the bitmap can once again be used by other functions. If you don't call Release, the bitmap (in memory) will forever remain locked and inaccessible.
Something akin to this would be ideal:
'Declare a new sampler class
Dim sampler As New GH_MemoryBitmap(myBitmap)
Try
'Iterate over all sampling locations
For Each point in allSamplePoints
Dim col As Color = Color.Transparent
'Sample the bitmap at {x,y}
If (sampler.Sample(point.X, point.Y, col)) Then
'If the sampling op went fine, append the colour to a list
sampleResult.Add(col)
End If
Next
Catch ex As Exception
'Report on any errors
Finally
'Always, always, always Release the memory bitmap.
If (sampler IsNot Nothing) Then sampler.Release()
End Try
--
David Rutten
david@mcneel.com
Poprad, Slovakia
Welcome to
Grasshopper
Added by Parametric House 0 Comments 0 Likes
Added by Parametric House 0 Comments 0 Likes
Added by Parametric House 0 Comments 0 Likes
Added by Parametric House 0 Comments 0 Likes
Added by Parametric House 0 Comments 0 Likes
© 2024 Created by Scott Davidson. Powered by