Upload a screenshot via HTTP POST in jpeg format without saving it on local file system

Hello there,

Is there any possibility to capture an entire desktop screenshot and upload it to a web server via a HTTP POST request?
We can't save the screenshot as a file on the computer, so we need a solution to upload it directly to our web server.

I've tryied the code from http://www.experts-exchange.com/Programming/Editors_IDEs/Q_23604694.html but that function will always return FALSE.

We use the screen capture feature in a windows service, so I can't really debug it to find more details, except LogMessage() function which reveals that BitBlt() function result is FALSE.

Thanks for your time!
Iulian StoianAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Pierre CorneliusCommented:
Perhaps an invalid handle being passed? For desktop the AHandle parameter should be 0.

It seems the BitBlt or StretchBlt is failing. In your call to GetScreenshot use RaiseLastOSError to understand the problem better.
e.g.
if not GetScreenshot(...) then RaiseLastOSError;

Open in new window


Just adding the code referred to in the question below as reference (source: http://www.experts-exchange.com/Programming/Editors_IDEs/Q_23604694.html):
function GetScreenShot(const AHandle: THandle; const CompressPercent: Byte; const ImgSizePercent: byte;  var AImage: TJPEGImage): Boolean;
var
  fBitmap, nBitmap: TBitmap;
  DC: HDC;
  Rect: TRect;
begin
  Result := False;
  if AImage = nil then Exit;
  DC := GetDC(AHandle);
  if DC <> 0 then
  try
    fBitmap := TBitmap.Create;
    try
      if not GetClientRect(AHandle, Rect) then Exit;
      fBitmap.Width := Rect.Right - Rect.Left;
      fBitmap.Height := Rect.Bottom - Rect.Top;
      fBitmap.PixelFormat := pf32bit;
      Result := BitBlt(fBitmap.Canvas.Handle, 0, 0, fBitmap.Width, fBitmap.Height, DC, 0, 0, SRCCOPY);
      nBitmap := TBitmap.Create;
      nBitmap.Width := round(fBitmap.Width*(ImgSizePercent/100));
      nBitmap.Height := round(fBitmap.Height*(ImgSizePercent/100));
      nBitmap.PixelFormat := pf32bit;
      SetStretchBltMode(nBitmap.Canvas.Handle, HALFTONE);
      StretchBlt(nBitmap.Canvas.Handle, 0, 0, nBitmap.Width, nBitmap.Height, fBitmap.Canvas.Handle, 0, 0, fBitmap.Width, fBitmap.Height, SRCCOPY);
      if not Result then Exit;
      AImage.Assign(nBitmap);
      AImage.CompressionQuality:=CompressPercent;
      nBitmap.Free;
    finally
      fBitmap.Free;
     end;
  finally
    ReleaseDC(AHandle, DC);
  end;
end;

Open in new window


I noticed a potential leak in the above code. nBitmap is created but potentially not freed, wrap in try finally as follows:
nBitmap := TBitmap.Create;
try
      nBitmap.Width := round(fBitmap.Width*(ImgSizePercent/100));
      nBitmap.Height := round(fBitmap.Height*(ImgSizePercent/100));
      nBitmap.PixelFormat := pf32bit;
      SetStretchBltMode(nBitmap.Canvas.Handle, HALFTONE);
      StretchBlt(nBitmap.Canvas.Handle, 0, 0, nBitmap.Width, nBitmap.Height, fBitmap.Canvas.Handle, 0, 0, fBitmap.Width, fBitmap.Height, SRCCOPY);
      if not Result then Exit;
      AImage.Assign(nBitmap);
      AImage.CompressionQuality:=CompressPercent;
finally
      nBitmap.Free;
end;

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Software

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.