gpt4 book ai didi

delphi - 为什么Delphi中BitMap的传输顺序相反?

转载 作者:行者123 更新时间:2023-12-02 08:37:50 28 4
gpt4 key购买 nike

单击该按钮时,图像应从 richedit1 传输到 richedit2 并按顺序显示,反之亦然。如何修复它?下面是代码。

procedure TForm1.Button1Click(Sender: TObject);
begin
if OpenPictureDialog1.Execute then
begin
Image1.Picture.LoadFromFile(OpenPictureDialog1.FileName);
InsertBitmapToRE(RichEdit1.Handle, Image1.Picture.Bitmap.Handle);
end;
end;

Function MAP_LOGHIM_TO_PIX(Const Val: Integer; Const Log: Integer): Integer;
Const
HIMETRIC_PER_INCH=2540;
Begin
Result:=MulDiv(Val, Log, HIMETRIC_PER_INCH);
End;

Function MAP_LOGHIMPT_TO_PT(Const Val: TPoint; Const Handle: HWND = 0): TPoint;
Var
DC: HDC;
Begin
DC:=GetDC(Handle);
Result.X:=MAP_LOGHIM_TO_PIX(Val.X, GetDeviceCaps(DC, LOGPIXELSX));
Result.Y:=MAP_LOGHIM_TO_PIX(Val.Y, GetDeviceCaps(DC, LOGPIXELSY));
ReleaseDC(Handle, DC);
End;

procedure TForm1.Button2Click(Sender: TObject);
Var
IREO: IRichEditOle;
OleClientSite: IOleClientSite;
ReObject: TReObject;
I: Integer;
ViewObject2: IViewObject2;
Rc: TRect;
Path:String;
bmp:TBitmap;
Pt: TPoint;
begin
Path:='C:\temp\richedit\';
SendMessage(RichEdit1.Handle, EM_GETOLEINTERFACE, 0, Longint(@IREO));
IREO.GetClientSite(OleClientSite);
For I:=IREO.GetObjectCount-1 Downto 0 Do
Begin
ZeroMemory(@ReObject, SizeOf(ReObject));
ReObject.cbStruct:=SizeOf(ReObject);
If Succeeded(IREO.GetObject(I, ReObject, $00000001)) Then
If Succeeded(ReObject.poleobj.QueryInterface(IViewObject2, ViewObject2)) Then
Begin
ViewObject2.GetExtent(DVASPECT_CONTENT, -1, Nil, Pt);
Pt:=MAP_LOGHIMPT_TO_PT(Pt, RichEdit1.Handle);
bmp:=TBitmap.Create;
Bmp.Height := Pt.Y;
Bmp.Width := Pt.X;
SetRect(Rc, 0, 0, Bmp.Width, Bmp.Height);
OleDraw(ReObject.poleobj, DVASPECT_CONTENT, bmp.Canvas.Handle, Rc);
bmp.SaveToFile(Path+'Img'+IntToStr(I+1)+'.bmp');
InsertBitmapToRE(RichEdit2.Handle, bmp.Handle);
End
Else
ShowMessage('Error: Can''t get IViewObject2');
End;
end;

截图

Screenshot

最佳答案

在 for 循环中使用 downto 0 效率很高,但会反向计数,因此并不总是可取的。出现这种情况是因为您使用循环变量作为索引并且需要特定的处理顺序。

对于 I:= 0 到 IREO.GetObjectCount-1 执行

关于delphi - 为什么Delphi中BitMap的传输顺序相反?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52445458/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com