Aurigma Forums
»
Graphics Mill
»
Discussions – Graphics Mill
»
Getting a pixel color from a zoomed Bitmapviewer
Rank: Member
Groups: Member
Joined: 5/24/2007(UTC) Posts: 3
|
Hi,
I am using a BitmapViewer with a ZoomInNavigator to zoom in on a bitmap. I followed the example for creating a color picker navigator, but it does not correctly get the color of the zoomed in pixels. I want to be able to let the user zoom into a bitmap and use the color picker to pick up the color of a zoomed in pixel. Please help! Thanks!
GP
|
|
|
|
Rank: Advanced Member
Groups: Member
Joined: 1/31/2005(UTC) Posts: 458
Was thanked: 5 time(s) in 5 post(s)
|
Hello, Unfortunately there is a problem with the sample. We will fix it in the next release of GraphicsMill 4.0 for .NET. Here is working code of the color picker navigator: Code:public class ColorPickerNavigator : UserInputController, INavigator
{
public ColorPickerNavigator()
{
//The cursor file should be an embedded resource to be called this way.
_cursor = new System.Windows.Forms.Cursor(GetType(), "ColorPicker.cur");
}
public override void Connect(ViewerBase viewer)
{
base.Connect (viewer);
base.Viewer.WorkspaceMouseDown += new Aurigma.GraphicsMill.WinControls.MouseEventHandler(OnWorkspaceMouseDown);
}
public override void Disconnect()
{
base.Disconnect ();
base.Viewer.WorkspaceMouseDown -= new Aurigma.GraphicsMill.WinControls.MouseEventHandler(OnWorkspaceMouseDown);
}
private void OnWorkspaceMouseDown(object sender, Aurigma.GraphicsMill.WinControls.MouseEventArgs e)
{
if (IsViewerAttached && ViewerHasContent)
{
BitmapViewer bitmapViewer = (BitmapViewer)Viewer;
//Retrieve the pixel color value.
int x = System.Math.Max(0, System.Math.Min((int)e.X, bitmapViewer.Bitmap.Width - 1));
int y = System.Math.Max(0, System.Math.Min((int)e.Y, bitmapViewer.Bitmap.Height - 1));
Color color = bitmapViewer.Bitmap.GetPixel(x, y);
//The RGB channel values will be displayed, so we convert the colorspace
//to RGB if needed.
if (color.ColorSpace != ColorSpace.Rgb)
color.ConvertColorSpace(ColorSpace.Rgb);
//...Do something to the color values...
//For example, read the channel values into a text string and copy
//it to the clipboard.
string text = String.Format("R: {0} G: {1} B: {2}",
color.GetChannel32(ColorChannel.Red),
color.GetChannel32(ColorChannel.Green),
color.GetChannel32(ColorChannel.Blue));
System.Windows.Forms.Clipboard.SetDataObject(text, true);
}
}
protected override void UpdateCursor(bool isCursorDefault, System.Drawing.Point point)
{
//Display this navigator cursor.
if (isCursorDefault)
{
Viewer.RestoreCursorToDefault();
return;
}
Viewer.Cursor = _cursor;
}
private System.Windows.Forms.Cursor _cursor;
}
Edited by user Tuesday, December 18, 2007 3:30:09 AM(UTC)
| Reason: Not specified |
|
|
|
|
Rank: Member
Groups: Member
Joined: 5/24/2007(UTC) Posts: 3
|
Thank you very much! It works perfectly! :D
|
|
|
|
Aurigma Forums
»
Graphics Mill
»
Discussions – Graphics Mill
»
Getting a pixel color from a zoomed Bitmapviewer
Forum Jump
You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.