L liuind Unregistered / Unconfirmed GUEST, unregistred user! 2003-12-27 #1 我试过用bmp.weight和 heigh属性,但不成功,有其他方法吗。谢谢!
陈 陈健松 Unregistered / Unconfirmed GUEST, unregistred user! 2003-12-27 #2 如果用的是TImage对象的话可以将其Stretch属性设置为True,然后设置其Width和Height属性,否则用API自己处理了。
W wlmmlw Unregistered / Unconfirmed GUEST, unregistred user! 2003-12-27 #3 > 我试过用bmp.weight和 heigh属性,但不成功,有其他方法吗。谢谢! 会吗? 我这边好象可以哦.[^]
L liuind Unregistered / Unconfirmed GUEST, unregistred user! 2003-12-27 #4 用imagelist1做列表listview中显示出来的图像表明,这个方法有问题,listview显示有多幅图,即被分割成几幅图。 bmp1.Assign(jpg); tmpbmp.Width :=128; tmpbmp.Height :=96; imagelist1.ShareImages:=true; imagelist1.CreateSize(128,96); imagelist1.Add(tmpbmp,tmpbmp);
用imagelist1做列表listview中显示出来的图像表明,这个方法有问题,listview显示有多幅图,即被分割成几幅图。 bmp1.Assign(jpg); tmpbmp.Width :=128; tmpbmp.Height :=96; imagelist1.ShareImages:=true; imagelist1.CreateSize(128,96); imagelist1.Add(tmpbmp,tmpbmp);
啊 啊啊啊啊啊 Unregistered / Unconfirmed GUEST, unregistred user! 2003-12-28 #5 呵呵,很简单,把BMP导入FILESTREAM,定位到文件头里宽高的地方,修改就行了,这样文件的大小不变,但显示出来的大小却变了,呵呵,这样可以随你改了,而且可以随时还原
M miaofeng Unregistered / Unconfirmed GUEST, unregistred user! 2003-12-30 #8 看看这段代码对你是否有帮助: 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;
看看这段代码对你是否有帮助: 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;
M miaofeng Unregistered / Unconfirmed GUEST, unregistred user! 2003-12-30 #9 需要把TImage的Stretch属性置为True。
W wjh_wy Unregistered / Unconfirmed GUEST, unregistred user! 2003-12-30 #10 {------------------------------------------------------------------------------- 函数名: 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;
{------------------------------------------------------------------------------- 函数名: 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;
L liuind Unregistered / Unconfirmed GUEST, unregistred user! 2003-12-31 #11 用StretchDraw方法,我显示不出来,方不方便给我几行关健代码,用 StretchBlt方法图像质量差了许多。颜色都变了。
W wjh_wy Unregistered / Unconfirmed GUEST, unregistred user! 2003-12-31 #12 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);
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);
W wjh_wy Unregistered / Unconfirmed GUEST, unregistred user! 2003-12-31 #13 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;
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;
L liuind Unregistered / Unconfirmed GUEST, unregistred user! 2003-12-31 #14 谢谢大家给我支持,如果大家有更好的意见,请给我E_mail liuind@sina.com.