Timage 旋转

wiShow: TWeaveImage;

procedure TFBMPBrowser.N1Click(Sender: TObject); //水平翻轉
begin
  wiShow.Picture.Bitmap.PixelFormat := pf24bit;
  wiShow.Picture.Bitmap :=
    GraphicMirror(wiShow.Picture.Bitmap, mtHorizontal);
end;

 

function Rotate270(const Bitmap: TBitmap): TBitmap;
var
  aStream: TMemoryStream;
  header: TBITMAPINFO;
  dc: hDC;
  P: ^THelpRGB;
  x, y, b, h: Integer;
  RowOut: pRGBArray;
begin
  Result := TBitmap.Create;

  Result := Bitmap;

  //創建內存流
  aStream := TMemoryStream.Create;
  try
    //設置大小,必須是4的倍數
    aStream.SetSize(Result.Height * Result.Width * 4);
    with header.bmiHeader do //操作位圖文件
    begin
      biSize := SizeOf(TBITMAPINFOHEADER); //設置文件頭的大小
      biWidth := Result.Width; //位圖寬
      biHeight := Result.Height; //位圖高
      biPlanes := 1;
      biBitCount := 32; //設置圖形的類型為32位
      biCompression := 0;
      biSizeimage := aStream.Size; //設置圖形的大小,也可以為0
      biXPelsPerMeter := 1; //水平分辨率
      biYPelsPerMeter := 1; //豎直分辨率
      biClrUsed := 0;
      biClrImportant := 0;
    end;
    //拷貝Result的圖像數據到內存流aStream中,注意此時的內存流中數據保存的數據順序
    dc := GetDC(0);
    P := aStream.Memory;
    GetDIBits(dc, Result.Handle, 0, Result.Height, P, header, dib_RGB_Colors);
    ReleaseDC(0, dc);
    //aStream.SaveToFile('E:\abc.bin');
    b := Result.Height; //源圖高
    h := Result.Width; //源圖寬
    //指定要創建的位圖的大小尺寸
    Result.Width := b;
    Result.height := h;
    for y := 0 to (h - 1) do
    begin
      rowOut := Result.ScanLine[(h - 1) - y]; //獲取新的位圖信息
      P := aStream.Memory; //設置文件指針
      inc(P, y); //指針移位
      for x := (b - 1) downto 0 do
      begin
        rowOut[x] := P^.rgb; //進行數據轉移
        inc(P, h);
      end;
    end;
  finally
    aStream.Free; //釋放資源
  end;
end;

 

转载于:https://www.cnblogs.com/sunnycnblogs/p/5138603.html

你可能感兴趣的:(Timage 旋转)