Link to home
Start Free TrialLog in
Avatar of OneDeath
OneDeath

asked on

How to resize a screenshot with proportionality

hi want the screen shot proportionality, i mean the resolution of the screen (Width and Height div 2)
and save it to a disk, this is the code im using:
program ScreenShot;
 
uses Windows, Classes, Graphics, Jpeg;
 
procedure DrawCursor(Bmp: TBitmap);
var
  r: TRect;
  CI: TCursorInfo;
  Icon: TIcon;
  II: TIconInfo;
begin
  r := Bmp.Canvas.ClipRect;
  Icon := TIcon.Create;
  try
    CI.cbSize := SizeOf(CI);
    if GetCursorInfo(CI) then
      if CI.Flags = CURSOR_SHOWING then
      begin
        Icon.Handle := CopyIcon(CI.hCursor);
        if GetIconInfo(Icon.Handle, II) then
        begin
          Bmp.Canvas.Draw(
            ci.ptScreenPos.x - Integer(II.xHotspot) - r.Left,
            ci.ptScreenPos.y - Integer(II.yHotspot) - r.Top,
            Icon
            );
        end;
      end;
  finally
    Icon.Free;
  end;
end;
 
procedure SaveScreenToFile(FileName: String);
var
  Bmp: TBitmap;
  Jpg: TJpegImage;
begin
  Bmp := TBitmap.Create;
  Jpg := TJpegImage.Create;
  try
    Bmp.Width := GetSystemMetrics(SM_CXSCREEN);
    Bmp.Height := GetSystemMetrics(SM_CYSCREEN);
    BitBlt(Bmp.Canvas.Handle, 0, 0, Bmp.Width, Bmp.Height, GetDc(0), 0, 0, SRCCOPY);
    DrawCursor(Bmp);
    Jpg.Assign(Bmp);
    Jpg.CompressionQuality := 60;
    Jpg.Compress;
    Jpg.SaveToFile(FileName);
  finally
    Bmp.free;
    Jpg.free;
  end;
end;
 
begin
 SaveScreenToFile('SHOT.JPG');
end.

Open in new window

Avatar of OneDeath
OneDeath

ASKER

i mean resize the image WITHOUT QUALITY LOSS, there are some GOOD code around?
thanks
SOLUTION
Avatar of dougaug
dougaug
Flag of Brazil image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Hi,

I've improve my code and now you can choose any screen percent (smaller or bigger than the screen resolution). See the code below:


procedure SaveScreenToFile(FileName: String; ScreenPercent: Word);
var
  Bmp, Bmp2: TBitmap;
  Jpg: TJpegImage;
begin
  Bmp := TBitmap.Create;
  Bmp2 := TBitmap.Create;
  Jpg := TJpegImage.Create;
  try
    Bmp.Width := GetSystemMetrics(SM_CXSCREEN);
    Bmp.Height := GetSystemMetrics(SM_CYSCREEN);
    BitBlt(Bmp.Canvas.Handle, 0, 0, Bmp.Width, Bmp.Height, GetDc(0), 0, 0, SRCCOPY);
    DrawCursor(Bmp);
 
    if ScreenPercent > 0 then
    begin
      Bmp2.Width := Bmp.Width * ScreenPercent div 100;
      Bmp2.Height := Bmp.Height * ScreenPercent div 100;
    end;
    StretchBlt(Bmp2.Canvas.Handle, 0, 0, Bmp2.Width,bmp2.Height, bmp.Canvas.Handle,
               0, 0, bmp.Width, Bmp.Height, SRCCOPY);
 
    Jpg.Assign(Bmp2);
    Jpg.CompressionQuality := 100;
    Jpg.Compress;
    Jpg.SaveToFile(FileName);
  finally
    Bmp.free;
    Bmp2.free;
    Jpg.free;
  end;
end;
 
begin
 SaveScreenToFile('SHOT.JPG', 50);
end.

Open in new window

just what i need thanks both ^^