用了很多方法,在缩小图形时失真到了忍无可忍的地步,哪位大哥有好的插值算法给偶用用吧,不甚感激

解决方案 »

  1.   

    with Self do  
    begin
      setstretchbltmode(Canvas.Handle,HALFTONE);
      Canvas.CopyRect(DestRect,Image1.Canvas,SourceRect);
    end;
      

  2.   

    使用方法:
    BmpFile1 :要缩放的原始图文件名
    BmpFile2 :缩放并存盘的文件名
    w2: 缩放后的图像宽度
    h2: 缩放后的图像高度procedure ResizeBMP(BmpFile1,BmpFile2:String;w2,h2:Integer);
    {作用:将位图BmpFIle1调整大小为w,h并存盘于BmpFile2中}
    var
     Bmp1,Bmp2 :TBitmap;
     w1,h1:Integer;
    begin
      Bmp1 :=TBitmap.Create;
      Bmp2 :=TBitmap.Create;  Bmp1.LoadFromFile(BmpFile1);  w1:=Bmp1.Width;
      h1:=Bmp1.Height;
      
     Bmp2.Width :=w1*w2 div w1;
     Bmp2.Height :=h1*h2 div h1; SetStretchBltMode(Bmp2.Canvas.Handle,HalfTone);
     StretchBlt(Bmp2.Canvas.Handle,0,0,w2,h2,
                Bmp1.Canvas.Handle,0,0,w1,h1,SRCCOPY);
     Bmp2.SaveToFile(BmpFile2);
     Bmp1.Free;
     Bmp2.Free;
    end;
      

  3.   

    function StretchBmp(SrcBmp:TBitmap;DesBmp:TBitmap;StretchRate:Integer):Boolean;
    //stretch an bitmap to a smaller bmp, stretchRate is from 0 to 100.
    //from tangfeng
    //2003.01.19
    var
      P1,P2:PByteArray;
      x1,y1,x2,y2,r,g,b:Integer;
    begin
      Result:=false;
      if StretchRate>=100 then
        exit;
      try
        DesBmp.PixelFormat:=pf24Bit;
        DesBmp.Width:=SrcBmp.Width*StretchRate div 100;
        DesBmp.Height:=SrcBmp.Height*StretchRate div 100;
        for y1:=0 to DesBmp.Height-1 do begin
          y2:=y1*100 div StretchRate;         //¼ÆËã³öSourceͼÏóÖжÔÓ¦µÄÏóËصãY·½ÏòλÖõÄÖµ
          P1:=DesBmp.Scanline[y1];
          for x1:=0 to DesBmp.Width-1 do begin
            x2:=x1*100 div StretchRate;          //¼ÆËã³öSourceͼÏóÖжÔÓ¦µÄÏóËصãX·½ÏòλÖõÄÖµ
            P2:=SrcBmp.ScanLine[y2];
            if (x1=0) or (x1=DesBmp.Width-1) or (y1=0) or (y1=DesBmp.Height-1) then begin
              P1[x1*3]:=P2[x2*3];
              P1[x1*3+1]:=P2[x2*3+1];
              P1[x1*3+2]:=P2[x2*3+2];
              continue;
            end;
            r:=P2[(x2-SrcBmp.Width)*3]+P2[(x2-1)*3]+P2[(x2+SrcBmp.Width)*3]+P2[(x2+1)*3]+P2[x2*3];
            g:=P2[(x2-SrcBmp.Width)*3+1]+P2[(x2-1)*3+1]+P2[(x2+SrcBmp.Width)*3+1]+P2[(x2+1)*3+1]+P2[x2*3+1];
            b:=P2[(x2-SrcBmp.Width)*3+2]+P2[(x2-1)*3+2]+P2[(x2+SrcBmp.Width)*3+2]+P2[(x2+1)*3+2]+P2[x2*3+2];
            P1[x1*3]:=min(P2[x2*3],r div 5);
            P1[x1*3+1]:=min(P2[x2*3+1],g div 5);
            P1[x1*3+2]:=min(P2[x2*3+2],b div 5);
          end;
        end;
        Result:=true;
      except
      end;
    end;
      

  4.   

    有没有JPG,GIF格式的算法呀??做缩略图用的。谢谢。若好用,奉上200大洋。