how to pick pixel colour from picture GTK 3 - c

I have image in pixbuf and viewed in GtkImage widget, Need Get pixel coordinates from cursor position and get that pixel value from the pixbuf.
user will move mouse over the image and pick any colour from that picture, i dont know what to use or best approach to pick colour from picture displayed in window

Related

Mapbox Get Point Raster Layer Color

I want to display a legend slider besides the map to show the color of the custom raster layer, of the hovered territory. Therefore, I need to get the layer pixel color where the cursor is.
I have found a solution to get the color of a pixel on the map How to get the color of pixels on mapbox, however, if we hover roads or names, another color gets read.
Is there a way to read the layer color on a specific map point?
Are the roads and place labels baked into the raster, or overlaid as vector data sourced layers?
I'm not sure of another method besides querying the canvas, in which case one option would be to hide the vector layers, query, then reshow. But that may not result in the interaction you want?

How can you use an ImageBrush to display a specified area of an image as the background of a rectangle?

I'm trying to add a zoom feature for an image viewer control I'm creating. When viewing the image, holding down the left mouse button brings up a rounded rectangle that is zoomed into the image. I figure I can use An ImageBrush as the background but I can't figure out how to make it just display a specified area of the image. Can this even be done?
By using the Viewbox.

Panning the display area in WPF

The application will have a menu strip on top and the rest will display lines and shapes. I want to be able to drag and pan the main display area by clicking it and dragging it in any direction.
I am currently drawing items using pixel values (for example a line drawn from (1042,54)to(1240,104). But I think a monitor with a smaller resolution will not be able to display that object. That is why I want to be able to pan the display area.
The lines and shapes are currently being drawn on a gird that I placed inside the window.
If you place the canvas inside a ScrollViewer then if the canvas is larger than the application window it will be displayed with scroll bars.
You can then address points on the canvas with values relative to the canvas rather than the screen.

Getting position of rendered image inside Image control

I have an Image control with Stretch==Uniform which means larger images will be scaled down. In my case the Image control fills the whole client space, the scaled down image is being displayed centered inside the control. What now will happen: the size of the rendered image and the Image control do not have the same size - the Image control is usually larger than its content (since I use uniform stretching).
I now need to know the position of the actual image inside the Image control. Some background: the user can place a rectangle on the image to crop it. To match the rectangle with the image coordinates I need to know exactly where the image is.
Is there a way to determine the position of the rendered image inside the Image control? Or is the only solution to make the control the same size as the image content?
To get more control, you might want to put the image on a canvas inside a viewbox.
That way you get pixel control via the canvas, but a scaled view via the outer viewbox. Set the canvas dimensions to match the image and add any decorations to the canvas.
You may need to inverse-scale the rectangle stroke width so that it is visible when the canvas is small.

WPF Cursor on a partially transparent image

I have a png that contains transparent regions and I set it to the image tag.
How am I able to set the cursor to a hand when it is over an opaque part of the image?
Thanks
To do this you will need to look at the bitmap itself. WPF's hit testing mechanism considers any pixel painted ith a "transparent" brush to still be clickable even though invisible. This is normally a good thing but gets in the way of what you're trying to do. Because a .png paints with the transparent brush, the entire .png is considerd as painted when doing hit testing.
What you need to do in your MouseMove event handler is:
Go ahead and invoke hit testing the normal way.
For each HitTestResult you get back, check to see if it is an Image and if so, whether a transparent pixel is under the mouse
When you get a hit on a non-image or a non-transparent pixel of an image, stop.
Decide on a Cursor value based on what the mouse is over
To determine whether a the mouse is over a transparent pixel of an image:
Get the mouse position relative to the image (e.GetPosition(image))
If you're using stretching you must back-compute the stretch at this point to get a bitmap index
Use BitmapSource.CopyPixels to copy a 1-pixel rectangle into an array (ie. only the single pixel the mouse is over)
Check the pixel value that was retrieved to see if it is a transparent pixel

Resources