用了很多方法,在缩小图形时失真到了忍无可忍的地步,哪位大哥有好的插值算法给偶用用吧,不甚感激
解决方案 »
- Delphi开发,用ADO调用Oracle的存储过程,存储过程有Blob参数32k限制问题,如何解决???急
- 雪MM来这也
- excel导入到delphi 日期格式转换问题,求助!!!
- 利用mshtml得到了某个IHTMLElement的实例,但是如何获得这个实例的width呢?
- 客户端使用SOCKETSVR.EXE 连接中间件服务器,只有本机能连上.其他机器均不能连接!服务端没有防火墙!各位大侠救命阿!
- 请教各位大侠,怎么才能即时输入文字那?(想了好久的问题,问过很多人都不能彻底回答)
- 怎样建立一个Socket?
- 如何控制收银台的抽屉
- 请教:用installshield做setup,bde设置如果是死的好弄,现在我想bde的设置是读INI的,怎么弄
- 怎么用delphi,往快速启动栏中添加快捷方式。
- 初学者,求助!
- 菜鸟问题!!
begin
setstretchbltmode(Canvas.Handle,HALFTONE);
Canvas.CopyRect(DestRect,Image1.Canvas,SourceRect);
end;
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;
//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;