delphi 이미지 회전

3017 단어
인터넷 검색해서 쓸모 있을 것 같은데 가져가세요. 스피드 좋네요.
//  90°
procedure Rotate(Bitmap: TBitmap);
type
  THelpRGB = packed record
    rgb: TRGBTriple;
    dummy: byte;
  end;

  pRGBArray = ^TRGBArray;
  TRGBArray = array[0..32767] of TRGBTriple;
var
  aStream: TMemorystream;
  //   
  header: TBITMAPINFO;
  dc: hDC;
  P: ^THelpRGB;
  x, y, b, h: Integer;
  RowOut: pRGBArray;
begin
  //     
  aStream := TMemoryStream.Create;
  //    ,   4   
  aStream.SetSize(Bitmap.Height * Bitmap.Width * 4);
  with header.bmiHeader do //      
  begin
    biSize := SizeOf(TBITMAPINFOHEADER); //  
    biWidth := Bitmap.Width; //   
    biHeight := Bitmap.Height; //   
    biPlanes := 1;
    biBitCount := 32;
    //   
    biCompression := 0;
    biSizeimage := aStream.Size;
    biXPelsPerMeter := 1; //     
    biYPelsPerMeter := 1; //     
    biClrUsed := 0;
    biClrImportant := 0;
  end;
  dc := GetDC(0);
  P := aStream.Memory;
  GetDIBits(dc, Bitmap.Handle, 0, Bitmap.Height, P, header, dib_RGB_Colors);
  ReleaseDC(0, dc);
  b := bitmap.Height; //   
  h := bitmap.Width; //   
  //             
  bitmap.Width := b;
  bitmap.height := h;
  for y := 0 to (h - 1) do
  begin
    rowOut := Bitmap.ScanLine[y]; //        
    P := aStream.Memory; //      
    inc(p, y); //    
    for x := 0 to (b - 1) do
    begin
      rowout[x] := p^.rgb; //      
      inc(p, h);
    end;
  end;
  aStream.Free; //    
end;

 
뒤에 이거 찾기 힘들어.
//    90°
procedure Rotate2(aBitmap: TBitmap);
var
  nIdx, nOfs,
  x, y, i, nMultiplier: integer;
  nMemWidth, nMemHeight, nMemSize, nScanLineSize: LongInt;
  aScnLnBuffer: PChar;
  aScanLine: PByteArray;
begin
  nMultiplier := 3;
  nMemWidth := aBitmap.Height;
  nMemHeight := aBitmap.Width;
  //        
  nMemSize := nMemWidth * nMemHeight * nMultiplier;
  //    
  GetMem(aScnLnBuffer, nMemSize);
  try
    //Scanline   
    nScanLineSize := aBitmap.Width * nMultiplier;
    // ScanLine    
    GetMem(aScanLine, nScanLineSize);
    try
      for y := 0 to aBitmap.Height - 1 do
      begin
        //        
        Move(aBitmap.ScanLine[y]^, aScanLine^, nScanLineSize);
        for x := 0 to aBitmap.Width - 1 do
        begin
          nIdx := ((aBitmap.Width - 1) - x) * nMultiplier;
          nOfs := (x * nMemWidth * nMultiplier) + (y * nMultiplier);
          for i := 0 to nMultiplier - 1 do
            Byte(aScnLnBuffer[nOfs + i]) := aScanLine[nIdx + i];
        end;
      end;
      //       ,     
      aBitmap.Height := nMemHeight;
      aBitmap.Width := nMemWidth;
      for y := 0 to nMemHeight - 1 do
      begin
        //    
        nOfs := y * nMemWidth * nMultiplier;
        Move((@(aScnLnBuffer[nOfs]))^, aBitmap.ScanLine[y]^, nMemWidth *
          nMultiplier);
      end;
    finally
      //    aScanLine
      FreeMem(aScanLine, nScanLineSize);
    end;
  finally
    //    aScnLnBuffer
    FreeMem(aScnLnBuffer, nMemSize);
  end;
end;

  
  
전재 대상:https://www.cnblogs.com/doorsky/p/5596490.html

좋은 웹페이지 즐겨찾기