I am writing an application, it should save the photo in a blob-field, but this will be the next step, and now I want to get a snapshot at least as a .jpg file. But somehow I get .bmp, but I can’t .jpg, I just create a file with 0 (zero) bytes.
Button code save photos from the camera:

procedure TForm1.Button14Click(Sender: TObject); var jpgImg: TJPEGImage; begin hWndC := capCreateCaptureWindowA('My Own Capture Window', WS_CHILD or WS_VISIBLE, Image1.Left, Image1.Top, Image1.Width, Image1.Height, Form1.Handle, 0); if hWndC <> 0 then SendMessage(hWndC, WM_CAP_DRIVER_CONNECT, 0, 0); //"подключаемся" к веб-камере jpgImg := TJPEGImage.Create; jpgImg.Assign(image1.Picture.Bitmap); jpgImg.SaveToFile(ExtractFilePath(Application.ExeName)+'\tmp_0001.jpg'); jpgImg.Free; SendMessage(hWndC, WM_CAP_DRIVER_DISCONNECT, 0, 0); //"отключаемся" от веб-камеры hWndC := 0; end; 

The uses JPEG connected.
What could be wrong?

  • one
    jpgImg.Assign(image1.Picture.Bitmap); Well, where in the Image1.Picture.Bitmap itself is something written? - kami
  • 2
    What makes you think that bmp get? Do you save it to a file? It is believed that the camera driver draws its picture over the window, the handle of which it received, but not in Image1. - kot-da-vinci
  • @kami tried with BMP - it is recorded there. I think the problem is in jpgImg.Assign(image1.Picture.Bitmap) - I_CaR

1 answer 1

It is necessary to transfer not Form1.Handle , but something like Image1.Canvas.Handle . In your code, everything is drawn on the outline of the form, while the Image itself remains empty and transparent, so you can see everything under it.

Upd. According to the comment kot-da-vinci: Most likely, drawing a picture from the camera is really on top of your window. In this case, even capturing the canvas of the form will do nothing, because de facto is drawn on a separate window using a hardware overlay. In this case, BitBlt can help you with the CAPTUREBLT flag. With one limitation: CaptureBlt slows down the overlay quite a lot (at least it was like this in the days of Windows XP).

  • Indeed, something is not all. Made Image1.Canvas.Handle now comes white picture. - I_CaR
  • @I_CaR the most important thing in my answer is the addition to the comment kot-da-vinci. Did you use BitBlt with the specified flag? - kami