如何将截屏后BMP的图片按比例缩小,下面是我的原代码: ( 积分: 100 )

  • 主题发起人 主题发起人 penwater191
  • 开始时间 开始时间
P

penwater191

Unregistered / Unconfirmed
GUEST, unregistred user!
procedure ScreenCap(LeftPos,TopPos,RightPos,BottomPos:integer);
begin
bmpstream := Tmemorystream.Create;
RectWidth:=RightPos-LeftPos;
RectHeight:=BottomPos-TopPos;
SourceDC:=CreateDC('DISPLAY','','',nil);
DestDC:=CreateCompatibleDC(SourceDC);
Bhandle:=CreateCompatibleBitmap(SourceDC,RectWidth,RectHeight);
SelectObject(DestDC,Bhandle);
BitBlt(DestDC,0,0,RectWidth,RectHeight,SourceDC,LeftPos,TopPos,SRCCOPY);
Bitmap:=TBitmap.Create;
Bitmap.Handle:=BHandle;
BitMap.SaveToStream(BmpStream);
BmpStream.Position:=0;
LeftSize:=BmpStream.Size;
Bitmap.Free;
DeleteDC(DestDC);
ReleaseDC(Bhandle,SourceDC);

end;

procedure TForm1.Button1Click(Sender: TObject);
begin
w:=screen.Width;
h:=screen.Height;
form1.AutoSize:=true;
screencap(0,0,w,h);
image1.AutoSize:=true;
image1.Picture.Bitmap.LoadFromStream(bmpstream);
bmpstream.Free;
end;
 
procedure ScreenCap(LeftPos,TopPos,RightPos,BottomPos:integer);
begin
bmpstream := Tmemorystream.Create;
RectWidth:=RightPos-LeftPos;
RectHeight:=BottomPos-TopPos;
SourceDC:=CreateDC('DISPLAY','','',nil);
DestDC:=CreateCompatibleDC(SourceDC);
Bhandle:=CreateCompatibleBitmap(SourceDC,RectWidth,RectHeight);
SelectObject(DestDC,Bhandle);
BitBlt(DestDC,0,0,RectWidth,RectHeight,SourceDC,LeftPos,TopPos,SRCCOPY);
Bitmap:=TBitmap.Create;
Bitmap.Handle:=BHandle;
BitMap.SaveToStream(BmpStream);
BmpStream.Position:=0;
LeftSize:=BmpStream.Size;
Bitmap.Free;
DeleteDC(DestDC);
ReleaseDC(Bhandle,SourceDC);

end;

procedure TForm1.Button1Click(Sender: TObject);
begin
w:=screen.Width;
h:=screen.Height;
form1.AutoSize:=true;
screencap(0,0,w,h);
image1.AutoSize:=true;
image1.Picture.Bitmap.LoadFromStream(bmpstream);
bmpstream.Free;
end;
 
ScreenCap是截屏函数没问题,当我读取图象想按比例缩小时无法实现:
// image1.AutoSize:=true;
// image1.Picture.Bitmap.LoadFromStream(bmpstream);
// bmpstream.Free;
上面代码该如何改?我原先想使用TJPEGIMAGE的COMPRESSQUALITY属性来实现,可是还是有问题,请教高人,这问题如何解决?
 
stretchdraw
给个例子 可以把image里的图片按比例缩小但是效果欠佳,不过是最简单的
procedure TForm1.Button1Click(Sender: TObject);
var
bt:tbitmap;
begin
bt:=tbitmap.create;
bt.width:=image2.Width;
bt.height:=image2.Height;
bt.canvas.StretchDraw(rect(0,0,image2.Width,image2.Height),image1.Picture.Graphic );
bt.savetofile('d:/1.bmp');
image2.Picture.Bitmap.Assign(bt);
bt.free;
end;
 
StretchDraw,StretchBlt是从源图象中移动图象到指定矩形
这个方法可行!还有其他更好方法吗?
 
image的Stretch设为True.
 
Stretch没用,不可以将图片按比例缩小
 
StretchBlt不仅仅限于image图片框,你可以自己做个timage,去存图片,既然你可以用流用个timage也没什么嘛
 
我一直这么用。。。
var
h:hwnd;
dc:hdc;
begin
try
bit.PixelFormat:=pf32bit;
bit.Width:=128;
bit.Height:=96;
h:=frm_window.Handle;
dc:=getdc(h);
stretchBlt(bit.Canvas.Handle,0,0,128,96,DC, frm_window.Width, frm_window.Height,frm_window.Width,frm_window.Height, SRCCOPY);
releasedc(h,dc);
except
end;
end;
 
谢谢funxu以及hs-kill
 
后退
顶部