Einzelnen Beitrag anzeigen

Benutzerbild von toms
toms
(CodeLib-Manager)

Registriert seit: 10. Jun 2002
4.648 Beiträge
 
Delphi XE Professional
 
#7

Re: Typ eines Blob Feldes Ermitteln

  Alt 23. Mai 2010, 06:35
Zitat von himitsu:
Zitat von DrNo:
Frage: Wie kann ich den Grafiktyp einer in einem BLOB gespeicherten
Grafik ermitteln ?
Indem du diese ausließt und analysierst, bzw. analysieren läßt.
Ansatz (ungetestet, unvollständig)

Delphi-Quellcode:
function GetImgFormatFromField(AField: TField): MyImageType;
var
  fldBLOB: TBlobField;
  MemStream: TMemoryStream;
  ImgGraphic: TGraphic;
  imgFormat: array[1..3] of char;
begin
  MyImageType := ImgUnknown;
  if (AField is TBlobField) then
  begin
    fldBLOB := TBlobField(AField);
    if not (fldBLOB.IsNull) then
    begin
      MemStream := TMemoryStream.Create();
      try
        fldBLOB.SaveToStream(MemStream);
        MemStream.Position := 0;
        if (MemStream.Size > 3) then
        begin
          MemStream.Read(imgFormat, 3);
          if (imgFormat[1] = 'B') and (imgFormat[2] = 'M') then
           MyImageType := // BMP
          else if (imgFormat[1] = 'G') and (imgFormat[2] = 'I') and (imgFormat[3] = 'F') then
           MyImageType := // GIF
          else if (imgFormat[1] = #$FF) and (imgFormat[2] = #$D8) and (imgFormat[3] = #$FF) then
           MyImageType := // JPEG
          else if (imgFormat[1] = 'E') and (imgFormat[2] = 'X') and (imgFormat[3] = 'I') then
           MyImageType := // EXIF
          else if (imgFormat[1] = #$D7) and (imgFormat[2] = #$CD) and (imgFormat[3] = #$C6) then
           MyImageType := // WMF
          else
           MyImageType := ImgUnknown// anderes Format
        end;
      finally
        MemStream.Free;
      end;
    end;
  end;
end;
Thomas
  Mit Zitat antworten Zitat