Notifications
Clear all

[Closed] colorpick from bitmap?

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!

4 Replies
1 Reply
(@bobo)
Joined: 11 months ago

Posts: 0

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.

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

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

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[left]
[/left]

[left]openBitMap <filename_string>
[/left]
[left]Returns a bitmap value containing the contents of the specified bitmap file. The bitmap value returned is a load-only bitmap.
[/left]

[left]
[/left]