T O P I C R E V I E W |
brm121966 |
Posted - Nov 29 2021 : 20:39:58 Hello. Help me please. How can I load 800x800 jpg 16M color file to resize 200x200px and change palette 256color and write png using only one obj TImageEnView. I got the code, but there is a problem. The code does not change the palette to 256color.
var
i, w, h, nKey: integer;;
NewExtension, OutputFilename: string;
DestImageEnView, InImageEnView : TImageEnView;
begin
InputFilename := 'cover.jpg';
InImageEnView := TImageEnView.Create(Owner);
with InImageEnView do begin
Clear;
IO.LoadFromFile( InputFilename );
end;
DestImageEnView := TImageEnView.Create(Owner);
with DestImageEnView do begin
Clear;
Assign(InImageEnView.IEBitmap);
LockUpdate;
Fit;
Stretch;
w := 200;
h := 200;
Proc.Resample(w, h, rfLanczos3, True);
Invalidate;
Proc.Update;
Proc.ConvertTo(256, ieThreshold);
IO.Params.BitsPerSample := 8;
IO.Params.SamplesPerPixel := 1;
IO.Update;
Invalidate;
IO.Params.PNG_Compression := 8;
IO.Params.Width := IEBitmap.Width;
IO.Params.Height := IEBitmap.Height;
IO.Update;
Update;
UnLockUpdate;
OutputFilename := ReplaceStr(InputFilename,'Cover','Folder');
OutputFilename := ReplaceStr(OutputFilename,'.jpg','.png');
Log('ConvertImage: save: ' + OutputFilename);
IO.SaveToFile(OutputFilename, ioPNG);
end;
end;
Thanks. |
20 L A T E S T R E P L I E S (Newest First) |
xequte |
Posted - Mar 12 2022 : 18:10:18
Nigel Xequte Software www.imageen.com
|
brm121966 |
Posted - Mar 12 2022 : 15:08:46 Hi Nigel. The new version (10.3.5) solved the problem. Thanks.
Rudolf |
xequte |
Posted - Feb 16 2022 : 14:33:59 I've emailed you the latest beta.
Nigel Xequte Software www.imageen.com
|
brm121966 |
Posted - Feb 15 2022 : 20:57:57 Hi Nigel. I use.
ImageEn 10.3.0 Packages -------------------------------- Version : 10.3.0.6203 Date : 2021/1/17 Target : Delphi XE5 64bit (c:\ProgramData\ImageEn\DelphiXE5_64\) -------------------------------- www.ImageEn.com
Path library - C:\ProgramData\ImageEn\DelphiXE5_64 --------------------------------
Where can I get beta 201 version?
Thanks.
Rudolf |
xequte |
Posted - Feb 15 2022 : 03:59:09 Hi Rudolf
You need to be using Beta 201 or newer. If you have downloaded the beta, ensure your Delphi library path points to the beta source folder.
Nigel Xequte Software www.imageen.com
|
brm121966 |
Posted - Feb 14 2022 : 10:12:43 Hi Nigel. Did not help. There is no mention of gPNGAlphaThreshold in ImageEn\Source.
Rudolf |
xequte |
Posted - Feb 13 2022 : 17:43:52 Hi Rudolf
Please add pngfiltw to your uses clause.
Nigel Xequte Software www.imageen.com
|
brm121966 |
Posted - Feb 12 2022 : 21:21:12 Hi Nigel. Compilation error. [dcc64 Error] U_Edit_Settings_File.pas(666): E2003 Undeclared identifier: 'gPNGAlphaThreshold' what module should i connect? There is no description in the help for gPNGAlphaThreshold. Thanks.
Rudolf |
xequte |
Posted - Feb 10 2022 : 21:19:31 Hi Rudolf
Anytime before saving to PNG.
Nigel Xequte Software www.imageen.com
|
brm121966 |
Posted - Feb 10 2022 : 10:14:50 Hi Nigel. Thanks for the information. But how to use it. Where to add gPNGAlphaThreshold in the program? Thank you.
ImageEnView1 := TImageEnView.Create(nil);
with ImageEnView1 do begin
IO.LoadFromFile( 'Cover.png' );
Proc.Resample(400, 400, rfLanczos3, True);
Proc.ConvertTo(256, ieThreshold); //Reduce colors
Proc.Sharpen(10,4);
IEBitmap.PixelFormat := ie8p; // Set PixelFormat to 8bit
IEGlobalSettings().AutoSetBitDepth := True;
OutputFilename := 'Folder.png';
IO.Params.PNG_Compression := 8;
IO.SaveToFile(OutputFilename, ioPNG); // Save it
Free;
end;
Rudolf |
xequte |
Posted - Feb 08 2022 : 15:27:20 Hi Rudolf
8bit PNG files only support 1bit alpha (transparent or not-transparent pixels).
gPNGAlphaThreshold just specifies which pixels are converted to transparent or not.
So for the default of gPNGAlphaThreshold := 125; pixels with alpha values < 125 become fully transparent. Pixels with alpha values > 125 become opaque.
Nigel Xequte Software www.imageen.com
|
brm121966 |
Posted - Feb 08 2022 : 09:25:08 Hi Nigel. Sorry, but how do I use this (gPNGAlphaThreshold := 125;) in the code I have. Thank you.
Rudolf |
xequte |
Posted - Jan 30 2022 : 20:24:10 Hi
You can email me for a fix for this.
If you need to tweak the result, add pngfiltw to your uses and specify a different alpha threshold value, e.g.
gPNGAlphaThreshold := 125;
Nigel Xequte Software www.imageen.com
|
xequte |
Posted - Dec 23 2021 : 17:21:19 Hi Rudolf
In the new year, we'll see if there is a better method to calculate the index color.
Nigel Xequte Software www.imageen.com
|
brm121966 |
Posted - Dec 22 2021 : 20:42:09 Sorry, but FastStone 7.5 converted this file (Cover.png) without artifacts. Inserted IEBitmap.RemoveAlphaChannel(True), but the transparent areas are replaced with areas with a white background. It spoils the picture. What function can I use to merge / remove the alpha channel?
Thinks.
Rudolf |
xequte |
Posted - Dec 21 2021 : 23:18:57 8bit PNG format only supports index transparency, which accounts for the artifacts you see. You might want to merge/remove the alpha channel before saving.
I'll see if we can improve the output.
Nigel Xequte Software www.imageen.com
|
brm121966 |
Posted - Dec 20 2021 : 22:06:36 Hi Nigel.
I now have 10.3.0, but there is a problem. The file image is not drawn correctly.
example image: https://www.dropbox.com/s/ph4lij5f73ce3zu/Blues.zip?dl=0
Thinks.
Rudolf
P.S. my code:
ImageEnView1 := TImageEnView.Create(nil);
with ImageEnView1 do begin
IO.LoadFromFile( InputFilename );
Proc.Resample(400, 400, rfLanczos3, True);
Proc.ConvertTo(256, ieThreshold); //Reduce colors
Proc.Sharpen(10,4);
IEBitmap.PixelFormat := ie8p; // Set PixelFormat to 8bit
IEGlobalSettings().AutoSetBitDepth := True;
OutputFilename := ReplaceStr(InputFilename,'Cover','Folder');
OutputFilename := ReplaceStr(OutputFilename,'.jpg','.png');
IO.Params.PNG_Compression := 8;
IO.SaveToFile(OutputFilename, ioPNG); // Save it
Free;
end; |
xequte |
Posted - Dec 09 2021 : 23:07:52 Hi Rudolf
Your code works for me as long as there is an AlphaChannel (i.e. your call to ImageEnView1.AlphaChanel). Otherwise I get an output image with vertical banding. It is an issue with the PNG output filter as it only affects PNG.
We have a fix for this in the upcoming 10.3.0
Nigel Xequte Software www.imageen.com
|
brm121966 |
Posted - Dec 08 2021 : 19:39:39 Hi Nigel. Some files have a transparent background. In the modified files, the background is filled with white or black. Any ideas on how to fix this. Thanks.
Rudolf |
brm121966 |
Posted - Dec 04 2021 : 19:43:12 Hi Nigel. This is my last code.
w := 400;
h := 400;
ImageEnView1 := TImageEnView.Create(nil);
with ImageEnView1 do begin
IO.LoadFromFile( InputFilename );
AlphaChannel; //Add AlphaChannel
Proc.Resample(w, h, rfLanczos3, True); //Resize to
Proc.ConvertTo(256, ieThreshold); //Reduce colors
Proc.Sharpen(10,4);
IEBitmap.PixelFormat := ie8p; // Set PixelFormat to 8bit
IEGlobalSettings().AutoSetBitDepth := True; // Use PixelFormat as authoritative source of bit-depth
OutputFilename := ReplaceStr(InputFilename,'Cover','Folder'); // Save it
OutputFilename := ReplaceStr(OutputFilename,'.jpg','.png');
IO.Params.PNG_Compression := 8;
IO.SaveToFile(OutputFilename, ioPNG); // Save it
Free;
end;
Without an alpha channel, images are spoiled.
example image: https://www.dropbox.com/s/54gcnobsh1r3ugh/image.zip?dl=0
Compilation of Folder-4.png and Folder-5.png without alpha channel I want to get a thumbnail of the original image from the Cover*.* files.
Rudolf |