Base64 image in a windows form using Dynamo?

Anyone know if it’s possible to embed a base64 image into a windows form using Dynamo 2.6.1.

I tried so many ways and got nothing but errors.

(I gave up and used a linked image instead).

But I was wondering if it’s even possible.

Might be a solution here:

1 Like

Definitely the solution; the hard part is implementing it in the context of the environment (as usual). :slight_smile:

2 Likes

That’s image from file… As I said, that’s what I ended up doing.

I want to embed a base64 image into the code though…

Am wondering if that is possible.

I had no issue putting a picture or a gif (which was fun) from my harddrive, or the internet
in a pop up window.

Hi @Alien

you have an example in this post (with base64)

2 Likes

Here are some of my failed examples:

import clr
clr.AddReference("System.Windows.Forms")
clr.AddReference("System.Drawing")

from System import Convert
from System.IO import MemoryStream
from System.Drawing import Image, Bitmap
from System.Windows.Forms import Application, Form, PictureBox, DockStyle

class CreateWindow(Form):
	def __init__(self):
		self.Name = "Create Window"
		self.Text = "Base64 Image"
		self.Width = 400
		self.Height = 400
		
		# Base64 encoded image
		base64_image = 'I PUT THE BASE 64 CODE HERE BUT DON'T WANT TO TOTALLY SPAM THIS POST'

form = CreateWindow()
Application.Run(form)

I got a blank pop up for the code above.

================================

import clr
clr.AddReference("System.Windows.Forms")
clr.AddReference("System.Drawing")
import System
from System.Windows.Forms import *
from System.Drawing import *
import base64
import io

# Create a form
form = Form()
form.Text = "This is a popup"
form.Width = 500
form.Height = 500

# Create a picture box
picBox = PictureBox()
picBox.SizeMode = PictureBoxSizeMode.StretchImage
picBox.Width = 300
picBox.Height = 300
picBox.Location = System.Drawing.Point(100, 100)

base64_image = 'BASE64 CODE WAS HERE'
image_bytes = base64.b64decode(base64_image)
image_stream = io.BytesIO(image_bytes)
image = System.Drawing.Image.FromStream(image_stream)

# set the image in the PictureBox
picture_box.Image = image
picBox.Image = image
form.Controls.Add(picBox)

# Show the form
form.ShowDialog()

This one gave me TypeError: expected Stream, got BytesIO

Thanks. I got there eventually with the help of your code…
But a URL is so, so much easier!

1 Like