Esempio n. 1
1
// fires an event when a file, or files are dropped onto the application.
void __fastcall TForm1::WMDropFiles(TWMDropFiles &message)
{ AnsiString FileName;
  FileName.SetLength(MAX_PATH);
  FileName.SetLength(DragQueryFile((HDROP)message.Drop, 0,FileName.c_str(), MAX_PATH));

  if(UpperCase(ExtractFileExt(FileName)) == ".BMP")
  {   bmp->LoadFromFile(FileName) ;
      img->Picture->Bitmap->Assign(bmp) ;
  } else if(UpperCase(ExtractFileExt(FileName)) == ".JPG")
         {   TJPEGImage * jpeg = new TJPEGImage();
             jpeg->LoadFromFile(FileName);
             jpeg->DIBNeeded();   
             bmp->Assign(jpeg);
             img->Picture->Bitmap->Assign(bmp) ;
             delete jpeg;
         }
  preview->frmSelect->Position = 0 ;
  outType->ItemIndex = 1 ;
  if(preview->Visible) updatePreview();
  int l = bmp->Width, h = bmp->Height ;
  transType->ItemIndex = 0 ;
  //preview->TransparentColor = 0 ;
  // auto compute frame number and frameset way
   if(l < 142 || h < 142)
    {  
       int s ; int yyop ; int *v=&h, *vh=&l ;
       if(l > h*2) { v=&l ; vh=&h ; vertical=0 ; } // horizontal frameset
       else vertical = 1 ;
       flipWay->Checked = !vertical ;
       s = *vh + 3 ;
       do { yyop = (*v)/s ; } while(s && yyop*s-- != *v) ; ++s ;
       if(s < 4)
       {  frmNb->Text = 1 ;
          sprintf(msg,"frames of %i*%i",l,h) ;
          LabelSize->Caption = msg ; fsx = l ; fsy = h ;
       }
       else {nb = yyop ; fsx = s ; fsy = *vh ;
             frmNb->Text = yyop ;
             sprintf(msg,"frames of %i*%i",s,*vh) ;
             LabelSize->Caption = msg ;
       }
    } else { frmNb->Text = 1 ;
             sprintf(msg,"frames of %i*%i",l,h) ;
             LabelSize->Caption = msg ;
             nb=1 ;
           }
  preview->ClientHeight = h ;
  preview->ClientWidth  = l + (nb > 1)*15 ;
  preview->Caption      = FileName + " (" + nb + ")" ;
  fname = FileName ;
  outTypeChange((TObject*)42) ;
  Form1->Button1->Enabled = 1 ;
  Form1->Height = 304 ;
  Form1->StatusBar->Visible = 1 ;
  // tell the OS that you're finished...
  DragFinish((HDROP) message.Drop);
}
void __fastcall TForm1::OpenPicture1Click(TObject *Sender)
{
    OpenPictureDialog1->Filter =
       "Bmp files (*.bmp)|*.BMP| JPEG images (*.jpg) | *.jpg; " ;
    if (OpenPictureDialog1->Execute())
    {
        if (!FileExists(OpenPictureDialog1->FileName))
            return;
        AnsiString temp2 = ExtractFileName(OpenPictureDialog1->FileName);
        AnsiString temp = ExtractFileExt(OpenPictureDialog1->FileName);
        AnsiString Ext = temp.LowerCase();

        if (Ext.AnsiPos("jpg") > 0)
        {
            TJPEGImage *myjpeg = new TJPEGImage();
            myjpeg->LoadFromFile(OpenPictureDialog1->FileName);
            myjpeg->DIBNeeded();
            Image1->Picture->Bitmap->Assign(myjpeg);
            delete myjpeg;
        }
        else if (Ext.AnsiPos("bmp") > 0)
        {
            Image1->Picture->Bitmap->LoadFromFile(OpenPictureDialog1->FileName);
        }
    }
        {
        Undo1->Enabled=false; //apenergopoioume ta undo/redo
        Redo1->Enabled=false;
        ToolUndo->Enabled=false;
        ToolRedo->Enabled=false;
        }
}