ScriptSpot home

Forum topic · General Scripting

Use Base64 DotNet Image Encoder for buttons with alpha

By artrender · 2013-03-16

Description

Is it possible to use Base64 DotNet Image Encoder http://lonerobot.net/?p=314
in connection with http://www.scriptspot.com/3ds-max/tutorials/maxscript-image-button-bmp-l…

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: http://www.scriptspot.com/3ds-max/scripts/base64-dotnet-image-encoder
	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 = -- http://lonerobot.net/
	(
		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)
)
Comments (19)
artrender

hmmm

Thx barigazy! You really helped me a lot!

artrender

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?

Reply to artrender
Branko Živković

:)

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)
--e.i
logobtn.backcolor = dnBC --for beckground
logobtn.forecolor = dnFC --for text

Reply to Branko Živković
Branko Živković

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 
--etc.
on somerollout open do (defLbl lblCtrl1 "Test Label1"; defLbl lblCtrl2 "Test Label2")

You welcome ;)

artrender

STRANGE

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?

Reply to artrender
Branko Živković

Create a Bitmap containting text from a String

Code by Rafaelo Insanto Steves

(
local str = "SomeFileName.ms" --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
)

Reply to Branko Živković
Branko Živković

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

artrender

THANK YOU SO MUCH!

I will try now!!!

artrender

I know about them inside MICROSOFT WORD

but they don't have all signs that I need. Some of them I draw in PHOTOSHOP

artrender

except this I can't make it work like a simple button

if I use


dotnetcontrol insertbtn "Label" pos:[647,102] width:16 height:16 border:false

then it does not animate like a button

if I use


dotNetControl insertbtn "Button" pos:[647,102] width:16 height:16 border:false

or
dotNetControl insertbtn "System.Windows.Forms.Button" pos:[647,102] width:16 height:16 border:false

then I get this ugly border, but it's animating

Reply to artrender
Branko Živković

Use label and for hilighting you can use "MouseHover" and "MouseLeave" events wher you can change contrlol "backcolor"

Branko Živković

I avoid using the bitmaps in my scripts. Are you hear about symbolic systems
fonts like "Wingdings" and "Webdings"?
It'smuch fester and beter to use theses as fontstyle then bitmaps

artrender

yes I know

It works wonderfull. but how to make it work for both - image and alpha! This is the first situation! The second is that when I want to use it for buttons


dotNetControl insertbtn "System.Windows.Forms.Button" pos:[647,102] width:20 height:20 border:false
....

insertbtn.image = (StringToImage img_insert)

I get an ugly border! - http://www.scriptspot.com/files/ugly_button.jpg

but I need smth like this http://www.scriptspot.com/files/needed.jpg

Attachments
Reply to artrender
Branko Živković

Yep to convert *.png image to string using Pete's tool.
He put his logo at the top of script (little robot) as *.png If you have not noticed.

Branko Živković

:)

this is mine earlier test using same Pete "LoneRobot" method

Attachments