// Erzeugt einen Base64-String aus der JPEG Bild-Datei die ich versenden will
function EncodeFile(
const FileName:
string): AnsiString;
var
stream: TMemoryStream;
begin
stream := TMemoryStream.Create;
try
stream.LoadFromFile(Filename);
result := EncodeBase64(stream.Memory, stream.Size);
finally
stream.Free;
end;
end;
// Kompressiert ein BMP in ein JPEG
procedure CompressImage(ImageFrom: TBitmap; ImageTo: TJPEGImage; Quality: integer);
var
bmp: TBitmap;
jpeg: TJPEGImage;
stream: TMemoryStream;
begin
bmp:=TBitmap.Create;
jpeg:=TJPEGImage.Create;
stream:=TMemoryStream.Create;
try
bmp.Assign(ImageFrom);
jpeg.Assign(bmp);
jpeg.PixelFormat:=jf24bit;
// or jf8bit
jpeg.CompressionQuality:=Quality;
jpeg.ProgressiveDisplay:=False;
jpeg.ProgressiveEncoding:=False;
jpeg.Compress;
jpeg.SaveToStream(stream);
stream.Position := 0;
ImageTo.LoadFromStream(stream);
finally
bmp.Free;
jpeg.Free;
stream.Free;
end;
end;
// Erzeugt einen Screenshot
procedure ScreenShot(DestBitmap: TBitmap);
var
DC: HDC;
begin
DC:=GetDC(GetDesktopWindow);
try
DestBitmap.Width:=GetDeviceCaps(
DC, HORZRES);
DestBitmap.Height:=GetDeviceCaps(
DC, VERTRES);
BitBlt(DestBitmap.Canvas.Handle,0,0,DestBitmap.Width,DestBitmap.Height,
DC,0,0,SRCCOPY);
finally
ReleaseDC(GetDesktopWindow,
DC);
end;
end;
// Fängt die PrintScreen-Taste auf
procedure TForm1.WMHotKey(
var Msg: TWMHotKey);
begin
Screenshot(ss);
image1.Picture.Bitmap := ss;
FormStyle := fsStayOnTop;
Show;
end;
// Upload-Funktion
procedure TForm1.Upload;
var
URL:
string;
img :TJPEGImage;
mes :
string;
cmds : TStringList;
bmp : TBitmap;
begin
img := TJPEGImage.Create;
CompressImage(ss, img, Trackbar1.Position);
img.SaveToFile('
./Screenshot.jpeg');
base64 := EncodeFile('
./Screenshot.jpeg');
idtcpclient1.IOHandler.WriteLn('
start');
idtcpclient1.IOHandler.WriteLn(base64);
// Hier wird der Base64-String gesendet
idtcpclient1.IOHandler.WriteLn('
end');
end;