[Closed] Set Pixel "ImageList"
Hi
Is posible to change color of an item in (dotNetObject “ImageList”).?
Here is what I’m tryed but, after success set pixels ,nothing changes:
fn createImage w:24 h:24 clr:white transparent:false =
(
local img = (dotNetObject "Drawing.Bitmap" w h)
local g = (dotNetClass "Drawing.Graphics").fromImage img
local brush = dotNetObject "drawing.SolidBrush" (netDrColor clr)
g.FillRectangle brush 0 0 w h
g.dispose()
if transparent do img.makeTransparent()
img
)
fn netDrColor clr = ((dotNetClass "Drawing.Color").fromArgb clr.r clr.g clr.b)
--create new image list
img_list = dotNetObject "ImageList"
img_list.Images.count -- ==0
--add image
new_img = createImage w:32 h:20 clr:red
img_list.Images.add new_img
img_list.Images.count -- ==1
--check bitmap color
(img_list.Images.item[0].getPixel 1 1).toString()
--"Color [A=255, R=0, G=0, B=255]"
--repaint
img_list.Images.item[0].SetPixel 1 1 (netDrColor blue)
--check bitmap color
(img_list.Images.item[0].getPixel 1 1).toString()
--"Color [A=255, R=0, G=0, B=255]"
Funny, it seems that images.item[0] returns a copy of the bitmap:
a = img_list.images.item[0]
a == img_list.images.item[0] --false
you can return the copy back to the list using list methods (remove, insert).
Hi Lo
Thanks for you quick answer
I’m searched in the code ,and I found only .RemoveAt.
The insert function is not there…
Hmm you’re right the insert method is not implemented in imageCollection (which is the type of imageList.images).
One workaround is to use keys instead of indices, even keys which are string representation of indices
for example: imageList.images.add “1” new_img
did you try
imagesList.images.get_item i
imagesList.images.set_item i
?
Hi Denis
Yes Yes , this way Works perfect! Magnificent :applause:
By the way where did you find those two commands, those are not in properties? :surprised
--create new image list
img_list = dotNetObject "ImageList"
--add image
new_img = createImage w:32 h:20 clr:yellow
img_list.Images.add new_img
--check bitmap color
(img_list.Images.item[0].getPixel 1 1).toString()
--"Color [A=255, R=255, G=255, B=0]"
new_img = createImage w:32 h:20 clr:red
img_list.Images.set_item 0 new_img
(img_list.Images.item[0].getPixel 1 1).toString()
Thank you Denis and Lo, finaly i can continue on max script color theme editor
it’s a feature of the max dotnet system. You can get/set any dotnet object parameter using function get(or set)<property>. if it is indexed parameter you have to add index.
max is doing automatic value conversion from dotnet value to mxs. So it can’t return all the time instance of the object. Why in some situations it returns an instance but in another a copy, I HAVE NO IDEA.
but you always can get an instance using[b] .get<property> asdotnetobject:on[/b] function.
you can search this forum for a sample (NumericUpDown control and the getting its float value).
Thanks for explanation Denis
This si a valuable information and make work much more easiest.
I’m always glad to chat with you guys
Have a nice day
I will explain lite bit more about this tool.
I have a dotNetControl “listView” table divided in two parts:
one for colors
and
one fot the text
I’m tried to change color of one part in table , lv.backColor =
but this will change whole line.
Then im use method lv.SmallImageList = getImageList() and setup each part of table with
itm.ImageIndex =
Now I’m need to change these colors dynamicaly and I can’t find way to repain or replace selected field in table.
Only with clear() and refilling whole table. Thats wery slow…