Autor Beitrag
Stevie
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 85

Windows 7
Delphi XE Professional
BeitragVerfasst: Mo 14.07.03 12:01 
Hallo,

gibt es eine andere (und bessere) Möglichkeit, ein Bitmap in ein RXRichEdit einzufügen, als folgende?
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
Bitmap := TBitmap.Create;
ImageList.GetBitmap(0, Bitmap);
Bitmap.SaveToClipboardFormat(Format, Data, Palette);
ClipBoard.SetAsHandle(Format, Data);
RxRichEdit.PasteFromClipboard;
Jebaz
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 44

Win NT 4, Win XP, Linux
Delphi 7.0
BeitragVerfasst: Fr 26.09.03 13:10 
Titel: ja gibt es
halli hallo, ich hab ne ewigkeit nach dieser möglichkeit gesuscht und hab dann eine bisschen aufwändigere lösung gefunde ;-)

um nichts zu vergessen hab ich alles gleich in eine eigene Unit gepackt, damit dein programm auch ein bisschen übersichtlich bleibt ;-)

ausblenden volle Höhe 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:
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:
60:
61:
62:
63:
64:
65:
66:
67:
68:
69:
70:
71:
72:
73:
74:
75:
76:
77:
78:
79:
80:
81:
82:
83:
84:
85:
86:
87:
88:
89:
90:
91:
92:
93:
94:
95:
96:
97:
98:
99:
100:
101:
102:
103:
104:
105:
106:
107:
108:
109:
110:
111:
112:
113:
114:
115:
116:
117:
118:
119:
120:
121:
122:
123:
124:
125:
126:
127:
128:
129:
130:
131:
132:
133:
134:
135:
unit InsBitmap_Unit;

interface

uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, ExtCtrls, Buttons, abfComponents, StdCtrls, ComCtrls, Menus,
  ScktComp, ExtActns, ActnList, StdActns, IniFiles, TransparentWnd, JvRichEd;

// Stream Callback function
type
  TEditStreamCallBack = function(dwCookie: Longint; pbBuff: PByte;
    cb: Longint; var pcb: Longint): DWORD;
  stdcall;

  TEditStream = record
    dwCookie: Longint;
    dwError: Longint;
    pfnCallback: TEditStreamCallBack;
  end;

// RichEdit Type
type
  TMyRichEdit = TJvxRichEdit;
  //Dies kann auch die normale TRichEdit von Delphi sein, funktioniert mit beiden

function BitmapToRTF(pict: TBitmap): string;
procedure PutRTFSelection(RichEdit: TMyRichEdit; SourceStream: TStream);

implementation

uses 
  RichEdit;



// EditStreamInCallback callback function
function EditStreamInCallback(dwCookie: Longint; pbBuff: PByte;
  cb: Longint; var pcb: Longint): DWORD; stdcall;
  // by P. Below
var
  theStream: TStream;
  dataAvail: LongInt;
begin
  theStream := TStream(dwCookie);
  with theStream do
  begin
    dataAvail := Size - Position; 
    Result := 0; 
    if dataAvail <= cb then 
    begin 
      pcb := read(pbBuff^, dataAvail); 
      if pcb <> dataAvail then 
        Result := UINT(E_FAIL); 
    end 
    else 
    begin
      pcb := read(pbBuff^, cb); 
      if pcb <> cb then 
        Result := UINT(E_FAIL); 
    end; 
  end; 
end; 

// Insert Stream into RichEdit 
procedure PutRTFSelection(RichEdit: TMyRichEdit; SourceStream: TStream);
  // by P. Below
var 
  EditStream: TEditStream; 
begin 
  with EditStream do 
  begin 
    dwCookie := Longint(SourceStream); 
    dwError := 0; 
    pfnCallback := EditStreamInCallBack; 
  end; 
  RichEdit.Perform(EM_STREAMIN, SF_RTF or SFF_SELECTION, Longint(@EditStream));
end; 

// Convert Bitmap to RTF Code 
function BitmapToRTF(pict: TBitmap): string; 
// by D3k 
var 
  bi, bb, rtf: string; 
  bis, bbs: Cardinal; 
  achar: ShortString; 
  hexpict: string;
  I: Integer; 
begin 
  GetDIBSizes(pict.Handle, bis, bbs); 
  SetLength(bi, bis); 
  SetLength(bb, bbs); 
  GetDIB(pict.Handle, pict.Palette, PChar(bi)^, PChar(bb)^); 
  rtf := '{\rtf1 {\pict\dibitmap '; 
  SetLength(hexpict, (Length(bb) + Length(bi)) * 2); 
  I := 2; 
  for bis := 1 to Length(bi) do
  begin 
    achar := Format('%x', [Integer(bi[bis])]); 
    if Length(achar) = 1 then 
      achar := '0' + achar; 
    hexpict[I - 1] := achar[1]; 
    hexpict[I] := achar[2]; 
    Inc(I, 2); 
  end;
  for bbs := 1 to Length(bb) do 
  begin 
    achar := Format('%x', [Integer(bb[bbs])]); 
    if Length(achar) = 1 then 
      achar := '0' + achar;
    hexpict[I - 1] := achar[1]; 
    hexpict[I] := achar[2];
    Inc(I, 2); 
  end; 
  rtf := rtf + hexpict + ' }}'; 
  Result := rtf;
end; 


// Example to insert image from Image1 into RxRichEdit1
procedure Button1Click(Sender: TObject);
var
  SS: TStringStream;
  BMP: TBitmap;
begin
  BMP := TBitmap.Create;
  BMP := Image1.Picture.Bitmap;
  SS  := TStringStream.Create(BitmapToRTF(BMP));
  try
    PutRTFSelection(RxRichEdit1, SS);
  finally
    SS.Free;
  end;
end;

end.


Die letzte Prozedur zeigt ganz schön, wie die Befehle angewendet werden. Natürlich muss das dann kein Button mehr sein, ich hab zum Beispiel nochmals eine Prozedur erstellt "InsertBitmap(RichEdit, BMP)..

Ein viel grösseres Problem das später auftaucht...wie schreibt man hinter der RichEdit wenn man nicht selber schreibt? (Chat-Problem...)

Da bringt dann das Property "SelStart" der RichEdit abhilfe ;-) Wenn du das genauer wissen willst, schreib nochmals ;-)

_________________
...and You will Know us By the Trail of Death.....
Stevie Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 85

Windows 7
Delphi XE Professional
BeitragVerfasst: Fr 26.09.03 13:24 
:shock: Ich hab ja schon nicht mehr an eine Antwort geglaubt! Danke, aber die Lösung hab ich dann nach langem Suchen auch gefunden! :oops:
Ich hab aber noch ein paar Fragen:
1.) Geht das wirklich auch mit dem "stinknormalen" TRichEdit? Ich dachte, das kann keine Bilder, auch wenn sie RTF sind.
2.) Ich benutze jetzt genau diese Funktion, aber die Bilder sind noch "resizeable". Wie kann ich das abstellen, dass ich die Größe der eingebundenen Bitmaps verändern kann?
3.) Geht das mit anderen Dateiformaten(png, jpg, ...)?
4.) Das dahinterschreiben geht bestimmt mit SelStart := GetTextLen, oder?
Jebaz
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 44

Win NT 4, Win XP, Linux
Delphi 7.0
BeitragVerfasst: Fr 26.09.03 16:09 
Titel: Sorry
tut mir leid wegen der verspäteten Antwort, ich wahr schon viel zu lange nicht mehr auf diesem Board:

Zu deinen Fragen

- Also es sollte schon auf einem normalen RichEdit möglich sein, wobie ich mich nicht mehr genau erinnern kann. Ansonsten kannst du die erweiterte RichEdit der JEDI-Kompos installieren (Link kann ich bei Bedarf auch noch posten, muss ich erst wieder suchen)
- Das Resizen ist in meinem Chat auch immer noch möglich, ich hab schon ganze Abende versucht, dass auszuschalten, wüsste ich selbst zu gerne....(unbedingt posten wenn du mal darauf stösst ;-))
- Soweit ich weiss sind leider nur BMP's möglich so in ein RichEdit einzufügen, für alles andere musst du es erst in ein BMP umwandeln (dafür gibts ja auch Kompos ;-))
- Und haaargenau, mit SelStart := GetSelText ist es easy möglich hinter das Bild zu schreiben, also mein Chat läuft wunderbar mit Emoticons und allem ;-)

_________________
...and You will Know us By the Trail of Death.....
Stevie Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 85

Windows 7
Delphi XE Professional
BeitragVerfasst: Mo 29.09.03 07:38 
Titel: Re: Sorry
JEDI-Kompos hab ich!
Und Wenn das "resizen" abschaltbar ist, dann werd ich das bestimmt noch rausfinden...
Kann man deinen Chat auch ausprobieren???
Jebaz
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 44

Win NT 4, Win XP, Linux
Delphi 7.0
BeitragVerfasst: Mo 29.09.03 08:24 
Titel: Chat
:) also wenns dich interessiert kann ich dir mal die beiden exe-dateien von client und server zusenden...denn leider hab ich immer noch keinen pc der im internet erreichbar währe, was den chat erst richtig lauffähig machen würde...naja, schade aber das krieg ich so wie du das resizen auch mal noch hin :wink:

werd mich dann wieder melden :)

_________________
...and You will Know us By the Trail of Death.....
maze2k
ontopic starontopic starontopic starontopic starhalf ontopic starofftopic starofftopic starofftopic star
Beiträge: 252

WIN 95, WIN NT 4.0, WIN 98, WIN 98SE, WIN 2000, RedHat Linux 7.3, Mandrake Linux 9.2, Knoppix Linux 3.3
D6 Pers
BeitragVerfasst: Di 14.10.03 08:24 
Und wieder bin ich auf der Suche nach hilfreichem für meinen Chat fündig geworden (will smilies einbauen, ähnlich wie BBCode hier *g*)

subba :)

_________________
Wer das Konzept der Unendlichkeit verstehen will, muss nur das Ausmaß menschlicher Dummheit betrachten. (Voltaire)