AGB  ·  Datenschutz  ·  Impressum  







Anmelden
Nützliche Links
Registrieren
Thema durchsuchen
Ansicht
Themen-Optionen

Array of Integer und crash

Ein Thema von EWeiss · begonnen am 19. Mär 2017 · letzter Beitrag vom 27. Sep 2018
 
TiGü

Registriert seit: 6. Apr 2011
Ort: Berlin
3.074 Beiträge
 
Delphi 10.4 Sydney
 
#33

AW: Array of Integer und crash

  Alt 27. Sep 2018, 09:29
Ok ist erledigt Danke.

Es scheint wohl kein Fehler in der Winapi.GDIPAPI vorzuliegen.

Habe mal meine beiden Versionen 32 und 64 Bit gegengeprüft.

Bei 32 Bit ohne "var" stürzt die Anwendung ab. (D2010)
Bei 64 Bit mit "var" genauso. (DX)
----------------------------------------------
Bei 32 Bit mit var funktioniert alles. (D2010)
Bei 64 Bit ohne var auch. (DX)

Unverständlich warum es hier unterschiede gibt.
Wahrscheinlich vertust du dich beim Holen der einzeln Items sowie der vorigen Speicherreservierung, dass macht schnell den Stack kaputt und man hat merkwürdige Fehler.
Anbei ein Testprojekt als ZIP-Archiv und Quelltext, mit dem du nachvollziehen kannst, wie es in 32- und 64-Bit funktioniert.

Delphi-Quellcode:
unit Unit4;

interface

uses
  Winapi.Windows, System.SysUtils, System.Classes,
  Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.StdCtrls, Vcl.ExtDlgs;

type
  TForm4 = class(TForm)
    Memo1: TMemo;
    OpenPictureDialog1: TOpenPictureDialog;
    procedure Memo1Click(Sender: TObject);
  private
    procedure ShowExifInfos(const AFileName: string);
    procedure LogToMemo(AText: string);
  end;

var
  Form4: TForm4;

implementation

uses
  Winapi.ActiveX,
  Winapi.GDIPAPI,
  Winapi.GDIPOBJ,
  Winapi.GDIPUTIL;

{$R *.dfm}

procedure GetExifInfo(const AFileName: string; const CommonExifProperties: TArray<PROPID>; const ALogCallback: TProc<string>);
var
  Image: TGPBitmap;
  PropSize: UINT;
  PropItemPtr: PPropertyItem;
  MyPropID: PROPID;
  MyStatus: Status;
  LogMsg: string;
begin
  Image := TGPBitmap.Create(AFileName);
  try
    if (Image.GetWidth <> 0) and (Image.GetHeight <> 0) then
    begin
      for MyPropID in CommonExifProperties do
      begin
        PropSize := Image.GetPropertyItemSize(MyPropID);
        if PropSize > 0 then
        begin
          GetMem(PropItemPtr, PropSize);
          try
            MyStatus := Image.GetPropertyItem(MyPropID, PropSize, PropItemPtr);
            if MyStatus = Status.Ok then
            begin
              LogMsg := 'Exif-Property: ' + GetMetaDataIDString(PropItemPtr.id) +
                ' with PropSize: ' + PropItemPtr.length.ToString +
                ' and data type: ' + ValueTypeFromULONG(PropItemPtr.type_);

              if Assigned(ALogCallback) then
              begin
                ALogCallback(LogMsg)
              end;
            end;
          finally
            FreeMem(PropItemPtr, PropSize);
          end;
        end;
      end;
    end;
  finally
    Image.Free;
  end;
end;

procedure TForm4.LogToMemo(AText: string);
begin
  Memo1.Lines.Add(AText);
end;

procedure TForm4.Memo1Click(Sender: TObject);
var
  MyFileName: string;
begin
  OpenPictureDialog1.Filter := '*.jpg; *.jpeg';
  if OpenPictureDialog1.Execute(Self.Handle) then
  begin
    MyFileName := OpenPictureDialog1.FileName;
    LogToMemo('Öffne Datei ' + MyFileName + sLineBreak);
    ShowExifInfos(MyFileName);
    LogToMemo(sLineBreak + 'Fertig!');
  end;
end;

procedure TForm4.ShowExifInfos(const AFileName: string);
var
  CommonExifProperties: TArray<PROPID>;
begin
  CommonExifProperties := [
    PropertyTagExifAperture
      , PropertyTagExifBrightness
      , PropertyTagExifCfaPattern
      , PropertyTagExifColorSpace
      , PropertyTagExifCompBPP
      , PropertyTagExifCompConfig
      , PropertyTagExifDTDigitized
      , PropertyTagExifDTDigSS
      , PropertyTagExifDTOrig
      , PropertyTagExifDTOrigSS
      , PropertyTagExifDTSubsec
      , PropertyTagExifExposureBias
      , PropertyTagExifExposureIndex
      , PropertyTagExifExposureProg
      , PropertyTagExifExposureTime
      , PropertyTagExifFileSource
      , PropertyTagExifFlash
      , PropertyTagExifFlashEnergy
      , PropertyTagExifFNumber
      , PropertyTagExifFocalLength
      , PropertyTagExifFocalResUnit
      , PropertyTagExifFocalXRes
      , PropertyTagExifFocalYRes
      , PropertyTagExifFPXVer
      , PropertyTagExifInterop
      , PropertyTagExifISOSpeed
      , PropertyTagExifLightSource
      , PropertyTagExifMakerNote
      , PropertyTagExifMaxAperture
      , PropertyTagExifMeteringMode
      , PropertyTagExifOECF
      , PropertyTagExifPixXDim
      , PropertyTagExifPixYDim
      , PropertyTagExifRelatedWav
      , PropertyTagExifSceneType
      , PropertyTagExifSensingMethod
      , PropertyTagExifShutterSpeed
      , PropertyTagExifSpatialFR
      , PropertyTagExifSpectralSense
      , PropertyTagExifSubjectDist
      , PropertyTagExifSubjectLoc
      , PropertyTagExifUserComment
      , PropertyTagExifVer
    ];

  GetExifInfo(AFileName, CommonExifProperties, LogToMemo);
end;

end.
Angehängte Dateien
Dateityp: zip Project5_2018-09-27_10-25-46.zip (5,5 KB, 3x aufgerufen)
  Mit Zitat antworten Zitat
 


Forumregeln

Es ist dir nicht erlaubt, neue Themen zu verfassen.
Es ist dir nicht erlaubt, auf Beiträge zu antworten.
Es ist dir nicht erlaubt, Anhänge hochzuladen.
Es ist dir nicht erlaubt, deine Beiträge zu bearbeiten.

BB-Code ist an.
Smileys sind an.
[IMG] Code ist an.
HTML-Code ist aus.
Trackbacks are an
Pingbacks are an
Refbacks are aus

Gehe zu:

Impressum · AGB · Datenschutz · Nach oben
Alle Zeitangaben in WEZ +1. Es ist jetzt 02:28 Uhr.
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024-2025 by Thomas Breitkreuz