Delphi-PRAXiS

Delphi-PRAXiS (https://www.delphipraxis.net/forum.php)
-   Multimedia (https://www.delphipraxis.net/16-multimedia/)
-   -   D5 + GraphicEx - .jpg will nicht (https://www.delphipraxis.net/176228-d5-graphicex-jpg-will-nicht.html)

miriki 20. Aug 2013 20:47

D5 + GraphicEx - .jpg will nicht
 
Moinsens!

Ich versuche gerade, ein (mehr oder weniger beliebiges) Bild zu erzeugen / laden, es (ggf. ausschnittsweise) auf ein anderes zu kopieren und das Ergebnis dann auf einem Form anzuzeigen.

Der erste Versuch mit .bmp verlief soweit ganz gut, aber ich brauchte ein paar mehr Formate, als mein altes Delphi 5 hergeben wollte. Und ich wollte mir Code-Weichen je nach Bildformat gerne sparen. GraphicEx schien da ein guter Weg zu sein.

Nach Einbinden der GraphicEx-Unit klappte es auch auf Anhieb mit .png und .pcx Grafiken. Und eine kleine Änderung in der Konfiguration ermöglichte dann auch .gif Bilder. (Weitere Formate habe ich bislang nicht getestet.)

Was ich aber auf Teufel komm raus nicht hinbekomme: .jpg Bilder - die resultieren in einem leeren Image.

Die "Kern"-Routine aus einem Test-Projekt:
Code:
procedure tform1.loadimage( f:string );
var
  src_image: timage;
  src_picture: tpicture;
  src_graphic: tgraphic;
  src_bitmap: tbitmap;
  src_canvas: tcanvas;
  src_x1, src_y1, src_x2, src_y2: integer;
  src_rect: trect;
  mid_image: timage;
  mid_picture: tpicture;
  mid_graphic: tgraphic;
  mid_bitmap: tbitmap;
  mid_canvas: tcanvas;
  mid_x1, mid_y1, mid_x2, mid_y2: integer;
  mid_rect: trect;
  dst_image: timage;
  dst_picture: tpicture;
  dst_graphic: tgraphic;
  dst_bitmap: tbitmap;
  dst_canvas: tcanvas;
  dst_x1, dst_y1, dst_x2, dst_y2: integer;
  dst_rect: trect;
begin
  if ( f <> '' ) then begin

    // ------------------------------------------------------------
    // image used to display the combined image on a form
    // (centered and stretched)
    // ------------------------------------------------------------
    dst_image := gfx_image;
    dst_picture := dst_image.picture;
    //dst_graphic := dst_picture.graphic;
    //dst_bitmap := dst_picture.bitmap;
    //dst_canvas := dst_bitmap.canvas;
    //dst_x1 := 0;
    //dst_y1 := 0;
    //dst_x2 := gfx_image.width - 1;
    //dst_y2 := gfx_image.height - 1;
    //dst_rect := rect( dst_x1, dst_y1, dst_x2, dst_y2 );

    // ------------------------------------------------------------
    // load the desired image
    // ------------------------------------------------------------
    src_picture := tpicture.create;
    src_picture.loadfromfile( f );
    //src_graphic := src_picture.graphic;
    src_bitmap := src_picture.bitmap;
    src_canvas := src_bitmap.canvas;
    src_x1 := 0;
    src_y1 := 0;
    src_x2 := src_bitmap.width - 1;
    src_y2 := src_bitmap.height - 1;
    src_rect := rect( src_x1, src_y1, src_x2, src_y2 );

    // ------------------------------------------------------------
    // prepare a canvas to hold the loaded image
    // ------------------------------------------------------------
    mid_picture := tpicture.create;
    //mid_graphic := mid_picture.graphic;
    mid_bitmap := mid_picture.bitmap;
    mid_bitmap.width := src_bitmap.width + 200;
    mid_bitmap.height := src_bitmap.height + 200;
    mid_canvas := mid_bitmap.canvas;
    mid_x1 := 100;
    mid_y1 := 100;
    mid_x2 := mid_x1 + ( src_x2 - src_x1 );
    mid_y2 := mid_y1 + ( src_y2 - src_y1 );
    mid_rect := rect( mid_x1, mid_y1, mid_x2, mid_y2 );

    // ------------------------------------------------------------
    // copy the loaded image onto the prepared canvas
    // ------------------------------------------------------------
    mid_canvas.copyrect( mid_rect, src_canvas, src_rect );

    // ------------------------------------------------------------
    // assign the combined image to the image on the form
    // ------------------------------------------------------------
    dst_picture.assign( mid_bitmap );

  end;
end;
Vielleicht kann mir hier jemand sagen, was ich für .jpg anpassen muß...

Was ich letztendlich brauche, sofern es für die Anpassung relevant ist:
a) Das Original des aus der Datei geladenen Bildes im Speicher, nicht zugeschnitten, skaliert oder sonstwas. Das Bild liegt wahrscheinlich im Bereich von 800x600 bis 1920x1080.
b) Das Original des Canvas, auf dem sich eine Kopie des Bildes aus a) befindet. Das Ding kann auch schon leicht mal 4000x4000 groß werden. Dieser Canvas muß als .bmp speicherbar sein.
c) eine Darstellung von b) auf dem Form, wobei die Breite vorgegeben ist (align:bottom) und ich die Höhe anpasse, damit das Seitenverhältnis von b) erhalten bleibt.
... und a) ist im eigentlichen Projekt ein Array aus mehreren (z.Z. bis zu 8) Bildern.

Gruß, Michael

baumina 26. Aug 2013 08:38

AW: D5 + GraphicEx - .jpg will nicht
 
Delphi-Quellcode:
uses JPEG;
Vielleicht hilft dir das ja weiter.

miriki 28. Aug 2013 19:30

AW: D5 + GraphicEx - .jpg will nicht
 
Zitat:

Zitat von baumina (Beitrag 1226192)
Delphi-Quellcode:
uses JPEG;
Vielleicht hilft dir das ja weiter.

Leider nein... Das hatte ich schon versucht und es brachte keinen Unterschied. Das dürfte aber auch daran liegen, das GraphicEx selbst bereits JPEG eingebunden hat.

Sofern ich das beim flüchtigen Lesen verstanden habe, gab's früher mal eine separate JPG-Unit (also ohne "E") mit GraphicEx, aber neuere Versionen benutzen jetzt die "standard" JPEG Unit.

Gruß, Michael

miriki 8. Sep 2013 11:03

AW: D5 + GraphicEx - .jpg will nicht
 
Moinsens!

Hat denn sonst keiner eine Idee?

Vielleicht mag sich ja mal jemand das Test-Projekt ansehen und speziell auf .jpg testen...

projekt1.zip

Da sind 5 Beispiel-Bilder 1920x1080 als .bmp, .png, .pcx, .gif und .jpg dabei. Beim Start lädt es das .bmp und per Klick auf das tImage kommt der Öffnen-Dialog. In der Vorschau des Öffnen-Dialogs wird das .jpg übrigens auch noch korrekt angezeigt (das .pcx übrigens nicht...), aber nach der Verarbeitung des .jpg bleibt das tImage leer.

Gruß, Michael

PS: Ach so, die verwendete GraphicEx hat im Header u.a.:
Delphi-Quellcode:
// (C) 1999-2003 Dipl. Ing. Mike Lischke. All Rights Reserved.
[ ... ]
// version - 9.9
//
// 03-SEP-2000 ml:


Alle Zeitangaben in WEZ +1. Es ist jetzt 15:45 Uhr.

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