请教如何在程序中改变bmp图像尺寸。(100分)

  • 主题发起人 主题发起人 liuind
  • 开始时间 开始时间
L

liuind

Unregistered / Unconfirmed
GUEST, unregistred user!
我试过用bmp.weight和 heigh属性,但不成功,有其他方法吗。谢谢!
 
如果用的是TImage对象的话可以将其Stretch属性设置为True,然后设置其Width和Height属性,否则用API自己处理了。
 
> 我试过用bmp.weight和 heigh属性,但不成功,有其他方法吗。谢谢!

会吗? 我这边好象可以哦.[^]
 
用imagelist1做列表listview中显示出来的图像表明,这个方法有问题,listview显示有多幅图,即被分割成几幅图。
bmp1.Assign(jpg);
tmpbmp.Width :=128;
tmpbmp.Height :=96;

imagelist1.ShareImages:=true;
imagelist1.CreateSize(128,96);
imagelist1.Add(tmpbmp,tmpbmp);
 
呵呵,很简单,把BMP导入FILESTREAM,定位到文件头里宽高的地方,修改就行了,这样文件的大小不变,但显示出来的大小却变了,呵呵,这样可以随你改了,而且可以随时还原
 
楼上老大,能不能具体一点呀,我是菜鸟。
 
用StretchDraw方法。
 
看看这段代码对你是否有帮助:
procedure TMainForm.ShowImage(PicFileName:String);
var Pic:TPicture;
Rate:Real;
ExtName:String;
begin
IF FileExists(PicFileName) = TRUE THEN
BEGIN
ExtName := ExtractFileExt(PicFileName);
ExtName := UpperCase(ExtName);
IF ((ExtName = '.BMP') OR (ExtName = '.JPG') OR (ExtName = 'JPEG')) THEN
BEGIN
TRY
Pic := TPicture.Create;
Pic.LoadFromFile(PicFileName);
StatusBar1.Panels[1].Text := '图片尺寸:' + INTTOSTR(Pic.Width) + '×' + INTTOSTR(Pic.Height);
IF Pic.Width >= Pic.Height THEN
BEGIN
Rate := Pic.Height / Pic.Width;
Image1.Width := Panel2.Width - 30;
Image1.Height := Round(Image1.Width * Rate);
END
ELSE
BEGIN
Rate := Pic.Width / Pic.Height;
Image1.Height := Panel2.Height - 30;
Image1.Width := Round(Image1.Height * Rate);
END;
Image1.Top := (Panel2.Height DIV 2) - (Image1.Height DIV 2);
Image1.Left := (Panel2.Width DIV 2) - (Image1.Width DIV 2);
Image1.Picture.Assign(Pic);
Image1.Show;
FINALLY
Pic.Free;
END;
END
ELSE
BEGIN
Image1.Hide;
StatusBar1.Panels[1].Text := '图片尺寸:';
END;
END
ELSE
BEGIN
Image1.Hide;
StatusBar1.Panels[1].Text := '图片尺寸:';
END;
end;
 
需要把TImage的Stretch属性置为True。
 
{-------------------------------------------------------------------------------
函数名: PictureResiz
作 者: cjsh(wjh_wy@163.com)
日 期: 2003.11.10
功 能: 图片放大或缩小显示
参 数: aFilename-源文件名
返回值: 目标文件名
-------------------------------------------------------------------------------}
Function PictureResiz(aFilename: String): String;
Const
csHeight = 200; //放大或缩小高度
csWidth = 200; //放大或缩小宽度
var
Image: TPicture;
bmp, tmpbmp: TBitmap;
aDesiredFileName: String;
begin
Image := TPicture.Create;
bmp := TBitmap.Create;
tmpbmp := TBitmap.Create;
try
Image.LoadFromFile(aFilename);
bmp.Assign(Image.Graphic);
tmpbmp.Width := csWidth;
tmpbmp.Height := csHeight;
SetStretchBltMode(tmpbmp.Canvas.Handle, STRETCH_DELETESCANS); //平滑处理
StretchBlt(tmpbmp.Canvas.Handle, 0, 0, tmpbmp.Width, tmpbmp.Height,
bmp.Canvas.Handle, 0, 0, bmp.Width, bmp.Height, SRCCOPY);
Image.Graphic.Assign(tmpbmp);
aDesiredFileName := aFilename;
Insert('_Bak', aDesiredFileName, Length(aDesiredFileName)-3);
if FileExists(aDesiredFileName) then DeleteFile(aDesiredFileName);
Image.SaveToFile(aDesiredFileName);
Result := aDesiredFileName;
finally
bmp.Free;
tmpbmp.Free;
Image.Free;
end;
end;
 
用StretchDraw方法,我显示不出来,方不方便给我几行关健代码,用 StretchBlt方法图像质量差了许多。颜色都变了。
 
image1中有一个100x100图片,newbmp为300x400的位图,要将image1的图形充
满newbmp,则代码如下:
newbmp.Canvas.stretchdraw(Rect(0,0,300,400),image1.Picture.Graphic);
如果只需要画到一个小区内,不要充满,则:
newbmp.Canvas.stretchdraw(Rect(50,50,200,200),image1.Picture.Graphic);
 
Var B:Tbitmap; //临时位图
Begin
B:=Tbitmap.Create; //建立临时位图
With B do
Begin
Width:=90; //临时位图的大小为90x90
Height:=90;
End;
B.canvas.StretchDraw(B.canvas.Cliprect,YourBitmap); //缩放适应
B.SavetoFile(YourFileName); //保存
B.Free;
End;
 
谢谢大家给我支持,如果大家有更好的意见,请给我E_mail liuind@sina.com.
 
后退
顶部