假设有4张图片,排列的方式是一个田字形,现在对其旋转45度,即田字转45度(里面的图片也各自旋转45度)请教各位应该怎样做比较好??

解决方案 »

  1.   

    把四张图形CopyRect到一个Image上,也形成一个田字型,再进行旋转
      

  2.   

    先写段代码再说。
    procedure RotateImage(Bitmap:TBitmap;Angle:Real);
    {Bitmap: 要旋转的图像。
    Angle: 要旋转的角度(弧度)。
    }
    var
         tx0,ty1,x0,y0,x1,x2,y1,y2,r:Integer;
         tmpBitmap:TBitmap;
         x,y:Integer;
    begin
         tmpBitmap:=TBitmap.Create;     
         x0:=Round(Bitmap.Width/2);
         y0:=Round(Biymap.Height/2);
         r:=Round(sqrt(x0*x0+y0*y0));
         tx1:=Round(abs(r*Cos(Angle)));
         ty1:=Round(abs(r*Sin(Angle)));
         tmpBitmap.Width:=2*tx1;
         tmpBitmap.Height:=2*ty1;
         for y:=0 to Bitmap.Height-1 do
         begin
              for x:=0 to Bitmap.Width-1 do
              begin
                   x1:=x-x0;
                   y1:=y-y0;
                   x2:=Round(x1*cos(Angle)-y1*sin(Angle))+tx1;
                   y2:=Round(y1*sin(Angle)+x1*cos(Angle))+ty1;
                   tmpBitmap.Canvas.Pixels[x2,y2]:=Bitmap.Canvas.Pixels[x,y];
              end;
         end;   
         Bitmap.Assign(tmpBitmap);
         tmpBitmap.Free;
    end;
    由于在网吧上网,没有开发工具,无法调试,只是人为编译通过. ^_^;
      

  3.   

    哈哈,谢谢各位了。
    to:: miky(miky) :我是这样想的,图片旋转后只显示菱形内的东西,而不会遮住底下的文字,它的角只存在上、下,和左、右。
       {角}  
        /\asdfsdfasdf
          /   角  / 内 \{角}
         \    /
          \  /
           \/
        角
      

  4.   

    明白你的意思了,如果在NT下,有现成API可用。PlgBltThe PlgBlt function performs a bit-block transfer of the bits of color data from the specified rectangle in the source device context to the specified parallelogram in the destination device context. If the given bitmask handle identifies a valid monochrome bitmap, the function uses this bitmap to mask the bits of color data from the source rectangle. BOOL PlgBlt(
      HDC hdcDest,          // handle to destination DC
      CONST POINT *lpPoint, // destination vertices
      HDC hdcSrc,           // handle to source DC
      int nXSrc,            // x-coord of source upper-left corner
      int nYSrc,            // y-coord of source upper-left corner
      int nWidth,           // width of source rectangle
      int nHeight,          // height of source rectangle
      HBITMAP hbmMask,      // handle to bitmask
      int xMask,            // x-coord of bitmask upper-left corner
      int yMask             // y-coord of bitmask upper-left corner
    );
    Parameters
    hdcDest 
    [in] Handle to the destination device context. 
    lpPoint 
    [in] Pointer to an array of three points in logical space that identify three corners of the destination parallelogram. The upper-left corner of the source rectangle is mapped to the first point in this array, the upper-right corner to the second point in this array, and the lower-left corner to the third point. The lower-right corner of the source rectangle is mapped to the implicit fourth point in the parallelogram. 
    hdcSrc 
    [in] Handle to the source device context. 
    nXSrc 
    [in] Specifies the x-coordinate, in logical units, of the upper-left corner of the source rectangle. 
    nYSrc 
    [in] Specifies the y-coordinate, in logical units, of the upper-left corner of the source rectangle. 
    nWidth 
    [in] Specifies the width, in logical units, of the source rectangle. 
    nHeight 
    [in] Specifies the height, in logical units, of the source rectangle. 
    hbmMask 
    [in] Handle to an optional monochrome bitmap that is used to mask the colors of the source rectangle. 
    xMask 
    [in] Specifies the x-coordinate, in logical units, of the upper-left corner of the monochrome bitmap. 
    yMask 
    [in] Specifies the y-coordinate, in logical units, of the upper-left corner of the monochrome bitmap. 
    Return Values
    If the function succeeds, the return value is nonzero.If the function fails, the return value is zero. Windows NT/2000/XP: To get extended error information, call GetLastError. Res
    The PlgBlt function works with device-dependent bitmaps.The fourth vertex of the parallelogram (D) is defined by treating the first three points (A, B, and C) as vectors and computing D = B + C A. If the bitmask exists, a value of one in the mask indicates that the source pixel color should be copied to the destination. A value of zero in the mask indicates that the destination pixel color is not to be changed. If the mask rectangle is smaller than the source and destination rectangles, the function replicates the mask pattern. Scaling, translation, and reflection transformations are allowed in the source device context; however, rotation and shear transformations are not. If the mask bitmap is not a monochrome bitmap, an error occurs. The stretching mode for the destination device context is used to determine how to stretch or compress the pixels, if that is necessary. When an enhanced metafile is being recorded, an error occurs if the source device context identifies an enhanced-metafile device context. The destination coordinates are transformed according to the destination device context; the source coordinates are transformed according to the source device context. If the source transformation has a rotation or shear, an error is returned. If the destination and source rectangles do not have the same color format, PlgBlt converts the source rectangle to match the destination rectangle. Not all devices support the PlgBlt function. For more information, see the description of the RC_BITBLT raster capability in the GetDeviceCaps function. If the source and destination device contexts represent incompatible devices, PlgBlt returns an error. Windows 2000/XP: When used in a multiple monitor system, both hdcSrc and hdcDest must refer to the same device or the function will fail. To transfer data between DCs for different devices, convert the memory bitmap to a DIB by calling GetDIBits. To display the DIB to the second device, call SetDIBits or StretchDIBits.Requirements 
      Windows NT/2000/XP: Included in Windows NT 3.1 and later.
      Windows 95/98/Me: Unsupported.
      Header: Declared in Wingdi.h; include Windows.h.
      Library: Use Gdi32.lib.
      

  5.   

    to: miky(miky)你说的我已经试过了的,不行的。但不知是不是我没用好。你先放一张底图(要大一些),再放一张小点的,用PlgBlt函数来处理,旋转小图后,其结果与计算象素点位置画出来的结果是一样的。虽然可以得到旋转后的图形,但仍然画在一个矩形区域里面。确实,除了象 linzhengqun(风) 说的那样处理,好象没什么其它的办法。 
      

  6.   

    to: miky(miky)不好意思,我弄错了,PlgBlt函数处理应该是可以的。