Cargando imágenes a TImageList y leyendolas?
Estoy tratando de cargar jpg en una lista de imágenes convirtiendo el .jpg en un bmp y luego guardándolo en imagelist1.
De arriba a abajo del recorte de código. El Selectdir funciona y funciona el archivo de piezas existentes. Esto se utiliza para cargar en todas las imágenes en una carpeta. Todas las imágenes se denominan así 0.jpg / 1.jpg ect ..
Entonces cargué el jpg a tpicture. Establezca el ancho / alto de bmp y cargue el bmp con la misma imagen que jpg, luego agrego el bmp a la lista de imágenes. Y cuando se hace debe mostrar la primera imagen 0.jpg.
Dos problemas, primero si me gustaba, así solo mostraría un área pequeña (arriba a la izquierda) del bmp pero era la imagen correcta. Supongo que esto se debe a la opción de cultivo. ¿Qué no puedo imaginar cómo hacer que seleccione centro durante el tiempo de ejecución?
Segundo, si pongo
Imagelist1.width := currentimage.width;
Imagelist1.height := currentimage.height;
Luego se muestra la última imagen. me gustaImagelist1.GetBitmap()
¿no funcionó? así que supongo que una solución para cualquiera sería genial! aplausos
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;