如何将BMP位图转换为指定象素? |
尚未結案
|
plmm25
一般會員 發表:15 回覆:6 積分:4 註冊:2004-04-20 發送簡訊給我 |
|
Chance36
版主 發表:31 回覆:1033 積分:792 註冊:2002-12-31 發送簡訊給我 |
請參考下列文章,有很精闢的說明
http://delphi.ktop.com.tw/topic.php?topic_id=49370
http://delphi.ktop.com.tw/topic.php?topic_id=34732 ★
http://delphi.ktop.com.tw/topic.php?topic_id=43205
http://delphi.ktop.com.tw/topic.php?TOPIC_ID=38057
http://delphi.ktop.com.tw/topic.php?TOPIC_ID=38124 ★ 發表人 - chance36 於 2004/05/17 19:03:11
|
yachanga
資深會員 發表:24 回覆:335 積分:296 註冊:2003-09-27 發送簡訊給我 |
這個問題好像很面熟 class="code">
function StretchImagePercent(FileName : TFileName; Percent, Quality : Integer) : TJpegImage;
var
bmp, tempbmp : TBitmap;
RT : TRect;
begin
result := TjpegImage.Create;
bmp := TBitmap.Create;
tempbmp := TBitmap.Create;
try
if Uppercase(ExtractFileExt(FileName)) = '.JPG' then
begin
result.LoadFromFile(FileName);
bmp.Width := Round(result.Width * Percent / 100);
bmp.Height := Round(result.Height * Percent / 100);
end
else if Uppercase(ExtractFileExt(FileName)) = '.BMP' then
begin
tempbmp.LoadFromFile(FileName);
bmp.Width := Round(tempbmp.Width * Percent / 100);
bmp.Height := Round(tempbmp.Height * Percent / 100);
end
else
exit;
RT.Left := 0;
RT.Top := 0;
RT.Right := bmp.Width - 1;
RT.Bottom := bmp.Height - 1;
if Uppercase(ExtractFileExt(FileName)) = '.JPG' then
bmp.Canvas.StretchDraw(RT,result)
else
bmp.Canvas.StretchDraw(RT,tempbmp);
result.CompressionQuality := Quality;
result.Assign(bmp);
finally
tempbmp.Free;
bmp.Free;
end;
end; ~悠遊法國號~
|
killghost
一般會員 發表:14 回覆:21 積分:7 註冊:2004-04-21 發送簡訊給我 |
下面是我的方法将图片压缩成了160*120:
Function CompressIMG(o_bitmap:Tbitmap):Tbitmap;
var
MaxPixW: real;
MaxPixH: real;
imagex: real;
imagey: real;
proportion:real;
tempRect :TRect;
n_bitmap:Tbitmap;
begin
n_bitmap:=TBitmap.create;
MaxPixW:=o_bitmap.Width;
MaxPixH:=o_bitmap.Height;
imagex:=160.0;
imagey:=120.0;
/////////// 确定n_bitmap的宽高/////////////////
proportion:=MaxPixW/MaxPixH;
if proportion>=imagex/imagey then
begin
n_bitmap.Width:=160;
n_bitmap.Height:=round(n_bitmap.Width/proportion);
end
else
begin
n_bitmap.Height:=120;
n_bitmap.Width:=round(n_bitmap.Height*proportion);
end;
tempRect.Left:=0;
tempRect.Right:=n_bitmap.Width;
tempRect.Top:=0;
tempRect.Bottom:=n_bitmap.Height; n_bitmap.Canvas.StretchDraw(tempRect,o_bitmap);
Result:=n_bitmap;
end;
|
本站聲明 |
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。 2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。 3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇! |