Delphi-PRAXiS
Seite 1 von 2  1 2      

Delphi-PRAXiS (https://www.delphipraxis.net/forum.php)
-   Multimedia (https://www.delphipraxis.net/16-multimedia/)
-   -   Delphi JPEG-Fehler: #41 (https://www.delphipraxis.net/16135-jpeg-fehler-41-a.html)

clues1 11. Feb 2004 09:10


JPEG-Fehler: #41
 
Hi, habe folgendes Problem:

Ich öffne Bilder, mit TImage.
Dann lade ich das bild in ein TJPEGImage ein.
> jpg.assign(Image.Picture.Graphic);
dieses JPG speichere ich in ein FileStream.
> jpg.savetofilestream(fs);

Nun will ich diese Datei wieder laden.
> jpg.loadfromfilestream(fs);
Das Funktioniert auch.
Wenn ich das Bild ins Image wieder lade funkt das auch.
> img.picture.assign(jpg);
Manchmal kommt aber hier an der Stelle folgende Meldung:
"JPEG-Fehler: #41" Vorallem wenn ich in der Datei mehr als ein Bild mit FileStream Speichere.

was könnte das sein?

clues1 11. Feb 2004 10:57

Re: JPEG-Fehler: #41
 
Ich nochmal.
Ich habe noch ein bissel rum probiert.
wenn ich das gleiche mit TBitmap mache funktioniert das super.
Leider nicht mit JPEG. Nur das Erste Bild wird ordentlich geladen. Ich will mehrere Bilder in eine Datei per FS speichern aber die Bilder so stark wie möglich Komprimieren.
Kann das sein das JPEGImage ein Bug hat?

dizzy 11. Feb 2004 13:08

Re: JPEG-Fehler: #41
 
Hi! Willkommen in der DP! (Delphi-Groups reichen net mehr? ;) )

Ein kleiner Auszug aus dem BDN:

Zitat:

If you have used the TJpegImage class you may be familiar with the "JPEG error #xx" error that comes up on occasion. You may want to know exactly what went wrong, and how to get more information based on that number.

Luckily, the TJpegImage pascal source is included on the Delphi CD. Looking at the source, you will notice that it is a wrapper around some C code. There is one particular file called "jerror.h" which contains an enumeration of error strings. Based on the offset in this enum, you can find out what a given error number means.

For ease of use, I converted the "jerror.h" file to pascal in the unit JpegErrors.pas. To use this unit, simply reference the string array cJpegErrors, passing a given error number to find the error string, such as:

Label1.Caption := cJpegErrors[StrToInt(Edit1.Text)]
Note that the JpegErrors.pas unit was based on the Jpeg source that comes with Delphi 5. If the order of the error messages in "jerror.h" ever changes, the JpegErrors.pas will not by in sync with it and has to be updated.

Dann findest du zu mindest heraus, was das für ein Fehler ist.
Alternativ könnte man mit Resourcen arbeiten. Die lassen sich, so wie ich das mal las, auch nachträglich zur Laufzeit modifizieren. Wie genau, müsste bei Bedarf gesucht werden. Ich will nix falsches sagen :)


gruss,
dizzy

clues1 11. Feb 2004 13:54

Re: JPEG-Fehler: #41
 
Zitat:

Hi! Willkommen in der DP! (Delphi-Groups reichen net mehr? )
hi ich habe mir gedacht, wenn ich hier noch frage ist die chance zum lösen höher.

Mein Quellcode funktioniert mit TBitmap und TPNGObject, aber nicht mit TJPEGImage :wiejetzt: .
Wenn ich die Bilder Speichere und wieder lade, läd der bei JPEG mittels LoadFromStream nur das erste Bild, danach bringt der bei jedem weiteren Bild eine Fehlermeldung (siehe oben). Ich kann mir das erste Bild anzeigen lassen aber die anderen nicht :gruebel: . Ich habe dann einfach mal TJPEGImage mit TPNGObject überschrieben, das funktioniert auch, sowie TBitmap.
Ich möchte aber die Foto-Bilder nicht mit PNG speichern, da Sie je größer sind.
:wall: .
Danke erstmal für dein Tipp, folgende Text gibt es mir aus "Empty input file". Ah das bild exisitiert nicht im Speicher, toll warum läd der das nicht aus/ins Stream?
:wall: :wall: :wall:

clues1 12. Feb 2004 07:21

Re: JPEG-Fehler: #41
 
@all

Problem habe ich nun gelöst:

Code:
function LoadJPGFromStream(FS: TFileStream; var JPG: TJPEGImage): boolean;
var MS: TMemoryStream;
    s: Cardinal;
    offset: cardinal;
begin
  MS := TMemoryStream.Create;

  FS.ReadBuffer(S, sizeof(s));
  offset := FS.Position;

  JPG.LoadFromStream(FS);
  FS.Position := offset + s;

  MS.free;
end;

function SaveJPGToStream(FS: TFileStream; JPG: TJPEGImage): boolean;
var MS: TMemoryStream;
    s: Cardinal;
begin
  MS := TMemoryStream.Create;

  JPG.SaveToStream(MS);
  s := MS.Size;

  FS.WriteBuffer(S, sizeof(s));
  JPG.SaveToStream(FS);

  MS.free;
end;
Ich habe nun diese 2 Funktionen zu speichern und lesen von JPEGImages erstellt.
Das Problem in JPEGImage liegt daran, das LoadFromStream immer zum ende des Streams springt.

clues1 12. Feb 2004 07:21

Re: JPEG-Fehler: #41
 
@all

Problem habe ich nun gelöst:

Code:
function LoadJPGFromStream(FS: TFileStream; var JPG: TJPEGImage): boolean;
var MS: TMemoryStream;
    s: Cardinal;
    offset: cardinal;
begin
  MS := TMemoryStream.Create;

  FS.ReadBuffer(S, sizeof(s));
  offset := FS.Position;

  JPG.LoadFromStream(FS);
  FS.Position := offset + s;

  MS.free;
end;

function SaveJPGToStream(FS: TFileStream; JPG: TJPEGImage): boolean;
var MS: TMemoryStream;
    s: Cardinal;
begin
  MS := TMemoryStream.Create;

  JPG.SaveToStream(MS);
  s := MS.Size;

  FS.WriteBuffer(S, sizeof(s));
  JPG.SaveToStream(FS);

  MS.free;
end;
Ich habe nun diese 2 Funktionen zu speichern und lesen von JPEGImages erstellt.
Das Problem in JPEGImage liegt daran, das LoadFromStream immer zum ende des Streams springt.

Luckie 12. Feb 2004 07:23

Re: JPEG-Fehler: #41
 
Ich vermisse eine Ressourcen-Schutzblock mit try-finally.

clues1 12. Feb 2004 08:05

Re: JPEG-Fehler: #41
 
habe ich nun gemacht siehe hier:
http://www.delphi-groups.de/YaBBSe/i...threadid=18990

dizzy 13. Feb 2004 01:55

Re: JPEG-Fehler: #41
 
Zitat:

Zitat von clues1
Das Problem in JPEGImage liegt daran, das LoadFromStream immer zum ende des Streams springt.

Also auf DIE Idee wär ich jetzt nicht gekommen (keine Ironie!!!). Das ist in der Tat böse. Und das ist NIRGENDWO dokumentiert!? Höftig...

Aber gut, dass ich jetzt weiss wo ich suchen muss, denn ich progge auch recht häufig an Grafiksachen mit jpegs rum :mrgreen:

gruss,
dizzy

PS: Dass DragonsLear diesen Thread noch nicht gefunden, und den auf DG geschlossen hat... :gruebel:

clues1 13. Feb 2004 06:37

Re: JPEG-Fehler: #41
 
schön freut mich das das nicht nur mir Hilf, sondern auch andere.
:-D


Alle Zeitangaben in WEZ +1. Es ist jetzt 08:36 Uhr.
Seite 1 von 2  1 2      

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024 by Thomas Breitkreuz