Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

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

Posted on 2014-09-02
1
Medium Priority
?
291 Views
Last Modified: 2014-09-12
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!
0
Comment
Question by:Iulian Stoian
1 Comment
 
LVL 14

Accepted Solution

by:
Pierre Cornelius earned 1500 total points
ID: 40300259
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

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

There can be many situations demanding the conversion of Outlook OST files to PST format and as such, there is no shortage of automated tools to perform this conversion. However, what makes Stellar OST to PST converter stand above the rest? Let us e…
Today as you open your Outlook, you witness an error message: “Outlook is using an old copy of your Outlook Data File…”. Probably, Outlook is accessing an old OST file.
This is used to tweak the memory usage for your computer, it is used for servers more so than workstations but just be careful editing registry settings as it may cause irreversible results. I hold no responsibility for anything you do to the regist…
Is your OST file inaccessible, Need to transfer OST file from one computer to another? Want to convert OST file to PST? If the answer to any of the above question is yes, then look no further. With the help of Stellar OST to PST Converter, you can e…

810 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question