Skip to content
This repository has been archived by the owner on Feb 23, 2024. It is now read-only.

Commit

Permalink
Update README.md
Browse files Browse the repository at this point in the history
  • Loading branch information
CWBudde committed Sep 8, 2017
1 parent 3317cca commit f4932d6
Showing 1 changed file with 38 additions and 0 deletions.
38 changes: 38 additions & 0 deletions README.md
Expand Up @@ -2,10 +2,16 @@
PNG library for reading and writing of PNG images in combination with a TBitmap32 class from the GR32 library.

## Usage
In order to use the library ensure that you use the unit GR32_PNG. This unit uses GR32_PortableNetworkGraphics to read and write PNG files, which makes it necessary to add the file to your project as well. Or just add the directory to the library path.

The simplest way to load a PNG to a TBitmap32 instance is by using:

LoadBitmap32FromPNG(Bitmap: TBitmap32; const Filename: string);

You can check if the file is a valid PNG file by using

function IsValidPNG(const Filename: string): Boolean;

If the PNG file comes from a stream one can also use

LoadBitmap32FromPNG(Bitmap: TBitmap32; Stream: TStream);
Expand All @@ -32,3 +38,35 @@ To save the content of a TBitmap32 instance to a PNG file or stream the function
procedure SaveBitmap32ToPNG(Bitmap: TBitmap32; Stream: TStream);

can be used.

## Advanced Usage
If you use the simple functions you won't be able to track the progress during loading. To do so you must create an instance of TPortableNetworkGraphic32 and load the PNG file manually. Before actually loading you can specify an OnProgress handler to track the progress. The code will then look like this:

with TPortableNetworkGraphic32.Create do
try
OnProgress := OnProgressHandler;
LoadFromFile(Filename);
AssignTo(YourBitmap); // can be Image32.Bitmap for example
finally
Free;
end;

Where the OnProgressHandler might looks like this:

procedure TForm1.OnProgressHandler(Sender: TObject; Percent: Single);
begin
ProgressBar.Position := Round(Percent);
end;

If you want to change some settings while saving you need to do this manually as well. The code can then look like this:

with TPortableNetworkGraphic32.Create do
try
AssignTo(YourBitmap); // can be Image32.Bitmap for example
Interlaced := imAdam7; // save as interlaced png file
SaveToFile(Filename);
finally
Free;
end;

With the current state of implementation it's not possible to alter everything without ending in an invalid PNG file. For example you could convert the image to use a pallete and then alter or delete the palette before saving. Doing so will not give you an error, but most probably the image won't be readable by other programs (or at least different to the original image).

0 comments on commit f4932d6

Please sign in to comment.