# How can I get OpenCV CalcHist output to a picturebox? (OpenCVSharp)

**URL:** <https://forum.opencv.org/t/how-can-i-get-opencv-calchist-output-to-a-picturebox-opencvsharp/12196>\
**Category:** Uncategorized\
**Created:** [March 1, 2023, 6:28pm UTC](https://forum.opencv.org/t/how-can-i-get-opencv-calchist-output-to-a-picturebox-opencvsharp/12196 "2023-03-01T18:28:23Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Branden](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.opencv.org/branden/32/7285_2.png) [@Branden](https://forum.opencv.org/u/Branden)\
**Post date:** [March 1, 2023, 6:28pm UTC](https://forum.opencv.org/t/how-can-i-get-opencv-calchist-output-to-a-picturebox-opencvsharp/12196/1 "2023-03-01T18:28:23Z")

</div>

OpenCV seems to streamline their calculated histogram data through their designed Windows Handle. I have produced the images I need, and calculated the data for raw images that I have taken, but I can seem to for the life of me get this output to a picture box.

I have tried numerous things, and I have been going at its since 8am (11:40 now) and while I can use the the Windows handle to take a screenshot of the given rectangle, it ultimately defeats the purpose of using a picture box.

```auto
DllImport("user32.dll")]
public static extern Boolean GetWindowRect(IntPtr hWnd, ref Rectangle bounds);

public Bitmap DrawWindow()
{
    Cv2.NamedWindow("Blue", WindowFlags.Normal);
    Cv2.ResizeWindow("Blue", new SizeCv(256, 128));
    Cv2.ImShow("Blue", _ResultB);
    Bitmap ResultB = OpenCvSharp.Extensions.BitmapConverter.ToBitmap(_ResultB);
    return ResultB;
}

```

Everything is commented. OpenCV offers a GetWindowHandle and also a GetWindowImageRectangle. I have tried both, and yes it does work, but the Window still shows and the Image is produces seems sluggish not to load the correct image.

```auto
[DllImport("user32.dll")]
public static extern Boolean GetWindowRect(IntPtr hWnd, ref Rectangle bounds);

public Bitmap DrawWindow()
{
    Cv2.ImShow("img", _Color);
    Cv2.NamedWindow("Blue", WindowFlags.Normal);
    Cv2.ResizeWindow("Blue", new SizeCv(256, 128));
    Rect rect = Cv2.GetWindowImageRect("Blue");
    Bitmap window = new Bitmap(rect.Width, rect.Height);
    Graphics g = Graphics.FromImage(window);
    Cv2.ImShow("Blue", _ResultB);

    g.CopyFromScreen(rect.X, rect.Y, 0, 0, new System.Drawing.Size(rect.Size.Width,
    rect.Size.Height), CopyPixelOperation.SourceCopy);

    return window;
}

```

![](https://us1.discourse-cdn.com/flex020/uploads/opencv/original/2X/0/02a208f6fc61f0cf736c6cb7edc6a5eda4036224.png)

```auto
https://i.stack.imgur.com/lwYkb.png

```

![](https://us1.discourse-cdn.com/flex020/uploads/opencv/original/2X/8/8fe55cf3a82b1263987784903cdb414f8546f93b.png)

```auto

```
