Quantcast
Channel: Scripting - McNeel Forum
Viewing all articles
Browse latest Browse all 5791

Help, fast image manipulation

$
0
0

@Holo wrote:

Hi guys, I am struggeling with a slow image manipluation as reading and writing each pixel take a long time.

This script gets the viewport image and sets all RED values to 255, but it takes like 5 seconds to recalculate a 1000x500 pixel viewport.

import scriptcontext
import System
import rhinoscriptsyntax as rs

# Capture the active view to a System.Drawing.Bitmap
bitmap = scriptcontext.doc.Views.ActiveView.CaptureToBitmap()

### --- modify bitmap
### --- make new bitmap
format = System.Drawing.Imaging.PixelFormat.Format32bppRgb
Width= bitmap.Size.Width
Height=bitmap.Size.Height

print Width,str("x"),Height, str("pixels.  Total = "), Width*Height

bitmapNew = System.Drawing.Bitmap(Width, Height, format)

for iW in range(Width):
    for iH in range(Height):
        pixel=System.Drawing.Bitmap.GetPixel(bitmap,iW,iH)
        RGB = (255, pixel.G, pixel.B)
        color = rs.CreateColor(RGB)
        System.Drawing.Bitmap.SetPixel(bitmapNew, iW,iH, color)

Is there anything I can easily do to speed this up?

Posts: 2

Participants: 2

Read full topic


Viewing all articles
Browse latest Browse all 5791

Trending Articles