简体   繁体   English

为什么在Delphi中转移BitMap的顺序相反?

[英]Why does transfer of BitMap reverse order in Delphi?

When the button is clicked, images should be transferred from richedit1 to richedit2 and displayed in order, and they are displayed in reverse. 单击该按钮时,应将图像从richedit1传输到richedit2并按顺序显示,并且图像应反向显示。 How to fix it? 如何解决? Below is the code. 下面是代码。

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 截图

截图

Using downto 0 in a for loop is efficient but counts in reverse so is not always desirable. 在for循环中使用downto 0效率高,但计数相反,因此并不总是希望的。 This is such a case since you are using the loop variable as an index and want a specific order of processing. 之所以如此,是因为您将循环变量用作索引并需要特定的处理顺序。

For I:= 0 to IREO.GetObjectCount-1 Do

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM