Register for your free account! | Forgot your password?

Go Back   elitepvpers > Coders Den > Coding Releases
You last visited: Today at 04:30

  • Please register to post and access all features, it's quick, easy and FREE!

Advertisement



Graphische Funktionen [VCL]

Discussion on Graphische Funktionen [VCL] within the Coding Releases forum part of the Coders Den category.

Reply
 
Old   #1
 
elite*gold: 0
Join Date: Feb 2009
Posts: 1,137
Received Thanks: 573
Graphische Funktionen [VCL]

Hallo Community
Im Zuge eines projektes habe ich ein paar funktionen geschrieben, und ich denke die können noch andere leute gebrauchen.
Geschrieben ist es in delphi, die funktionen lassen sich aber auch mit dem Rad Studio in C++ verwenden

Sollte schon ab D5 gehen, da es allerdings die PNGImage Komponente verwendet geht es nur wenn die installiert ist (standartmäßig ab 09 glaub ich)

die Funktionen sind:
DrawOnCanvas: Zeichnet ein Bild (TPicture) auf ein Canvas Objekt, mit verschiedenen anzeige möchlichkeiten (Zentriert, gestreckt, gezoomt, gefüllt, wiederholend X, wiederholendy, wiederohlendXY)

FileMD5: Gibt dem Hash einer Datei zurück, super zum überprüfen ob sich eine datei in der zwischenzeit geändert hat

GreyAndDarkenPicture: Diese funktion ändert die Helligkeit und die Sättigung eines TPictures (Nach HSV-Farbraum)

RGBToHSV und HSVToRGB: Konvertierung zwischen den Farbschemen, funktionen nicht von mir, nur von mir angepasst

DrawTextOnWindow, DrawTextOnDesktop: Schreibt einen Text auf den Bildschirm oder auf ein Fenster (Fenstertitel muss angegeben werden)

DrawOnWindow, DrawOnDesktop: Zeichnet ein TPicture auf bildschirm oder auf ein anderes Fenster

SetOpacity: Reduziert die Opacity von einem TPicture

Hinweise:
Verwendet man GreyAndDarkenPicture sowie die HSV Convertierung so wird der Alpha kanal von Png bildern auf 1bit gesetzt-> Nur noch tranzparent, oder farbig, nix mehr dazwischen
Selbiges gilt bei DrawOnCanvas, wenn Smooth aktiviert ist.
Ohne smooth bleibt der Alpha kanal zwar erhalten, aber beim skalieren verschlächtert sich die Qualität

Bei den DrawTextOn und DrawOn methoden bleibt das gezeichnete nur solange erhalten bis sich der hintergrund hinter dem gezeichneten ändert, danach verschwindet das gezeichnete

SetOpacity: funktioniert erst beim 2ten aufruf im testprogramm



Hier die Unit mit den Funktionen:

PHP Code:
unit GraphicalFunctions;

interface
uses WindowsSysUtilsClassesGraphicsControlsJpegPngImage,
  
idHashMessageDigestDialogsMath;

type
  PRow
=^TRow;
  
TRow=array[0..(High(Integer)-10div Sizeof(TRGBTriple)] of TRGBTriple;
  
TImageMode = (imStrechimZoomimCenterimRepeatXimRepeatYimRepeatXYimFill);
  
THSVColor record
    Hue
Integer;
    
ValueByte;
    
SaturationByte;
  
end;


function 
GetCanvasHandle(var pTPicture): Integer;
procedure DrawOnCanvas(CanvasTCanvasSmoothBooleanPicToDrawTPicture;
  
DrawModeTImageModeWidthHeightIntegerOffsetTPoint);
function 
FileMD5(const fileName string) : string;
procedure GreyAndDarkenPicture(PTPictureGreyValDarkValReal);
function 
RGBtoHSV(RedGreenBlueByte): THSVColor;
function 
HSVtoRGB(HSVTHSVColor):TColor;
function 
ColToRGBTriple(const ColorTColor): TRGBTriple;
procedure DrawTextOnDesktop(TextstringXYIntegerFTFont);
procedure DrawOnDesktop(PTPicturePosTRectSmoothBoolean);
procedure DrawTextOnWindow(TextWindowstringXYIntegerFTFont);
procedure DrawOnWindow(PTPictureWindowstringPosTRectSmoothBoolean);
procedure SetOpacity(PTPictureOpacityByte);

implementation

function GetCanvasHandle(var pTPicture): Integer;
var 
tmpbmpTBitmap;
g:TGraphic;
begin
  Result
:=-1;
  
g:=p.Graphic;
  if 
g is TBitmap then
    Result
:=TBitmap(g).Canvas.Handle
  
else if g is TPngImage then
    Result
:=TPngImage(g).Canvas.Handle
  
else if g is TJPEGImage then
  begin
    tmpbmp
:=TBitmap.Create;
    try
    
tmpbmp.Assign(TJPEGImage(g));
    
p.Graphic:=tmpbmp;
    
Result:=tmpbmp.Canvas.Handle;
    
finally
      tmpbmp
.Free;
    
end;
  
end;
end;


procedure DrawOnCanvas(CanvasTCanvasSmoothBooleanPicToDrawTPicture;
  
DrawModeTImageModeWidthHeightIntegerOffsetTPoint);
  var 
newWnewHInteger;
  
ixInteger;
begin
SetStretchBltMode
(Canvas.HandleHALFTONE);
if 
Assigned(PicToDrawthen
 begin
  
case DrawMode of
    imStrech
:
    
begin
      
if (GetCanvasHandle(PicToDraw)<>-1) And Smooth then
        StretchBlt
(Canvas.HandleOffset.XOffset.YWidthHeightGetCanvasHandle(PicToDraw), 00,
          
PicToDraw.WidthPicToDraw.HeightSRCCOPY)
        else
          
Canvas.StretchDraw(Rect(Offset.XOffset.YWidthOffset.XHeight Offset.Y), PicToDraw.Graphic);
    
end;
    
imZoom:
    
begin
      
if PicToDraw.Width Width>PicToDraw.Height Height then
      begin
        newW
:=Width;
        
newH:=round(PicToDraw.Height/(PicToDraw.Width Width));
      
end
      
else
      
begin
        newH
:=Height;
        
newW:=round(PicToDraw.Width/(PicToDraw.Height Height));
      
end;
      if (
GetCanvasHandle(PicToDraw)<>-1) And Smooth then
        StretchBlt
(Canvas.HandleWidth div 2 newW div 2 Offset.XHeight div 2 newH div 2 Offset.YnewWnewHGetCanvasHandle(PicToDraw), 00,
          
PicToDraw.WidthPicToDraw.HeightSRCCOPY)
      else
        
Canvas.StretchDraw(Rect(Width div 2 -newW div 2 Offset.XHeight div 2 -newH div 2 Offset.YnewW+Width div 2 -newW div 2 Offset.XnewH Height div 2 -newH div 2 Offset.Y), PicToDraw.Graphic);
    
end;
    
imCenter:
    
begin
      Canvas
.Draw(Width div 2 PicToDraw.Width div 2 Offset.X,Height div 2 PicToDraw.Height div 2 Offset.YPicToDraw.Graphic);
    
end;
    
imFill:
    
begin
      
if PicToDraw.Width Width<PicToDraw.Height Height then
      begin
        newW
:=Width;
        
newH:=round(PicToDraw.Height/(PicToDraw.Width Width));
      
end
      
else
      
begin
        newH
:=Height;
        
newW:=round(PicToDraw.Width/(PicToDraw.Height Height));
      
end;
      if (
GetCanvasHandle(PicToDraw)<>-1) And Smooth then
        StretchBlt
(Canvas.HandleWidth div 2 newW div 2 Offset.XHeight div 2 newH div 2 Offset.YnewWnewHGetCanvasHandle(PicToDraw), 00,
          
PicToDraw.WidthPicToDraw.HeightSRCCOPY)
      else
        
Canvas.StretchDraw(Rect(Width div 2 -newW div 2 Offset.XHeight div 2 -newH div 2 Offset.YnewW+Width div 2 -newW div 2 Offset.XnewH Height div 2 -newH div 2 Offset.Y), PicToDraw.Graphic);
    
end;
    
imRepeatX..imRepeatXY:
    
begin
      
for := Offset.X to Width div PicToDraw.Width+Offset.do
      
begin
        
if DrawMode<>imRepeatY then
          Canvas
.Draw(i*PicToDraw.Width0PicToDraw.Graphic);
        if 
DrawMode<>imRepeatX then
          
for := Offset.Y to Height div PicToDraw.Height+Offset.do
            if 
DrawMode=imRepeatXY then
              Canvas
.Draw(i*PicToDraw.Widthx*PicToDraw.HeightPicToDraw.Graphic)
            else
              
Canvas.Draw(0x*PicToDraw.HeightPicToDraw.Graphic);

      
end;
    
end;
  
end;
 
end;
end;

function 
FileMD5(const fileName string) : string;
var
  
MD5 TIdHashMessageDigest5;
  
FileStreamTFileStream;
begin
  MD5 
:= TIdHashMessageDigest5.Create;
  
FileStream := TFileStream.Create(fileNamefmOpenRead OR fmShareDenyWrite) ;
  try
    
result := MD5.HashStreamAsHex(FileStream);
  
finally
    FileStream
.Free;
    
MD5.Free;
  
end;
end;

procedure GreyAndDarkenPicture(PTPictureGreyValDarkValReal);
var
  
yxInteger;
  
Row: ^TRGBTriple;
  
hsvTHSVColor;
  
bmpTBitmap;
begin
  
if Assigned(P.Graphicthen
  begin
    bmp
:=TBitmap.Create;
    try
      
bmp.PixelFormat := pf24bit;
      
bmp.Assign(TJPEGImage(P.Graphic));
      for 
:= 0 to bmp.Height do
      
begin
        Row
:=bmp.ScanLine[y];
        for 
:= 0 to bmp.Width do
        
begin
          hsv
:=RGBtoHSV(row^.rgbtRedrow^.rgbtGreenrow^.rgbtBlue);
          
hsv.Saturation:=Max(round(hsv.Saturation-hsv.Saturation/100*GreyVal), 0);
          
hsv.Value:=Max(round(hsv.Value-hsv.Value/100*DarkVal), 0);
          
row^:=ColToRGBTriple(HSVtoRGB(hsv));
          
inc(Row);
        
end;
      
end;
      
P.Bitmap.Assign(bmp);
    
finally
      bmp
.Free;
    
end;
  
end;
end;

function 
ColToRGBTriple(const ColorTColor): TRGBTriple;
begin
  result
.rgbtRed := Color and $FF;
  
result.rgbtGreen := (Color shr 8) and $FF;
  
Result.rgbtBlue := (Color shr 16) and $FF;
end;


//abgeändert von http://www.delphipraxis.net/42054-rgb-hsv-und-hsv-rgb.html
function RGBtoHSV(RedGreenBlueByte): THSVColor;
var 
HueInteger;
var 
SaturationValueByte;
var
  
MaximumMinimumByte;
  
RcGcBcSingle;
  
HSingle;
begin
  Maximum 
:= Max(RedMax(GreenBlue));
  
Minimum := Min(RedMin(GreenBlue));
  
Value := Maximum;
  if 
Maximum <> 0 then
    Saturation 
:= MulDiv(Maximum Minimum255Maximum)
  else
    
Saturation := 0;
  if 
Saturation 0 then
    Hue 
:= // arbitrary value
  
else
  
begin
    Assert
(Maximum <> Minimum);
    
Rc := (Maximum Red) / (Maximum Minimum);
    
Gc := (Maximum Green) / (Maximum Minimum);
    
Bc := (Maximum Blue) / (Maximum Minimum);
    if 
Red Maximum then
      H 
:= Bc Gc
    
else if Green Maximum then
      H 
:= Rc Bc
    
else
    
begin
      Assert
(Blue Maximum);
      
:= Gc Rc;
    
end;
    
:= 60;
    if 
0 then
      H 
:= 360;
    
Hue := Round(H);
  
end;
  
result.Hue:=Hue;
  
Result.Value:=Value;
  
Result.Saturation:=Saturation;
end;


//abgeändert von http://www.delphipraxis.net/42054-rgb-hsv-und-hsv-rgb.html
function HSVtoRGB(HSVTHSVColor):TColor;
var
  
H:Integer;
  
SVByte;
  
htdt1t2t3:Integer;
  
R,G,B:Word;
begin
  h
:=HSV.Hue;
  
S:=HSV.Saturation;
  
V:=HSV.Value;
  if 
0 then
   begin
    R 
:= V:= V:= V;
   
end
  
else
   
begin
    ht 
:= 6;
    
:= ht mod 360;

    
t1 := round(* (255 S) / 255);
    
t2 := round(* (255 360) / 255);
    
t3 := round(* (255 * (360 d) / 360) / 255);

    case 
ht div 360 of
    0
:
      
begin
        R 
:= V:= t3:= t1;
      
end;
    
1:
      
begin
        R 
:= t2:= V:= t1;
      
end;
    
2:
      
begin
        R 
:= t1:= V:= t3;
      
end;
    
3:
      
begin
        R 
:= t1:= t2:= V;
      
end;
    
4:
      
begin
        R 
:= t3:= t1:= V;
      
end;
    else
      
begin
        R 
:= V:= t1:= t2;
      
end;
    
end;
   
end;
  
Result:=RGB(R,G,B);
end;


procedure DrawOnWindow(PTPictureWindowstringPosTRectSmoothBoolean);
var 
cTCanvas;
begin
  c
:=TCanvas.Create;
  try
    
c.Handle:=GetWindowDC(FindWindow(nilPChar(Window)));
    
DrawOnCanvas(cSmoothPimZoomPos.Right-Pos.LeftPos.Bottom-Pos.Top,
      
Point(Pos.LeftPos.Top));
  
finally
    c
.Free;
  
end;
end;

procedure DrawTextOnWindow(TextWindowstringXYIntegerFTFont);
var 
cTCanvas;
begin
  c
:=TCanvas.Create;
  try
    
c.Handle:=GetWindowDC(FindWindow(nilPChar(Window)));
    if 
Assigned(Fthen
      c
.Font:=F;
    
c.TextOut(XYText);
  
finally
    c
.Free;
  
end;
end;

procedure DrawOnDesktop(PTPicturePosTRectSmoothBoolean);
var 
cTCanvas;
begin
  c
:=TCanvas.Create;
  try
    
c.Handle:=GetWindowDC(GetDesktopWindow);
    
DrawOnCanvas(cSmoothPimZoomPos.Right-Pos.LeftPos.Bottom-Pos.Top,
      
Point(Pos.LeftPos.Top));
  
finally
    c
.Free;
  
end;
end;

procedure DrawTextOnDesktop(TextstringXYIntegerFTFont);
var 
cTCanvas;
begin
  c
:=TCanvas.Create;
  try
    
c.Handle:=GetWindowDC(GetDesktopWindow);
    if 
Assigned(Fthen
      c
.Font:=F;
    
c.TextOut(XYText);
  
finally
    c
.Free;
  
end;
end;

procedure SetOpacity(PTPictureOpacityByte);
var 
tmpbmpTBitmap;
begin
  tmpbmp
:=TBitmap.Create;
  try
    
tmpbmp.SetSize(P.Graphic.WidthP.Graphic.Height);
    
tmpbmp.PixelFormat:=pf24bit;
    
tmpbmp.Canvas.Draw(0,0P.GraphicOpacity);
    
P.Graphic:=(tmpbmp);
  
finally
    tmpbmp
.Free;
  
end;
end;

end
BSP Projekt (Erstellt mit Rad Studio XE):
warfley is offline  
Reply


Similar Threads Similar Threads
TBM API: Weitere Funktionen?
09/30/2011 - Off Topic - 3 Replies
Heyho Leute, da einige von euch sicherlich die TBM API für ihre Programme benutzen, eröffne ich hier einfach mal einen Poll, damit mehr Funktionen hinzugefügt werden. z.B: Von welcher Treasure das e*G stammt. Per JSON eine neue Transaktion aufgeben.
[Release]duffbier`s D3D NoMenu Base [D3D Funktionen/Normale Funktionen]
06/01/2011 - WarRock Hacks, Bots, Cheats & Exploits - 15 Replies
Hey Com. Ich hab mich entschieden meine D3D NoMenu Base zu Releasen In dieser kannst du normale Funktionen sowie D3D Funktionen adden Screens: http://img64.imageshack.us/img64/4444/screeenl.jp g
°*NEW Funktionen*° th3man0f22 NO MENÜ Public Hack°*NEW Funktionen*° 06.09.2010
09/06/2010 - WarRock Hacks, Bots, Cheats & Exploits - 2 Replies
Funktionen: PLAYERPOINTER ¤SERVERPOINTER (Immer an)¤ ¤NOSPREAD (Numm-Pad 7)¤ ¤FULLBRIGHT (Numm-Pad 5)¤ ¤EXTRAAMMO1 (Immer an)¤ ¤EXTRAAMMO2 (Immer an)¤ ¤SCOPE (Rechte Maustaste)¤ ¤FASTAMMO (Immer an)¤
Only App mit 3 Funktionen
05/31/2010 - Last Chaos - 4 Replies
Wenn jemand mal Zeit hat, kann mir jemand einen kleines App machen mit HP Scan, Maphack (Also auf Saveplace und Saveplace Port) und die Funktionen von dem Unterstützer? Sowas wie eben bei dem UltraBot von Tytal, aber nur eben mit den 3 funktionen :)
Funktionen etc...
12/06/2009 - AutoIt - 5 Replies
Hey Leute hab da noch 1 Problem^^ Ich kann schon mal sagen die addressen sind richtig aber das system net^^ #Region Includes #include <ButtonConstants.au3> #include <EditConstants.au3> #include <GUIConstantsEx.au3> #include <StaticConstants.au3> #include <WindowsConstants.au3> #include <NomadMemory.au3> #EndRegion Includes



All times are GMT +1. The time now is 04:31.


Powered by vBulletin®
Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
SEO by vBSEO ©2011, Crawlability, Inc.
This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

Support | Contact Us | FAQ | Advertising | Privacy Policy | Terms of Service | Abuse
Copyright ©2025 elitepvpers All Rights Reserved.