PDA

View Full Version : colorpick from bitmap?


OutOfInspiration
06-11-2010, 02:36 PM
hey,

is it possible to pick colors from a bitmap? don't find anything about it.
I want to create a custom smaller color picker

so like if you do a mouse down on a bitmap it gives the colorcode of the current pixel the mouse is on....

thanks!

Bobo
06-11-2010, 03:34 PM
hey,

is it possible to pick colors from a bitmap? don't find anything about it.
I want to create a custom smaller color picker

so like if you do a mouse down on a bitmap it gives the colorcode of the current pixel the mouse is on....

thanks!

You can do this with an ImgTag which is a bitmap display control that has its own mouse event handlers. Alternatively, you can use the mouse event handlers of a rollout displayed as a dialog and get the position and button clicks from the rollout itself.

But it is definitely possible to get the mouse cursor's position within the control, then you will have to get the pixel using getPixels() yourself.

Bobo
06-11-2010, 03:44 PM
Here is a quick test:


rollout ccp_test "Custom Color Picker Test"
(
local theMap = gradient_ramp gradient_Type:8
local theBmp = (renderMap theMap)
imgtag img_display width:200 height:200 bitmap:theBmp
colorpicker clr_picker
label lbl_pos
on img_display lbuttondown thePos theFlags do
(
theColor = getPixels theBmp thePos 1
lbl_pos.text = thePos as string + " : " + theColor[1] as string
clr_picker.color = theColor[1]
)
)
createDialog ccp_test 250 260

OutOfInspiration
06-11-2010, 04:18 PM
thanks bobo,
it helped me to get going.

but i'm having problems with loading external bitmaps in a bitmap

so it s the same code that you hav, only i'm using a custom bitmap and load it in using "filename" parameter.
but the result of the bitmap stays gray and the color picker keeps giving me a color 0 0 0.

Any ideas how i need to load the bitmap in?

thanks


rollout ccp_test "Custom Color Picker Test"
(

local bm = bitmap 200 200 filename:"$scripts\\PolyPainter\\ColorRange.bmp"
imgtag img_display width:200 height:200 bitmap:bm
colorpicker clr_picker
label lbl_pos
on img_display lbuttondown thePos theFlags do
(
theColor = getPixels bm thePos 1
lbl_pos.text = thePos as string + " : " + theColor[1] as string
clr_picker.color = theColor[1]
)
)
createDialog ccp_test 250 260

Bobo
06-11-2010, 05:46 PM
Creating a bitmap with a filename does NOT open the existing bitmap, it creates a NEW empty bitmap that would overwrite your existing one if you would call SAVE on it!

You have to use the OpenBitmap() method to read a bitmap from disk.

Bitmap Values

openBitMap <filename_string>

Returns a bitmap value containing the contents of the specified bitmap file. The bitmap value returned is a load-only bitmap.

CGTalk Moderation
06-11-2010, 05:46 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.