Autor Beitrag
Tabakbrummel
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 124

win 7
Turbo Delphi, VS 20010 Express
BeitragVerfasst: Mi 24.01.07 23:19 
Hallo

Mein Problem ist lade ein PNG Bild im Image und will es über edit mit neuen Namen BMP speichen da kommt die Excepion( Exception-Klasse GIFException mit Meldung 'Invalid GIF signature). Und wenn ich ein Gif Bild in BMP Speicher kommt die Exception(EPNGInvalidFileHeader mit Meldung 'The file being readed is not a valid "Portable Network Graphics" image because it contains an invalid header. This file may be corruped, try obtaining it again). Was mache ich Falsch?


ausblenden Delphi-Quelltext
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:
procedure TForm4.Button2Click(Sender: TObject);
var
  GIF: TGIFImage;
  PNG: TPNGObject;
  BMP: TBitmap;
begin
  GIF := TGIFImage.Create;
  PNG := TPNGObject.Create;
try
  GIF.LoadFromFile(Form4.OpenPictureDialogKarte.FileName);
  PNG.LoadFromFile(Form4.OpenPictureDialogKarte.FileName);
  BMP := TBitmap.Create;
    try
      BMP.Assign(GIF);
      BMP.Assign(PNG);
      Path := ExtractFilePath(Application.ExeName)+'Karten\'+ Edit1.Text + '.bmp';
      BMP.SaveToFile(Path);
    finally
      BMP.Free;
    end;
finally
  GIF.Free;
  PNG.Free;
end;
  DM.Faenge.Edit;
  DM.Faenge.FieldByName('Karten').AsString := (Path);
  DM.Faenge.Post;
  FileListBox1.Update;
  Edit1.Clear;
end;


Moderiert von user profile iconGausi: Code- durch Delphi-Tags ersetzt

_________________
MfG
Tabakbrummel
Robinator
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 275

WinXP
BDS 2006
BeitragVerfasst: Mi 24.01.07 23:22 
Du lädst in die PNG und GIF Variablen die gleiche Datei. Da diese aber nur eins von beiden Formaten haben kann, ist es logisch, dass dir das jedemal ne execption wirft. Du musst also erstmal unterscheiden, um welches Dateiformat es sich handelt (stichwort ExtractFileExt), oder aber eine abstrakte Grafikklasse nehmen, die dir das abnimmt.

Gruss, Rob
Tabakbrummel Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 124

win 7
Turbo Delphi, VS 20010 Express
BeitragVerfasst: Mi 24.01.07 23:33 
Hallo Robinator

Mit denn ExtractFileExt komm ich nicht klar. Habe auch schon in der OH gesehen da sehe ich auch nur Bahnhof. Und was meinst du mit abstrakte Grafikklasse?

_________________
MfG
Tabakbrummel
Robinator
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 275

WinXP
BDS 2006
BeitragVerfasst: Do 25.01.07 00:01 
Wieso kommst du denn mit ExtractFileExt nicht klar? Das gibt dir einfach nur die dateiendung einer kompletten Pfadangabe zurück. ExtractFileExt('C:\MyBitmap.bmp') gibt dir beispielsweise .bmp zurück. Dadurch kannst du auf einfache Weise überprüfen, um welches Format es sich handelt.
Mit Abstrakter Grafikklasse meine ich ansich genau das was ich sage, guck dir doch mal TPicture bzw. TGraphic und die GraphicEX unit von Mike Lischke an.

gruss
Tabakbrummel Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 124

win 7
Turbo Delphi, VS 20010 Express
BeitragVerfasst: Do 25.01.07 00:48 
Hallo Robinator

Erst mal vielen Dank für deine Antworten. Ich habe die Komponente GraphicEx genommen und es funktioniert.

_________________
MfG
Tabakbrummel