From 9421ba29cbe52d93e4e595dc2c643ffe6147f5f7 Mon Sep 17 00:00:00 2001 From: Marc Durdin Date: Wed, 2 Nov 2022 12:05:50 +1100 Subject: [PATCH] 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. --- .../src/tike/child/UfrmPackageEditor.pas | 42 +++++++++++++++---- 1 file changed, 33 insertions(+), 9 deletions(-) diff --git a/developer/src/tike/child/UfrmPackageEditor.pas b/developer/src/tike/child/UfrmPackageEditor.pas index a8eee2148a..7c1deba706 100644 --- a/developer/src/tike/child/UfrmPackageEditor.pas +++ b/developer/src/tike/child/UfrmPackageEditor.pas @@ -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;