我正在尝试通过将 .jpg 转换为 bmp 然后将其保存到 imagelist1 来将 jpg 加载到 imagelist 中。
从上到下的代码片段。Selectdir 工作和 fileexists 部分工作。这用于加载文件夹中的所有图像。所有图像都以 0.jpg / 1.jpg 等命名。
然后我将 jpg 加载到 tpicture 中。设置 bmp 宽度/高度并使用与 jpg 相同的图像加载 bmp,然后将 bmp 添加到图像列表中。完成后,它应该显示第一张图片 0.jpg
两个问题,首先,如果我这样做,它只会显示 bmp 的一小块区域(左上角),但它是正确的图像。我认为这是由于选项作物。我似乎无法弄清楚如何在运行时使其选择中心?
第二,如果我把
Imagelist1.width := currentimage.width;
Imagelist1.height := currentimage.height;
然后它显示最后一张图片。好像 Imagelist1.GetBitmap()
没用?所以我认为修复任何一个都会很棒!欢呼海啸
procedure TForm1.Load1Click(Sender: TObject);
var
openDialog : TOpenDialog;
dir :string;
MyPicture :TPicture;
currentimage :Tbitmap;
image : integer;
clTrans : TColor;
begin
Image := 0 ;
//lets user select a dir
SelectDirectory(Dir, [sdAllowCreate, sdPerformCreate, sdPrompt],SELDIRHELP);
myPicture :=Tpicture.Create;
currentimage := TBitmap.Create;
//keeps adding images as long as the file path exsist.
//thus comic pages should be renumbed to 0-XX
while FileExists(Dir+'\'+inttostr(image)+'.jpg') do
begin
try
MyPicture.LoadFromFile(Dir+'\'+inttostr(image)+'.jpg'); //load image to jpg holder
currentimage.Width := mypicture.Width; //set width same as jpg
currentimage.Height:= mypicture.Height; //set height same as jpg
currentimage.Canvas.Draw(0, 0, myPicture.Graphic); //draw jpg on bmp
clTrans:=currentimage.TransparentColor; //unknown if needed?
//Imagelist1.Width := currentimage.Width;
//imagelist1.Height := currentimage.Height;
Imagelist1.Addmasked(Currentimage,clTrans); //add to imagelist
finally
image := image +1; //add one so it adds next page
end;
end;
ImageList1.GetBitmap(0,zImage1.Bitmap);
mypicture.Free;
currentimage.Free;
end;