1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50
|
TJPEGImage *jp = new TJPEGImage();
Graphics::TBitmap *Bitmap = new Graphics::TBitmap;
if(OpenDialog1->Execute())
{
Image1->Picture = NULL;
Image1->Height = 401;
Image1->Width = 401;
if(ExtractFileExt(OpenDialog1->FileName).LowerCase() == ".jpeg" || ExtractFileExt(OpenDialog1->FileName).LowerCase() == ".jpg")
{
jp->LoadFromFile(OpenDialog1->FileName);
Bitmap->Height = jp->Height;
Bitmap->Width = jp->Width;
Dimensions.x = jp->Width;
Dimensions.y = jp->Height;
if(jp->Height <= Image1->Height && jp->Width <= Image1->Width)
{//chargerment de l'image taille normale
Image1->Width = jp->Width;
Image1->Height= jp->Height;
Image1->Canvas->Draw(0,0,jp);
Image1->Stretch = false;
}
else if(jp->Height >= jp->Width)
{//chargement de l'image redimensionné en gardant les proportions
//aligné sur sa hauteur
Image1->Width = (float)jp->Width/(float)jp->Height*Image1->Height;
Bitmap->Canvas->Draw(0,0,jp);
Image1->Picture->Bitmap->Assign(Bitmap);
Image1->Stretch = true;
}
else
{//chargement de l'image redimensionné en gardant les proportions
//aligné sur sa largeur
Image1->Height= (float)jp->Height/(float)jp->Width*Image1->Width;
Bitmap->Canvas->Draw(0,0,jp);
Image1->Picture->Bitmap->Assign(Bitmap);
Image1->Stretch = true;
}
}
else
{
Image1->Picture->LoadFromFile(OpenDialog1->FileName);
}
Buffer->Assign(Image1->Picture);
}
delete jp;
delete Bitmap; |