PicEdt.cpp
上传用户:hylc_2004
上传日期:2014-01-23
资源大小:46800k
文件大小:3k
源码类别:

Delphi控件源码

开发平台:

Delphi

  1. //---------------------------------------------------------------------------
  2. #include <vcl.h>
  3. #pragma hdrstop
  4. #include "PicEdt.h"
  5. #include "fcCommon.hpp"
  6. //---------------------------------------------------------------------------
  7. #pragma package(smart_init)
  8. #pragma resource "*.dfm"
  9. TfcPicEditor *fcPicEditor;
  10. //---------------------------------------------------------------------------
  11. __fastcall TfcPicEditor::TfcPicEditor(TComponent* Owner)
  12.         : TForm(Owner)
  13. {
  14. }
  15. //---------------------------------------------------------------------------
  16. bool TfcPicEditor::ExecutePictureEditor(TGraphic* AGraphic, TPersistent* DestGraphic)
  17. {
  18.   bool retVal = false;
  19.   TfcPicEditor* PicEditor = new TfcPicEditor(Application);
  20.   PicEditor->StoredImage->Assign(AGraphic);
  21.   PicEditor->UpdateImage();
  22.   if (PicEditor->ShowModal() == Controls::mrOk) {
  23.     retVal = true;
  24.     DestGraphic->Assign(PicEditor->StoredImage->Graphic);
  25.   }
  26.   PicEditor->Free();
  27.   return retVal;
  28. }
  29. //---------------------------------------------------------------------------
  30. void TfcPicEditor::UpdateImage()
  31. {
  32.   if (StoredImage->Graphic != NULL && !StoredImage->Graphic->Empty) {
  33.     SIZE s = fcSize(StoredImage->Width, StoredImage->Height);
  34.     if (StoredImage->Width > Image->Width || StoredImage->Height > Image->Height) {
  35.       if (StoredImage->Width > Image->Height)
  36.         s = fcSize(Image->Width, Image->Width * StoredImage->Height / StoredImage->Width);
  37.       else s = fcSize(Image->Height * StoredImage->Width / StoredImage->Height, Image->Height);
  38.     }
  39.     Image->Picture->Bitmap->Width = s.cx;
  40.     Image->Picture->Bitmap->Height = s.cy;
  41.     Image->Picture->Bitmap->Canvas->StretchDraw(Rect(0, 0, s.cx, s.cy), StoredImage->Graphic);
  42.     ImagePanel->Caption = "";
  43.   } else {
  44.     Image->Picture->Bitmap->Assign(NULL);
  45.     Image->Repaint();
  46.     ImagePanel->Caption = "(None)";
  47.   }
  48. }
  49. //---------------------------------------------------------------------------
  50. void __fastcall TfcPicEditor::LoadButtonClick(TObject *Sender)
  51. {
  52.   if (OpenDialog->Execute()) {
  53.     StoredImage->LoadFromFile(OpenDialog->FileName);
  54.     UpdateImage();
  55.   }
  56. }
  57. //---------------------------------------------------------------------------
  58. void __fastcall TfcPicEditor::SaveButtonClick(TObject *Sender)
  59. {
  60.   if (SaveDialog->Execute()) StoredImage->SaveToFile(SaveDialog->FileName);
  61. }
  62. //---------------------------------------------------------------------------
  63. void __fastcall TfcPicEditor::ClearButtonClick(TObject *Sender)
  64. {
  65.   StoredImage->Free();
  66.   StoredImage = new TPicture;
  67.   UpdateImage();
  68. }
  69. //---------------------------------------------------------------------------
  70. void __fastcall TfcPicEditor::FormCreate(TObject *Sender)
  71. {
  72.   StoredImage = new TPicture;        
  73. }
  74. //---------------------------------------------------------------------------
  75. void __fastcall TfcPicEditor::FormDestroy(TObject *Sender)
  76. {
  77.   StoredImage->Free();        
  78. }
  79. //---------------------------------------------------------------------------