//--------------------------------------------------------------------------- #include #pragma hdrstop #include "ViewImage.h" #include "Main.h" //--------------------------------------------------------------------------- #pragma package(smart_init) #pragma link "TPStretchImage" #pragma resource "*.dfm" TImageViewForm *ImageViewForm; //--------------------------------------------------------------------------- __fastcall TImageViewForm::TImageViewForm(TComponent* Owner) : TForm(Owner) { } //--------------------------------------------------------------------------- void __fastcall TImageViewForm::FormCreate(TObject *Sender) { if (Width>Screen->Width) Left = 100; else Left = (Screen->Width-Width)/2; if (Height>Screen->Height) Top = 100; else Top = (Screen->Height-Height)/2; sbmp = NULL; tbmp = NULL; zoom = 1; } //--------------------------------------------------------------------------- void __fastcall TImageViewForm::sbZoomInClick(TObject *Sender) { if (zoom < 2) { zoom = zoom*2; ViewZoom(); ShowBitmap(); } } //--------------------------------------------------------------------------- void __fastcall TImageViewForm::sbZoomOutClick(TObject *Sender) { if (zoom > 0.5) { zoom = zoom/2; ViewZoom(); ShowBitmap(); } } //--------------------------------------------------------------------------- void __fastcall TImageViewForm::ViewZoom() { AnsiString str; if (zoom == 0.5) { str = " 1/2 "; } else if (zoom == 2) { str = " 2/1 "; } else { str = " 1 "; } Edit->Text = str; } //--------------------------------------------------------------------------- void __fastcall TImageViewForm::FormDestroy(TObject *Sender) { if (sbmp) { delete sbmp; sbmp = NULL; } if (tbmp) { delete tbmp; tbmp = NULL; } } //--------------------------------------------------------------------------- void __fastcall TImageViewForm::MakeBitmap(TTexpiaBitmap *tmp) { HDC shDC = NULL, thDC = NULL; if (sbmp) { delete sbmp; sbmp = NULL; } if ((sbmp = new TTexpiaBitmap) == NULL) goto fail; if (!(sbmp->Create(tmp->Width, tmp->Height, 24))) goto fail; if ((shDC = sbmp->CreateDC()) == NULL) goto fail; if ((thDC = tmp->CreateDC()) == NULL) goto fail; BitBlt(shDC, 0, 0, tmp->Width, tmp->Height, thDC, 0, 0, SRCCOPY); tmp->DeleteDC(thDC); sbmp->DeleteDC(shDC); ShowBitmap(); return; fail: if (shDC) tmp->DeleteDC(shDC); if (sbmp) { delete sbmp; sbmp = NULL; } ShowMessage("Bitmap copy fails!"); } //--------------------------------------------------------------------------- void __fastcall TImageViewForm::ShowBitmap() { int ww, hh; HDC shDC = NULL, thDC = NULL; if (tbmp) { delete tbmp; tbmp = NULL; } if ((tbmp = new TTexpiaBitmap) == NULL) goto fail; if (!(tbmp->Create(sbmp->Width*zoom, sbmp->Height*zoom, 24))) goto fail; Image->Width = tbmp->Width; Image->Height = tbmp->Height; Image->Bitmap = tbmp; if ((shDC = sbmp->CreateDC()) == NULL) goto fail; if ((thDC = tbmp->CreateDC()) == NULL) goto fail; if (zoom == 1) { BitBlt(thDC, 0, 0, sbmp->Width, sbmp->Height, shDC, 0, 0, SRCCOPY); } else { StretchBlt(thDC, 0, 0, tbmp->Width, tbmp->Height, shDC, 0, 0, sbmp->Width, sbmp->Height, SRCCOPY); } tbmp->DeleteDC(thDC); sbmp->DeleteDC(shDC); Image->Repaint(); return; fail: if (shDC) sbmp->DeleteDC(shDC); if (tbmp) { delete tbmp; tbmp = NULL; } ShowMessage("Bitmap copy fails!"); } //---------------------------------------------------------------------------