截取到的是屏幕大小的bitmap,我需要修改其大小,并转换为JPEG.我代码如下,可是需要从文件中转function TForm1.ResizeImage(SourceBitmap:TBitmap):TJPEGimage;
var tmpBitmap:TBitmap;
tmpJPEG:TJPEGimage;
Dest:TRect;
begin
tmpBitmap:=TBitmap.Create;
tmpBitmap.Width:=320;
tmpBitmap.Height:=240; with Dest do
begin
Left:=0;
Top:=0;
Right:=tmpBitmap.Width;
bottom:=tmpbitmap.Height;
end; tmpBitmap.Canvas.StretchDraw(Dest,SourceBitmap);
tmpJPEG:=TJPEGimage.Create;
tmpJPEG.Assign(tmpBitmap);
result:=tmpJPEG;
end;procedure TForm1.ScreenCap;
var RectWidth,RectHeight:integer;
SourceDC,DestDC,Bhandle:integer;
Bitmap,Bitmap2:TBitmap;
NewJpeg:TJPEGimage;
begin
RectWidth:=Screen.Width;
RectHeight:=Screen.Height;
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;
Bitmap2:=TBitmap.Create;
NewJpeg:=TJPEGimage.Create;
Bitmap.Handle:=BHandle;
Bitmap.SaveToFile('d:\temp.bmp');
Bitmap2.LoadFromFile('d:\temp.bmp');
deletefile('d:\temp.bmp');
NewJpeg.Assign(ResizeImage(Bitmap2));
NewJpeg.SaveToStream(BmpStream);
BmpStream.Position:=0;
LeftSize:=BmpStream.Size;
Bitmap.Free;
NewJpeg.Free;
DeleteDC(DestDC);
ReleaseDC(Bhandle,SourceDC);
end;
var tmpBitmap:TBitmap;
tmpJPEG:TJPEGimage;
Dest:TRect;
begin
tmpBitmap:=TBitmap.Create;
tmpBitmap.Width:=320;
tmpBitmap.Height:=240; with Dest do
begin
Left:=0;
Top:=0;
Right:=tmpBitmap.Width;
bottom:=tmpbitmap.Height;
end; tmpBitmap.Canvas.StretchDraw(Dest,SourceBitmap);
tmpJPEG:=TJPEGimage.Create;
tmpJPEG.Assign(tmpBitmap);
result:=tmpJPEG;
end;procedure TForm1.ScreenCap;
var RectWidth,RectHeight:integer;
SourceDC,DestDC,Bhandle:integer;
Bitmap,Bitmap2:TBitmap;
NewJpeg:TJPEGimage;
begin
RectWidth:=Screen.Width;
RectHeight:=Screen.Height;
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;
Bitmap2:=TBitmap.Create;
NewJpeg:=TJPEGimage.Create;
Bitmap.Handle:=BHandle;
Bitmap.SaveToFile('d:\temp.bmp');
Bitmap2.LoadFromFile('d:\temp.bmp');
deletefile('d:\temp.bmp');
NewJpeg.Assign(ResizeImage(Bitmap2));
NewJpeg.SaveToStream(BmpStream);
BmpStream.Position:=0;
LeftSize:=BmpStream.Size;
Bitmap.Free;
NewJpeg.Free;
DeleteDC(DestDC);
ReleaseDC(Bhandle,SourceDC);
end;
解决方案 »
- 有关临时表的操作,请帮忙
- 自动加栽图片!!!
- 求水晶报表VCL9.2的帮助文挡.
- 急!求用OpenPictureDialog 打開jpg圖片方法
- 有没有学习delphi的QQ群体啊?
- 我找不到QReport了怎么办?就Options里也找不到了。这是为什么啊?
- selected collating sequence not supported by the operating system//出现这个错误是怎么回事
- dbgrideh
- EnumChildWindows和EnumChildProc怎么用啊?
- 一个很实用的程序(建立SQL结构)和源代码送给大家,具体请进
- 关于Delphi操作Excel的两个问题。有兴趣的朋友进来探讨一下。(实在没办法了)
- 这代码错在哪儿?请楼主指教?
Bitmap对象的图片通过Assign方法/Canvas的复制CopyRect,就可以复制其内容的