Delphi-PRAXiS
Seite 2 von 4     12 34      

Delphi-PRAXiS (https://www.delphipraxis.net/forum.php)
-   Algorithmen, Datenstrukturen und Klassendesign (https://www.delphipraxis.net/78-algorithmen-datenstrukturen-und-klassendesign/)
-   -   Delphi Grafik im Speicher erstellen für BlobStream (DB) (https://www.delphipraxis.net/207654-grafik-im-speicher-erstellen-fuer-blobstream-db.html)

NoGAD 19. Apr 2021 21:52

AW: Grafik im Speicher erstellen für BlobStream (DB)
 
Vielen Dank, Du hast mir sehr geholfen :-)

PS: gibt es schon eine fertige Funktion, um ein Zufallsbild zu erzeugen?

LG

KodeZwerg 19. Apr 2021 21:56

AW: Grafik im Speicher erstellen für BlobStream (DB)
 
nicht das ich wüsste, aber per iteration (über width und height) kannst du bunte punkte setzen...
Zitat:

Zitat von NoGAD (Beitrag 1487434)
Vielen Dank, Du hast mir sehr geholfen :-)

Gerne!

KodeZwerg 19. Apr 2021 22:07

AW: Grafik im Speicher erstellen für BlobStream (DB)
 
nur mal auf die schnelle dahingedaddelt. erwarte keine wunder.
Delphi-Quellcode:
procedure TForm9.FormCreate(Sender: TObject);
type
  TRGB = record
    b,g,r: Byte;
  end;
  ARGB = array [0..1] of TRGB;
  PARGB = ^ARGB;
var
  p: PARGB;
  x,y: Integer;
  bmp: Vcl.Graphics.TBitmap;
begin
  bmp := Vcl.Graphics.TBitmap.Create;
  try
    bmp.PixelFormat := pf24bit;
    bmp.Width := 50;
    bmp.Height := 50;
    for y := 0 to (bmp.Height - 1) do
    begin
      p := bmp.ScanLine[y];
      for x := 0 to (bmp.Width - 1) do
        begin
          p[x].r := Random(High(Byte));
          p[x].g := Random(High(Byte));
          p[x].b := Random(High(Byte));
        end;
    end;
    // mach was...
  finally
    bmp.Free;
  end;
end;

NoGAD 19. Apr 2021 22:15

AW: Grafik im Speicher erstellen für BlobStream (DB)
 
Das ist nett :-)

:-D

KodeZwerg 19. Apr 2021 22:29

AW: Grafik im Speicher erstellen für BlobStream (DB)
 
Ps: Randomize << das noch aufrufen bevor Random() aufgerufen wird, habs vergessen im oberen source.

NoGAD 20. Apr 2021 01:15

AW: Grafik im Speicher erstellen für BlobStream (DB)
 
Danke nochmal, ich habe es in eine Function gegossen:


Delphi-Quellcode:

type
  TRGB = record
    b, g, r: Byte;
  end;

  ARGB = array [0 .. 1] of TRGB;
  PARGB = ^ARGB;


function RandomBitmap(bmp: VCL.Graphics.TBitmap; iWidth: Integer = 225; iHeight: Integer = 225): Boolean;
var
  ix, iy: Integer;
  p: PARGB;
begin

  Result := default (Boolean);

  if (iWidth = 0) and (iHeight = 0) then
    exit;

  Randomize;
  try
    bmp.PixelFormat := pf24bit;
    bmp.Width := iWidth;
    bmp.Height := iHeight;
    for iy := 0 to (bmp.Height - 1) do
    begin
      p := bmp.ScanLine[iy];
      for ix := 0 to (bmp.Width - 1) do
      begin
        p[ix].r := random(High(Byte));
        p[ix].g := random(High(Byte));
        p[ix].b := random(High(Byte));
      end;
    end;
  finally
    Result := true;
  end;

end;


// Aufruf z.B.:

var
  Dummy_Image: Vcl.Graphics.TBitmap;
begin
  Dummy_Image := Vcl.Graphics.TBitmap.Create;
  RandomBitmap(Dummy_Image, random(50) + 225, random(50) + 225);
// hier was mit dem Bild machen
  Dummy_Image.Free;
end;

LG und schlaf gut :-)

KodeZwerg 20. Apr 2021 18:40

AW: Grafik im Speicher erstellen für BlobStream (DB)
 
Delphi-Quellcode:
function RandomBitmap(Abmp: VCL.Graphics.TBitmap; const AWidth: Integer = 225; const AHeight: Integer = 225): Boolean;
type
  TRGB = record
    b, g, r: Byte;
  end;
  ARGB = array [0 .. 1] of TRGB;
  PARGB = ^ARGB;
var
  x, y: Integer;
  p: PARGB;
begin
  Result := False;
  if (AWidth = 0) or (AHeight = 0) then
    Exit(False);

  Randomize;

  if Abmp = nil then
    Abmp := Vcl.Graphics.TBitmap.Create;
  try
    Abmp.PixelFormat := pf24bit;
    Abmp.Width := AWidth;
    Abmp.Height := AHeight;
    for y := 0 to (Abmp.Height - 1) do
    begin
      p := Abmp.ScanLine[y];
      for x := 0 to (Abmp.Width - 1) do
      begin
        p[x].r := Random(High(Byte));
        p[x].g := Random(High(Byte));
        p[x].b := Random(High(Byte));
      end;
    end;
  finally
    Result := True;
  end;
end;
minimal abgeändert, jedenfalls würde es so bei mir aussehen.

DeddyH 21. Apr 2021 07:47

AW: Grafik im Speicher erstellen für BlobStream (DB)
 
Und den Speicher hast Du im Griff?

NoGAD 21. Apr 2021 08:37

AW: Grafik im Speicher erstellen für BlobStream (DB)
 
Zitat:

Zitat von DeddyH (Beitrag 1487491)
Und den Speicher hast Du im Griff?

Meinst Du bezüglich KodeZwerg's

Delphi-Quellcode:
 if Abmp = nil then
    Abmp := Vcl.Graphics.TBitmap.Create;
?

Das würde bei mir auch mittels Exit, bei nil, vorher abgefangen werden. Hatte ich in meinem Code vergessen.

LG

KodeZwerg 21. Apr 2021 09:19

AW: Grafik im Speicher erstellen für BlobStream (DB)
 
Zitat:

Zitat von DeddyH (Beitrag 1487491)
Und den Speicher hast Du im Griff?

Definitiv positiv.
(kein objekt da = erschaffe eins, ist eins da = mach was)


//edit
(ich gebe solche objekte per freeandnil frei)


Alle Zeitangaben in WEZ +1. Es ist jetzt 15:58 Uhr.
Seite 2 von 4     12 34      

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024 by Thomas Breitkreuz