PDA

View Full Version : Set Pixel "ImageList"


MerlinEl
04-02-2012, 11:49 AM
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]"

lo
04-02-2012, 12:30 PM
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).

MerlinEl
04-02-2012, 12:41 PM
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...

lo
04-02-2012, 01:02 PM
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

MerlinEl
04-02-2012, 02:09 PM
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

nop, im tried again and did not works....

denisT
04-02-2012, 02:15 PM
did you try
imagesList.images.get_item i
imagesList.images.set_item i
?

MerlinEl
04-02-2012, 02:23 PM
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....

lo
04-02-2012, 02:27 PM
did you try
imagesList.images.get_item i
imagesList.images.set_item i
?

yeah those work!

lo
04-02-2012, 02:29 PM
I'm tried to change color of one part in table , lv.backColor =
but this will change whole line.


http://msdn.microsoft.com/en-us/library/system.windows.forms.listviewitem.useitemstyleforsubitems.aspx

MerlinEl
04-02-2012, 02:41 PM
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 :-D

lo
04-02-2012, 02:43 PM
Look at the link I posted, you don't need imagelist at all.

MerlinEl
04-02-2012, 02:53 PM
Look at the link I posted, you don't need imagelist at all.


Nice Lo, :beer: that's great!

denisT
04-02-2012, 03:21 PM
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


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 .get_<property> asdotnetobject:on function.
you can search this forum for a sample (NumericUpDown control and the getting its float value).

MerlinEl
04-02-2012, 03:58 PM
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 .get_<property> asdotnetobject:on 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 :thumbsup:
Have a nice day :)

CGTalk Moderation
04-02-2012, 03:58 PM
This thread has been automatically closed as it remained inactive for 12 months. If you wish to continue the discussion, please create a new thread in the appropriate forum.