Autor Beitrag
FaTaLGuiLLoTiNe
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 200
Erhaltene Danke: 5

Windows 7, Windows 8.1
Delphi XE
BeitragVerfasst: Mi 29.01.03 16:48 
Ich weiss, das Thema gab's schon tausendmal, aber 'ne richtige Lösung hab' ich immer noch nicht gefunden, also ...

Ich will also Bilder in die DB hauen, und ich will keine Pfade speichern, sondern das Bild direkt. Ich will auch nicht die Bilddatei speichern (also kein Umweg über das Filesystem) sondern die Bilddaten. Und ich benutze keine datensensitiven Komponenten (TTable).

Am liebsten wäre mir eine Lösung, mit der ich ein TPicture - Objekt an einen Param übergeben kann und ein TField - Objekt an ein TPicture - Objekt. Ich hab' auch schon alle Varianten von Assign (mit und ohne Typumwandlung) sowie mehrere Möglichkeiten über Streams versucht, aber klappt nicht. Ich war schonmal soweit, dass ich Bitmaps speichern konnte (will aber auch z.B. JPEG), aber das hat auch nicht richtig geklappt und die Pics waren hinterher immer teilweise schwarz.

_________________
<< FaTaLGuiLLoTiNe >>
Rhinoceroses don't play games!
bis11
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 1247
Erhaltene Danke: 2

Apple Mac OSX 10.11

BeitragVerfasst: Mi 29.01.03 17:20 
Hi,

was hälst Du von der TDBImage-Komponente, würde ich jetzt mal ausprobieren.
FaTaLGuiLLoTiNe Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 200
Erhaltene Danke: 5

Windows 7, Windows 8.1
Delphi XE
BeitragVerfasst: Mi 29.01.03 17:24 
Hmmm ... hast du schonmal was von den TMS - Komponenten gehört? Da gibt es eine Thumbnaillist, da würde ich die Pictures gerne zuordnen, aber die enthält leider keine DBImage Komponenten.

Das Problem besteht v.a. deshalb, weil ich die Bilder über 1:n in einer Tabelle habe und deshalb x DBImages zur Laufzeit erstellen müsste.

_________________
<< FaTaLGuiLLoTiNe >>
Rhinoceroses don't play games!
bis11
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 1247
Erhaltene Danke: 2

Apple Mac OSX 10.11

BeitragVerfasst: Mi 29.01.03 18:04 
Die Komponente DBImage ist ja auch direkt von Delphi dabei. Ist in der Spalte Datensteuerung glaube ich.
FaTaLGuiLLoTiNe Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 200
Erhaltene Danke: 5

Windows 7, Windows 8.1
Delphi XE
BeitragVerfasst: Mi 29.01.03 21:25 
ähemm, ja, aber ich kann mit dem teil glaub ich nicht viel anfangen (aus o.g. Gründen) Aber ich werd morgen auf der Arbeit mal n bisserl damit rumspielen und sehen ob ich mit deinem Tip was anfangen kann.

Wenn's mit der DBImage so klappt wie ich mir das vorstelle dann hab' ich die ganze Zeit den Wald vor lauter Bäumen und so ...

_________________
<< FaTaLGuiLLoTiNe >>
Rhinoceroses don't play games!
CenBells
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 1547

Win 7
Delphi XE5 Pro
BeitragVerfasst: Sa 01.02.03 15:38 
Hallo,

ich speicher meine Bilder in einem Blob feld einer db, dazu nutze ich folgenden code

ausblenden volle Höhe 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:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
//------------------------------------------------------------------------------
function updateBlob(AKeyFieldName, AFieldName, ATableName: String;
  AKeyFieldValue: Variant;
  ABlobField: TMemoryStream): boolean;
var
  LTransaction: TIBTransaction;
  LDataset: TIBQuery;
begin
  result := true;
  LTransaction := TIBTransaction.Create(nil);
  try
    LTransaction.DefaultDatabase := DSM_Datamodule.IBDB_DSM;
    LTransaction.Params.add('read_committed');
    LTransaction.Params.add('rec_version');
    LTransaction.Params.add('nowait');
    LTransaction.DefaultAction := TACommit;
    LTransaction.AutoStopAction := saCommit;
    LTransaction.StartTransaction;
    LDataset := TIBQuery.Create(nil);
    LDataset.Database := DSM_Datamodule.IBDB_DSM;
    LDataset.Transaction :=  LTransaction;
    LDataset.SQL.Add('UPDATE ' + ATableName + #13#10 +
      'SET ' + AFieldName + ' = :' + AFieldName + #13#10 +
      'WHERE ' + AKeyFieldName + ' = ' + AKeyFieldValue);
    LDataset.Params[0].DataType := ftBytes;
    ABlobField.Seek(0, soFromBeginning);
    LDataset.Params[0].LoadFromStream(ABlobField, ftBlob);
    LDataset.Prepare;
    try
      LDataset.ExecSQL;
    except
      result := false;
    end;
  finally
    if assigned(LDataset) then begin
      if assigned(LTransaction) then begin
        LTransaction.Commit;
        LTransaction.Free;
      end;
      FreeAndNil(LDataset);
    end;
  end;
end;

//Beispiel aufruf
var
  LMemoryStream: TMemoryStream;
begin
//hier muss überprüfung stattfinden, ob es den Datensatz schon gibt ansonsten mit insert anlegen

  LMemoryStream := TMemoryStream.Create;
  try
    vImage.Picture.Graphic.SaveToStream(LMemoryStream);
    updateBlob('Name', 'MeinFeld', 'MeineTabelle',
      cbStrToSQLStr(meinBezeichner), LMemoryStream);
  finally
    FreeAndNil(LMemoryStream);
  end;
end;


Ein bild lade ich mit folgendem aufruf

ausblenden Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
//------------------------------------------------------------------------------
function TCBRechnung.getHeaderImage(AFieldName, ATableName, Identifier: String: TImage;
var
  LQuery: TIBQuery;
begin
  result := TImage.Create(self);
  LQuery := getQuery('SELECT ' + AFieldName + 'FROM ' +ATableName + #13#10 +
    'WHERE Name = ' + cbStrToSQLStr(Identifier));
  if assigned(LQuery) then
  try
    if not LQuery.FieldByName(AFieldName).IsNull then
      result.Picture.Assign(Lquery.FieldByName(AFieldName ));
  finally
    FreeAndNil(LQuery);
  end;
end;



Ich hoffe, das hilft dir.

Gruß
Ken
FaTaLGuiLLoTiNe Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 200
Erhaltene Danke: 5

Windows 7, Windows 8.1
Delphi XE
BeitragVerfasst: Fr 07.02.03 10:33 
DAS sieht aus als könnte es mir tatsächlich helfen.

Ich kann das leider gerade nicht ausprobieren, da ich zwischenzeitlich an einem anderen (kleinen) Projekt sitze; ich meld' mich aber nochmal wenn ich es getestet habe.

Schonmal fetten Dank!
FaTaLGuiLLoTiNe Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 200
Erhaltene Danke: 5

Windows 7, Windows 8.1
Delphi XE
BeitragVerfasst: Mi 12.02.03 12:58 
Titel: Fortschritt !!!
Super !

Ich habe mir jetzt folgende Funktionen, inspiriert durch Deinen Quelltext, zusammengebastelt:

ausblenden Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
procedure AssignPictureToParam(Source: TPicture; Target: TParam);
var MStream : TMemoryStream;
begin
  MStream := TMemoryStream.Create;
  try
   Source.Graphic.SaveToStream(MStream);
   Target.DataType := ftBytes;
   MStream.Seek(0, soFromBeginning);
   Target.LoadFromStream(MStream, ftBlob);
  finally
   FreeAndNil(MStream);
  end;
end;

procedure AssignFieldToPicture(Source: TField; var Target: TPicture);
begin
  Target.Assign(TPicture(Source));
end;


Das klappt auch jetzt alles ganz gut, allerdings nur mit Bitmaps, obwohl TPicture / TGraphic ja eigentlich auch JPEGs können sollten, oder?!?

Was läuft hier jetzt noch schief?
gasser
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 51

W7
Delphi XE
BeitragVerfasst: Mi 07.05.03 06:41 
Hast Du in der USES Clause JPEG eingetragen?