Use Base64 DotNet Image Encoder for buttons with alpha

Is it possible to use Base64 DotNet Image Encoder
in connection with

so that I could encode both - image and alpha and call functions for both images?

logo.images = #((StringToImage img_logo), (StringToImage img_logo_alpha), 1,1,1,1,1 )

for example inside this code (by barigazy)

rollout testRoll "LOGO"
	--if you want to convert image to string see these link:
	local img_logo = "..."--encoded image
	local img_logo_alpha = "..."--encoded image alpha
	local ConvertClass = dotNetClass "System.Convert"
	local ImageClass = dotNetClass "System.Drawing.Image"
	fn StringToImage str = --
		byteArr = ConvertClass.FromBase64String str
		memstream = dotnetobject "System.IO.MemoryStream" byteArr
		DecodedImg = ImageClass.fromstream memstream
		memstream.close() ; return DecodedImg
	dotnetcontrol logo "Label" pos:[0,0] width:100 height:100 
	on testRoll open do (logo.image = (StringToImage img_logo))
createDialog testRoll 100	100 style:#(#style_titlebar, #style_sysmenu, #style_toolwindow)


Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.'s picture


Thx barigazy! You really helped me a lot!'s picture

Look! I've found the solution with alpha

inside on open... I need to use

			logobtn.backcolor = (dotnetclass "System.Drawing.Color").slategray

but what should I put instead of "slategray", in order to detect the color scheme?

barigazy's picture


Don't tell me that you forget to add backcolor:)
If you need max default BG and FG color than you can use this

maxBC = (colorMan.getColor #background) * 255.0
dnColorFG = (dotNetClass "System.Drawing.Color").FromArgb maxBC.x maxBC.y maxBC.z
maxFC = (colorMan.getColor #Text) * 255.0 
dnColorFG = (dotNetClass "System.Drawing.Color").FromArgb maxFC.x maxFC.y maxFC.z

But I prefere this method for custom color

fn defColor r g b = ((dotNetClass "System.Drawing.Color").FromArgb r g b)
dnBC = (defColor 60 60 60)
dnFC = (defColor 200 200 200)
logobtn.backcolor = dnBC --for beckground
logobtn.forecolor = dnFC --for text


barigazy's picture

Also put all your .net

Also put all your .net objects (controls) definition inside function. You can save time a lot.
Example for labeldefinition

	fn defLbl dnLbl txt =
		dnLbl.BackColor = (dotNetClass "System.Drawing.Color").FromArgb maxFC.x maxFC.y maxFC.z
		dnLbl.ForeColor = (dotNetClass "System.Drawing.Color").FromArgb maxBC.x maxBC.y maxBC.z
		dnLbl.Text = txt ; dnLbl.TextAlign = dnLbl.TextAlign.MiddleCenter
dotnetcontrol lblCtrl1 "Label" pos:[2,2] width:100 height:16
dotnetcontrol lblCtrl2 "Label" pos:[2,20] width:100 height:16 
on somerollout open do (defLbl lblCtrl1 "Test Label1"; defLbl lblCtrl2 "Test Label2")

You welcome ;)

barigazy's picture


I get white inside image where I have transparency! I've saved it correctly in png format! I'm sure about that!
may be I need background!

Very interesting about saving to hdd! But I don't understand why, anyway, it's giving the image! Is it about speed?

barigazy's picture

Create a Bitmap containting text from a String

Code by Rafaelo Insanto Steves

   local str = "" --thats the string wich will be put out
   local bmapPath = @"C:\Users\Insanto\Desktop\alphabet.tga" --this path needs to lead to the bitmapFile containing the letters, numbers and signs
   local bMap = openBitmap bmapPath
   local letterArr = #("A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P","Q","R","S","T","U","V","W","X","Y","Z","a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z","0","1","2","3","4","5","6","7","8","9"," ","-","_",".","+","&","#","!",":","?")
   --build the single letters
   local letterBMs = #()
   for l = 1 to str.count do
      local letter = str[l]
      local letterBM = bitmap 11 12
      local startpoint = if letter != "A" then 12 * ((findItem letterArr letter)-1) else 0
      for y = 0 to 11 do
         local ps = getPixels bMap [startpoint,y] 11
         setPixels letterBM [0,y] ps
      letterBMs[l] =  letterBM
   --build the full string from the letters
   local fullWidth = letterBMs.count * 11
   local strBM = bitmap fullWidth (12+2*2) color:white
   for b = 0 to letterBMs.count-1 do
      local startpoint = 11*b
      for y = 0 to 11 do
         local ps = getPixels letterBMs[b+1] [0,y] 11
         setPixels strBM [startpoint,y+2] ps
   display strBM
   letterBMs = undefined  --make sure to leave this line so the gc can remove the letter bitmaps from memory
   close bMap


barigazy's picture

same author

fn string2Bmp str =
         if classOf str == string do
            local pixlRows = filterString str "BR" splitEmptyTokens:false ; pixlRows = for i in pixlRows collect execute i
            local resBMP = bitmap pixlRows[1].count pixlRows.count
            for y = 0 to pixlRows.count-1 do
               setPixels resBMP [0,y] pixlRows[y+1]
            return resBMP
      )--END string2Bmp FN

barigazy's picture


I will try now!!!

barigazy's picture

One more tip

Look at this Pete tool
When you first time run this tool all buttons icons are created and saved on HDD.
This aproch is better (using icons from script folder) then creating them over and over again.
Cool right?


barigazy's picture


One more colored test script. Funny stuff you can learn here


Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.