求图象缩小(只需要缩小)尽量少失真的算法或代码,给点建议也行。(30分)

  • 主题发起人 billjohn1999
  • 开始时间
B

billjohn1999

Unregistered / Unconfirmed
GUEST, unregistred user!
求图象缩小(只需要缩小)尽量少失真的算法或代码,给点建议也行。

我在论坛上找过了,好像说要插值,
插值是图象放大时可以减少失真的方法吧?
我只需要缩小,尽量少失真,
我看了ImageEn控件的缩放,效果很好(我比较过的,比Acdsee的效果还要好),
好象有什么bell型、triangle型之类的,不知该怎样实现?
 
我有一个放大放小不会出现马赛克的函数,就是类似ImageEn的,但我是从GraphicEx扒下
来的[:D][:D][:D]
TResamplingFilter = (sfBox, sfTriangle, sfHermite, sfBell, sfSpline,
sfLanczos3, sfMitchell);
procedure Stretch(NewWidth, NewHeight: Cardinal; Filter: TResamplingFilter;
Radius: Single; Source: TBitmap);
已经可以独立使用
graphics32上也有这种功能。缩放无马赛克
 
to yuki2003, 能不能发给我?谢谢.
email address: whtj2018@yahoo.com
 
以下程序只能折半处理
unit JpgCompress;
// 标准照片大小为112*82
//本程序把照片压缩为宽度在 82*1.2/2-82*1.2 间
// 高度在 112*1.2/2-112*1.2 间的图片
interface
uses jpeg,classes,graphics;
procedure Compress(var Jpeg:TJpegImage);
function CompressJpgFile(JpegFile:string):boolean;

implementation
uses dialogs;
procedure Compress(var Jpeg:TJpegImage);
var Bmp:TBitMap; tmpjpg:TJpegImage;
begin
if (Jpeg.Height<=112*1.2) and (Jpeg.Width<=82*1.2) then
Exit;
Bmp:= TBitMap.Create;
tmpjpg:= TJpegImage.Create;
try
//Jpeg.Grayscale:=true;//灰化
if (Jpeg.Height>112*1.2) or (Jpeg.Width>82*1.2) then
//标准大小112*82,这里给一点余量
Jpeg.Scale:=jsHalf;
bmp.Assign(Jpeg);
tmpJpg.Assign(bmp);
tmpJpg.Compress;
Compress(tmpJpg);
Jpeg.Assign(tmpjpg);
finally
bmp.Free;
tmpjpg.Free;
end;
end;
function CompressJpgFile(JpegFile:string):boolean;
var jpg:TJpegImage;
begin
result:=true;
jpg:= TJpegImage.Create;
try
try
jpg.LoadFromFile(JpegFile);
//Jpeg.Grayscale:=true;//灰化
while (jpg.Height>112*1.2) or (jpg.Width>82*1.2) do
Compress(jpg);
jpg.SaveToFile(JpegFile);
except
result:=false;
end;
finally
jpg.Free;
end;
end;
end.
 
to 张鸿林,谢谢,我的图象是bmp格式黑白图象,好象你的代码是jpeg格式的吧?
 
// 缩放BMP
void __stdcall StretchBmp(Graphics::TBitmap *pBmp, int StretchToWidth, int StretchToHeight) {
int OldW = pBmp->Width;
int OldH = pBmp->Height;
::SetStretchBltMode(pBmp->Canvas->Handle, HALFTONE);
if(pBmp->Width>=StretchToWidth) { // 缩小
::StretchBlt(pBmp->Canvas->Handle,
0,
0,
StretchToWidth,
StretchToHeight,
pBmp->Canvas->Handle,
0,
0,
OldW,
OldH,
SRCCOPY);
pBmp->Width = StretchToWidth;
pBmp->Height = StretchToHeight;
}
else { // 放大
pBmp->Width = StretchToWidth;
pBmp->Height = StretchToHeight;
::StretchBlt(pBmp->Canvas->Handle,
0,
0,
StretchToWidth,
StretchToHeight,
pBmp->Canvas->Handle,
0,
0,
OldW,
OldH,
SRCCOPY);
}
SetBrushOrgEx(pBmp->Canvas->Handle, 0, 0, NULL);
}
代码是bcb的,改改就行,效果我试过可以和xp缩略图比美


 
来自:billjohn1999, 时间:2002-12-4 18:19:00, ID:1485744
to yuki2003, 能不能发给我?谢谢.
email address: whtj2018@yahoo.com

邮件已发
 
to yuki2003:
能不能发给我一个,我现在正作图像处理。
ztiger_11@163.com.谢谢。[:D]
 
to yuki2003:已收到,谢谢!
 
多人接受答案了。
 
to yuki2003:
谢谢,已收到。
 
to yuki2003:
能不能发给我一个,我现在正作图像处理。
fwcf@163.net.谢谢!
 
to yuki2003:
能不能发给我一个, qfjaming@963.net.谢谢!
 
to yuki2003:
我也要一个,qft@designtime.com.cn 谢谢!
 
to yuki2003:
ydystory@vip.sina.com万分感谢!
 
to yuki2003, 能不能发给我?谢谢.
email address: maxwell@dg163.com
 
顶部