1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25: 26: 27: 28: 29: 30: 31: 32: 33: 34: 35: 36: 37: 38: 39: 40: 41: 42: 43: 44: 45: 46: 47: 48: 49: 50: 51: 52: 53: 54: 55: 56: 57: 58: 59: 60: 61: 62: 63: 64: 65: 66: 67: 68: 69: 70: 71: 72: 73: 74: 75: 76: 77: 78: 79: 80: 81: 82: 83: 84: 85: 86: 87: 88: 89: 90: 91: 92: 93: 94: 95: 96: 97: 98: 99: 100: 101: 102: 103: 104: 105: 106: 107: 108: 109: 110: 111: 112: 113: 114: 115: 116: 117:
| function JPEGDimensions(Filename : string; var X, Y : Word) : boolean; var SegmentPos : Integer; SOIcount : Integer; b : byte; begin Result := False; with TFileStream.Create(Filename, fmOpenRead or fmShareDenyNone) do begin try Position := 0; Read(X, 2); if (X <> $D8FF) then exit; SOIcount := 0; Position := 0; while (Position + 7 < Size) do begin Read(b, 1); if (b = $FF) then begin Read(b, 1); if (b = $D8) then inc(SOIcount); if (b = $DA) then break; end; end; if (b <> $DA) then exit; SegmentPos := -1; Position := 0; while (Position + 7 < Size) do begin Read(b, 1); if (b = $FF) then begin Read(b, 1); if (b in [$C0, $C1, $C2]) then begin SegmentPos := Position; dec(SOIcount); if (SOIcount = 0) then break; end; end; end; if (SegmentPos = -1) then exit; if (Position + 7 > Size) then exit; Position := SegmentPos + 3; Read(Y, 2); Read(X, 2); X := Swap(X); Y := Swap(Y); Result := true; finally Free; end; end; end;
procedure SetImgList(SourceJPG:String;IL:TImageList); var MyJPEG : TJPEGImage; x,y:word; MyBMP : TBitmap; begin MyJpeg := TJpegImage.Create; try MyJpeg.LoadFromFile(SourceJPG); MyBmp := TBitmap.Create; try JPEGDimensions(SourceJPG,x,y); MyBmp.Width := 100; MyBmp.Height:= 100; if x>y then begin MyBmp.Canvas.StretchDraw(Rect(0,0,100,80),MyJpeg); end else begin MyBmp.Canvas.StretchDraw(Rect(0,0,80,100),MyJpeg); end; IL.Add(MyBmp,MyBmp); except ON E: exception do MessageBox(0,PChar(E.Message),'',mb_Ok); end; finally MyJpeg.Free; end; end;
procedure TForm1.FileListBox1Change(Sender: TObject); var i:integer; begin Screen.Cursor:=crHourGlass; ImageList1.Clear; ListView1.Items.Clear;
for i:=0 to filelistbox1.Items.Count-1 do begin SetImgList(filelistbox1.Items.Strings[i],ImageList1); ListView1.Items.Add.Caption:=filelistbox1.Items.Strings[i]; ListView1.Items.Item[i].ImageIndex:=i; ListView1.Update; end; Screen.Cursor:=crDefault; end;
procedure TForm1.Button1Click(Sender: TObject); begin ShowMessage('Imagelist count: '+inttostr(ImageList1.Count)); end;
procedure TForm1.ListView1Change(Sender: TObject; Item: TListItem; Change: TItemChange); begin if ListView1.Selected<>nil then begin FileListBox1.Selected[ListView1.Selected.Index]:=True; end; end; |