0
Microsoft lifecam에서 피드를 표시 할 수있는 창을 만드는 동안 문제가 발생했습니다. 기본적으로 하나 이상의 스크린 샷을 찍을 수 있지만 코드를 스레드 안에 넣으면 (API를 사용하지 않고 실시간으로 피드를 표시 할 수 있습니다.) API가 실패하여 발견 된 장치가 없습니다.Microsoft LifeCam ESCAPI - 작업 내부가 아닌 UI에서 작업 중
C++ CLI :
EasyPicture::EasyPicture()
{
int devices = setupESCAPI(); //returns 1 if run synchronously, 0 otherwise
_apiInitialized = devices > 0;
std::cout << (_apiInitialized ? "Escapi initialized successfully!\n" : "Failed to init escapi.\n");
_capture = new struct SimpleCapParams();
}
bool EasyPicture::GetFrame(void* buffer, int width, int height)
{
if (!_apiInitialized || buffer == nullptr || width == 0 || height == 0)
return false;
pin_ptr<int> buffPtr = reinterpret_cast<int*>(buffer);
_capture->mTargetBuf = buffPtr;
_captureInitialized = _capture->mWidth == width && _capture->mHeight == height;
_capture->mWidth = width;
_capture->mHeight = height;
if (!_captureInitialized)
{
//works if run synchronously, otherwise returns 0 (failed)
if (initCapture(0, _capture) == 0) //Maybe the device is already in use
{
if (Disconnect()) // try to disconnect it
{
if (initCapture(0, _capture) == 0)
{
_captureInitialized = false;
return false;
}
_captureInitialized = true;
}
else
{
_captureInitialized = false;
return false;
}
}
}
doCapture(0);
while (isCaptureDone(0) == 0)
{
/* Wait until capture is done. */
}
return true;
}
C# 코드
private void UserControl_Loaded(object sender, RoutedEventArgs e)
{
_cts = new CancellationTokenSource();
_frameLoop = new Task(() =>
{
Frame = new Bitmap(_width, _height, System.Drawing.Imaging.PixelFormat.Format32bppArgb);
var BoundsRect = new System.Drawing.Rectangle(0, 0, _width, _height);
BitmapData bmpData = Frame.LockBits(BoundsRect, ImageLockMode.WriteOnly, Frame.PixelFormat);
int counter = 0;
while(!_cts.IsCancellationRequested)
{
unsafe
{
if (!_picHelper.GetFrame((void*)bmpData.Scan0, _width, _height))
{
}
else
{
Frame.Save("Test_" + counter + ".bmp"); //For now i just save the frame, i have yet to figure out how to put the bitmap in xaml without copying it...
/* Image = System.Windows.Interop.Imaging.CreateBitmapSourceFromHBitmap(
Frame.GetHbitmap(),
IntPtr.Zero,
System.Windows.Int32Rect.Empty,
BitmapSizeOptions.FromWidthAndHeight(_width, _height));*/
}
}
Thread.Sleep(500);
}
Frame.UnlockBits(bmpData);
},_cts.Token);
_frameLoop.RunSynchronously();// Start(); Works only with RunSynchronously, but blocks ui of course
}
사람이 올바른 방향으로 날 포인트 여기 코드는?