Difference between revisions of "Developing with Graphics/nl"

From Free Pascal wiki
Jump to navigationJump to search
 
Line 1: Line 1:
 
==Overview==
 
==Overview==
  
This page will be the start for tutorials with regard to manipulating Bitmaps and other graphics in your program. As I'm not a graphics programmer I invite all who are, to share their expertise! Just add a link to this page and create your own WiKi article.
+
Deze pagina is de start voor lessen die betrekking hebben op het manipuleren van Bitmap en plaatjes in andere formats. Ik ben geen graphics programmeur, dus iedereen die wel veel met graphics programmeert zou ik willen vragen om deze pagina uit te breiden. Gewoon door een link te maken in de sectie hieronder en dan een Wiki-pagina te vullen. Op deze pagina zal ik een klein voorbeeldje geven van hoe je een fading plaatje kunt maken.
On this page some general information will be given.
 
  
==Working with TBitmap==
+
==Lessen in het programmeren met Graphics==
The first thing to remember is that Lazarus is meant to be platform independent, so any methods using Windows API functionality are out of the question. So a method like ScanLine is not supported by Lazarus because it is intended for Device Independant Bitmap and uses functions from the GDI32.dll.
+
* [[#Werken met TBitmap|Werken]] met een bitmap
So this takes care of the FAQ: Why is there no ScanLine in Lazarus?
+
*
 +
 
 +
==Werken met TBitmap==
 +
Allereerst even een FAQ beantwoorden: Waarom is er (nog) geen ScanLine in Lazarus?
 +
Zoals bekend is, moet Lazarus platform onafhankelijk zijn. Dit heeft tot gevolg tot methodes die gebruik maken van de Windows API niet tot de mogelijkheden behoren. ScanLine is zo'n method. ScanLine werkt met DIBs (Device Independant Bitmap) en gebruikt daarbij een aantal functies uit de GDI32.dll.
  
 
===A fading example===
 
===A fading example===

Revision as of 14:42, 5 April 2005

Overview

Deze pagina is de start voor lessen die betrekking hebben op het manipuleren van Bitmap en plaatjes in andere formats. Ik ben geen graphics programmeur, dus iedereen die wel veel met graphics programmeert zou ik willen vragen om deze pagina uit te breiden. Gewoon door een link te maken in de sectie hieronder en dan een Wiki-pagina te vullen. Op deze pagina zal ik een klein voorbeeldje geven van hoe je een fading plaatje kunt maken.

Lessen in het programmeren met Graphics

Werken met TBitmap

Allereerst even een FAQ beantwoorden: Waarom is er (nog) geen ScanLine in Lazarus? Zoals bekend is, moet Lazarus platform onafhankelijk zijn. Dit heeft tot gevolg tot methodes die gebruik maken van de Windows API niet tot de mogelijkheden behoren. ScanLine is zo'n method. ScanLine werkt met DIBs (Device Independant Bitmap) en gebruikt daarbij een aantal functies uit de GDI32.dll.

A fading example

Say you want to make a Fading picture. In Delphi you could do something like:

type
  PRGBTripleArray = ^TRGBTripleArray;
  TRGBTripleArray = array[0..32767] of TRGBTriple;

procedure TForm1.FadeIn(aBitMap: TBitMap);
var
  Bitmap, BaseBitmap: TBitmap;
  Row, BaseRow: PRGBTripleArray;
  x, y, step: integer;
begin
  Bitmap := TBitmap.Create;
  try
    Bitmap.PixelFormat := pf32bit;  //  or pf24bit
    Bitmap.Assign(aBitMap);
    BaseBitmap := TBitmap.Create;
    try
      BaseBitmap.PixelFormat := pf32bit;
      BaseBitmap.Assign(Bitmap);
      for step := 0 to 32 do begin
        for y := 0 to (Bitmap.Height - 1) do begin
          BaseRow := BaseBitmap.Scanline[y];
          Row := Bitmap.Scanline[y];
          for x := 0 to (Bitmap.Width - 1) do begin
            Row[x].rgbtRed := (step * BaseRow[x].rgbtRed) shr 5;
            Row[x].rgbtGreen := (step * BaseRow[x].rgbtGreen) shr 5; // Fading
            Row[x].rgbtBlue := (step * BaseRow[x].rgbtBlue) shr 5;
          end;
        end;
        Form1.Canvas.Draw(0, 0, Bitmap);
        InvalidateRect(Form1.Handle, nil, False);
        RedrawWindow(Form1.Handle, nil, 0, RDW_UPDATENOW);
      end;
    finally
      BaseBitmap.Free;
    end;
  finally
    Bitmap.Free;
  end;
end;

This function in Lazarus could be implemented like:

procedure TForm1.FadeIn(ABitMap: TBitMap);
var
  SrcIntfImg, TempIntfImg: TLazIntfImage;
  ImgHandle,ImgMaskHandle: HBitmap;
  FadeStep: Integer;
  px, py: Integer;
  CurColor: TFPColor;
  TempBitmap: TBitmap;
begin
  SrcIntfImg:=TLazIntfImage.Create(0,0);
  SrcIntfImg.LoadFromBitmap(ABitmap.Handle,ABitmap.MaskHandle);
  TempIntfImg:=TLazIntfImage.Create(0,0);
  TempIntfImg.LoadFromBitmap(ABitmap.Handle,ABitmap.MaskHandle);
  TempBitmap:=TBitmap.Create;
  for FadeStep:=1 to 32 do begin
    for py:=0 to SrcIntfImg.Height-1 do begin
      for px:=0 to SrcIntfImg.Width-1 do begin
        CurColor:=SrcIntfImg.Colors[px,py];
        CurColor.Red:=(CurColor.Red*FadeStep) shr 5;
        CurColor.Green:=(CurColor.Green*FadeStep) shr 5;
        CurColor.Blue:=(CurColor.Blue*FadeStep) shr 5;
        TempIntfImg.Colors[px,py]:=CurColor;
      end;
    end;
    TempIntfImg.CreateBitmap(ImgHandle,ImgMaskHandle,false);
    TempBitmap.Handle:=ImgHandle;
    TempBitmap.MaskHandle:=ImgMaskHandle;
    Canvas.Draw(0,0,TempBitmap);
  end;
  SrcIntfImg.Free;
  TempIntfImg.Free;
  TempBitmap.Free;
end;

The Lazarus code on this page has been taken from the $LazarusPath/examples/lazintfimage/fadein1.lpi project. So if you want a flying start with graphics programming take a closer look at this example.