请问一个关于分辨率和色彩的问题
主 题:一个关于拷屏的问题,请各位帮个忙
作 者:bluesnail
所属论坛:C++ Builder
问题点数:29
回复次数:0
人气指数:0
发表时间:2001-5-31 11:36:00
以下是一段拷屏的代码,但是只能做到根据现在屏幕的分辨率和颜色来拷屏,但是我想做到根据指定的分辨率和颜色来拷屏。
假如现在屏幕的分辨率是800*600,16位彩色,我想拷下来的是640*480,256色,该怎么样来做呢?请各位帮个忙。
{
TCanvas *Desktop = new TCanvas();
Graphics::TBitmap *Bmp = new Graphics::TBitmap();
TRect SourRect,DestRect;
//要拷的区域
SourRect.Left = 0;
SourRect.Top = 0;
SourRect.Right = 100;
SourRect.Bottom = 100;
DestRect.Left = 0;
DestRect.Top = 0;
DestRect.Right = SourRect.Right - SourRect.Left;
DestRect.Bottom = SourRect.Bottom - SourRect.Top;
Desktop->Handle = GetDC(NULL);
Bmp->Width = DestRect.Right;
Bmp->Height = DestRect.Bottom;
Bmp->Canvas->CopyRect(DestRect, Desktop ,SourRect);
Bmp->SaveToFile("c:\\temp\\temp.bmp");
//以下由你的代码得到
TMemoryStream *JpgStrm = new TMemoryStream();
JpgStrm->Clear();
TJPEGImage *Jpg = new TJPEGImage();
Jpg->CompressionQuality=100;
try
{
Jpg->Assign(Bmp);
Jpg->Compress();
Jpg->SaveToStream(JpgStrm);
Jpg->SaveToFile("C:\\temp\\temp.jpg");
}
__finally
{
delete Jpg;
delete JpgStrm;
}
delete Bmp;
delete Desktop;
}