Exemplo n.º 1
0
def captureScreenshot(filename):
    format = Drawing.Imaging.ImageFormat.Gif
    bounds = Forms.Screen.GetBounds(Drawing.Point.Empty)
    with Drawing.Bitmap(bounds.Width, bounds.Height) as bitmap:
        with Drawing.Graphics.FromImage(bitmap) as gr:
            gr.CopyFromScreen(Drawing.Point.Empty, Drawing.Point.Empty,
                              bounds.Size)
        bitmap.Save(filename, format)
Exemplo n.º 2
0
def load_image():
    filter = "BMP (*.bmp)|*.bmp|PNG (*.png)|*.png|JPG (*.jpg)|*.jpg|All (*.*)|*.*||"
    #filter = "PNG (*.png)|*.png"
    filename = rs.OpenFileName("Select image file", filter)

    if not filename: return

    # use the System.Drawing.Bitmap class described at
    # [url]http://msdn.microsoft.com/en-us/library/system.drawing.bitmap.aspx[/url]
    img = SD.Bitmap(filename)

    w = img.Width
    h = img.Height

    red = []
    green = []
    blue = []
    colourTuple = []
    sumR = 0
    sumG = 0
    sumB = 0
    N = 0
    for x in range(w):
        for y in range(h):
            color = img.GetPixel(x, y)
            r = rs.ColorRedValue(color)
            g = rs.ColorGreenValue(color)
            b = rs.ColorBlueValue(color)
            red.append(r)
            green.append(g)
            blue.append(b)
            N += N
    for item in red:
        sumR += item
    colourTuple.append(sumR / len(red))
    for item in green:
        sumG += item
    colourTuple.append(sumG / len(green))
    for item in blue:
        sumB += item
    colourTuple.append(sumB / len(blue))

    print(colourTuple)
    return colourTuple, filename
Exemplo n.º 3
0
def PictureframeOnScale():
    filter = "PNG (*.png)|*.png|JPG (*.jpg)|*.jpg|BMP (*.bmp)|*.bmp|All (*.*)|*.*||"
    #filter = "PNG (*.png)|*.png"
    filename = rs.OpenFileName("Select existing image file", filter)
    if not filename: return
    # use the System.Drawing.Bitmap class described at
    # [url]http://msdn.microsoft.com/en-us/library/system.drawing.bitmap.aspx[/url]
    img = SD.Bitmap(filename)
    img.Dispose
    # define scale from inch to file unitsystem
    dblScale = rs.UnitScale(rs.UnitSystem(), 8)

    #calculate width based on image pixel dimension and image HorizontalResolution
    w = str((img.Width / img.HorizontalResolution) * dblScale)

    #release the image (not sure if this is correct but seems to work)

    # scripted rhino command pictureframe with width and height as calculated above
    rs.Command("!_-PictureFrame \"" + filename + "\" _Pause " + w + " ")
Exemplo n.º 4
0
def get_facereader_rep(filename):

    FR.GrabCredits(1)
    bitmap = Drawing.Bitmap(filename)
    try:
        result = (FR.AnalyzeFace(bitmap))
        result = json.loads(result.ToJson())
    except:
        return "error"

    if isinstance(result, Mapping):
        if result['FaceAnalyzed']:
            landmarks = []
            landmarks_dict = result['Landmarks3D']
            for item in landmarks_dict:
                landmarks.append([item['X'], item['Y'], item['Z']])
            landmarks = np.array(landmarks)
            return landmarks
        else:
            # no face found
            return "no face found"
Exemplo n.º 5
0
    plane = 0
if plane > 2:
    plane = 2
if not level:
    level = 0

nyz = ny * nz
dims = [nz, ny, nx]
if level >= dims[plane]:
    level = dims[plane] - 1

mx = max(vals)
mn = min(vals)

if plane == 0:
    bmp = drw.Bitmap(nx, ny)
    for x in range(nx):
        for y in range(ny):
            v = vals[get_index(x, y, level)]
            bmp.SetPixel(x, ny - 1 - y, get_color(v))
elif plane == 1:
    bmp = drw.Bitmap(nx, nz)
    for x in range(nx):
        for y in range(nz):
            v = vals[get_index(x, level, y)]
            bmp.SetPixel(x, nz - 1 - y, get_color(v))
elif plane == 2:
    bmp = drw.Bitmap(ny, nz)
    for x in range(ny):
        for y in range(nz):
            v = vals[get_index(level, x, y)]
    try:
        for x in range(aBitmap.Width // resolution):
            for y in range(aBitmap.Height // resolution):
                aColour = aBitmap.GetPixel(x * resolution, y * resolution)
                if (aColour.A >
                        128):  #  Make a panel for non-transparent pixels only
                    aPanel = gh.Kernel.Special.GH_Panel()
                    aPanel.NickName = NICKNAME
                    aPanel.UserText = ""
                    aPanel.Properties.Colour = aColour
                    aPanel.Properties.Font = sd.Font("Trebuchet MS", 4)
                    aPanel.Properties.Multiline = False
                    theDoc.AddObject(aPanel, False, theDoc.ObjectCount + 1)
                    aPanel.Attributes.Pivot = sd.PointF(
                        x * x_spacing, y * y_spacing)
                    aPanel.Attributes.Bounds = sd.RectangleF(
                        0, 0, x_spacing, y_spacing)
    except Exception, ex:
        ghenv.Component.AddRuntimeMessage(
            Grasshopper.Kernel.GH_RuntimeMessageLevel.Warning, str(ex))


try:
    theBitmap = sd.Bitmap(imagePath)
    remove_old()
    print "Creating {:d}x{:d} Image".format(theBitmap.Width, theBitmap.Height)
    make_new(theBitmap, xSpacing, ySpacing, Resolution)
except Exception, ex:
    ghenv.Component.AddRuntimeMessage(
        Grasshopper.Kernel.GH_RuntimeMessageLevel.Warning, str(ex))