M
Hallo,
das Problem ist gelöst. Der folgende Code kann das Preview-Fenster wahlweise mit Zoomfaktor 1x, 2x oder "Fit to Window" darstellen, wobei bei Bedarf Scrollbars verwendet werden:
public struct BITMAPINFOHEADER
{
public uint biSize;
public int biWidth;
public int biHeight;
public ushort biPlanes;
public ushort biBitCount;
public uint biCompression;
public uint biSizeImage;
public int biXPelsPerMeter;
public int biYPelsPerMeter;
public uint biClrUsed;
public uint biClrImportant;
}
[System.Runtime.InteropServices.StructLayout(System.Runtime.InteropServices.LayoutKind.Sequential)]
public struct BITMAPINFO
{
public BITMAPINFOHEADER bmiHeader;
public int bmiColors;
}
[DllImport("user32")]
private static extern bool SendMessage(int hWnd, int wMsg, int wParam, ref BITMAPINFO lParam);
private void previewSize()
{
BITMAPINFO buffer = new BITMAPINFO();
SendMessage(_hHwnd, WM_CAP_GET_VIDEOFORMAT, Marshal.SizeOf(buffer), ref buffer);
if (radioButton1.Checked)
{
SendMessage(_hHwnd, WM_CAP_SET_SCALE, 0, 0); // Zoom 1x
pictureBox1.Width = buffer.bmiHeader.biWidth;
pictureBox1.Height = buffer.bmiHeader.biHeight;
}
if (radioButton2.Checked)
{
SendMessage(_hHwnd, WM_CAP_SET_SCALE, 1, 0); // Zoom 2x
pictureBox1.Width = 2 * buffer.bmiHeader.biWidth;
pictureBox1.Height = 2 * buffer.bmiHeader.biHeight;
}
if (radioButton3.Checked)
{
SendMessage(_hHwnd, WM_CAP_SET_SCALE, 1, 0); // Fit to Window
pictureBox1.Width = panel1.Width;
pictureBox1.Height = panel1.Height;
}
SetWindowPos(_hHwnd, HWND_BOTTOM, 0, 0, pictureBox1.Width, pictureBox1.Height, SWP_NOMOVE | SWP_NOZORDER);
}
private void OpenPreviewWindow()
{
iDevice = comboBox1.Text;
_hHwnd = capCreateCaptureWindow(iDevice, WS_VISIBLE | WS_CHILD, 0, 0, pictureBox1.Width, pictureBox1.Height, pictureBox1.Handle.ToInt32(), 0);
if (SendMessage(_hHwnd, WM_CAP_DRIVER_CONNECT, 0, 0) != 0)
{
SendMessage(_hHwnd, WM_CAP_SET_PREVIEWRATE, 40, 0);
SendMessage(_hHwnd, WM_CAP_SET_PREVIEW, 1, 0);
previewSize();
}
else
{
DestroyWindow(_hHwnd);
}
}
private void button4_Click(object sender, EventArgs e)
{
SendMessage(_hHwnd, WM_CAP_DLG_VIDEOFORMAT, 0, 0);
previewSize();
}
private void radioButton1_CheckedChanged(object sender, EventArgs e)
{
previewSize();
}
private void radioButton2_CheckedChanged(object sender, EventArgs e)
{
previewSize();
}
private void radioButton3_CheckedChanged(object sender, EventArgs e)
{
previewSize();
}