Re: Convert BMP to JPG (Full Source Code)


2004-07-25 12:39:19 AM
cppbuilder19
{
//initializations
int H,W;
TScreen *MyScr;
TCanvas *Canvas1 = new TCanvas;
Graphics::TBitmap *bmp = new Graphics::TBitmap();
TJPEGImage *jpg = new TJPEGImage();
AnsiString FN;
randomize();
//jobs todo :-)
H=MyScr->DesktopHeight;
W=MyScr->DesktopWidth;
Canvas1->Handle =GetDC(0);//What is this?
TRect destRect = Rect(0,0,W,H);//All around the desktop
TRect sourceRect;
sourceRect = destRect;
Image1->Canvas->CopyRect(destRect,Canvas1,sourceRect);
bmp=Image1->Picture;//<------- Problem !!
jpg->Assign(bmp);
Image1->Picture=jpg;
// jpg->Assign(Image1->Picture);
// jpg->Assign(what??????);
FN="jpgfile#"+IntToStr(random(100))+".jpg";
jpg->SaveToFile(FN);
//MyStuff
ReleaseDC(0,Canvas1->Handle);
//Finalizations
delete Canvas1;
delete jpg;
delete bmp;
}
Hi I was trying to get a BMP from a TImage that contains JPEG format image
file,
then I was in trouoble and when I see you wrote Image1->Picture->Bitmap I
got what can I do.
Then The Code above is changed to code below and its working for me
I realy approciate Hans Galema and Michael :-) @};-
///==================================================
//initializations
int H,W;
TScreen *MyScr;
TCanvas *Canvas1 = new TCanvas;
Graphics::TBitmap *bmp = new Graphics::TBitmap();
TJPEGImage *jpg = new TJPEGImage();
AnsiString FN;
randomize();
//jobs todo :-)
H=MyScr->DesktopHeight;
W=MyScr->DesktopWidth;
Canvas1->Handle =GetDC(0);
TRect destRect = Rect(0,0,W,H);
TRect sourceRect;
sourceRect = destRect;
Image1->Canvas->CopyRect(destRect,Canvas1,sourceRect);
bmp=Image1->Picture->Bitmap;//<------- Problem is Solved!!
jpg->Assign(bmp);
FN="jpgfile#"+IntToStr(random(100))+".jpg";
jpg->SaveToFile(FN);
Image1->Stretch=true;//<---- New Problem ,
//My Image is not sretching although I set strech property to
true
ReleaseDC(0,Canvas1->Handle);
//Finalizations
delete Canvas1;
delete jpg;
delete bmp;
}
///==================================================
Can you tell me what GetDC(0) means?
thx