fix(developer): support gif preview images in Package Editor

Fixes #6974.

GIF images were not supported in the Details tab, Image file, because we
didn't link in GIF file support. After linking it in, we also needed to
change over the picture rendering to have an intermediate render step,
as the existing model only worked with .bmp images.

At the same time, added warnings for wrongly-sized images to the image
size information.
This commit is contained in:
Marc Durdin 2022-11-02 12:05:50 +11:00
parent cb9649dc4b
commit 9421ba29cb

View file

@ -345,6 +345,7 @@ implementation
uses
Vcl.Clipbrd,
Vcl.Imaging.GifImg,
Keyman.Developer.System.HelpTopics,
@ -1346,28 +1347,51 @@ end;
procedure TfrmPackageEditor.UpdateImagePreviews;
var
filename: WideString;
filename, msg: string;
p: TPicture;
begin
filename := '';
lblKMPImageSize.Caption := '(Unknown image format)';
imgKMPSample.Picture := nil;
if cbKMPImageFile.ItemIndex > 0 then
filename := (cbKMPImageFile.Items.Objects[cbKMPImageFile.ItemIndex] as TPackageContentFile).FileName;
if filename <> '' then
begin
try
imgKMPSample.Picture.LoadFromFile(filename);
lblKMPImageSize.Caption := Format('Image size: (%d x %d)',
[imgKMPSample.Picture.Bitmap.Width, imgKMPSample.Picture.Bitmap.Height]);
p := TPicture.Create;
try
p.LoadFromFile(filename);
if (p.Width = 0) or (p.Height = 0) then
Exit;
imgKMPSample.Picture.Bitmap.SetSize(p.Width, p.Height);
imgKMPSample.Picture.Bitmap.PixelFormat := pf24bit;
imgKMPSample.Picture.Bitmap.Canvas.StretchDraw(imgKMPSample.ClientRect, p.Graphic);
msg := Format('Image size: (%d x %d)', [p.Width, p.Height]);
// Check dimensions and aspect ratio
if Round(100 * p.Width / p.Height) <> 56 then
begin
msg := msg + ' WARNING: image has wrong aspect ratio; should be 140 x 250 pixels';
end
else if (p.Width <> 140) or (p.Height <> 250) then
begin
msg := msg + ' WARNING: image should be 140 x 250 pixels';
end;
finally
p.Free;
end;
lblKMPImageSize.Caption := msg;
except
imgKMPSample.Picture := nil;
lblKMPImageSize.Caption := '(Unknown image format)';
end;
end
else
begin
imgKMPSample.Picture := nil;
lblKMPImageSize.Caption := '(No image)';
end;
end;