| Ver tema anterior :: Ver tema siguiente |
| Autor |
Mensaje |
code1980 Invitado
|
Publicado: Jue 28 Abr, 2005 10:32 am Asunto: Cargar una imagen según el tamaño |
|
|
Hola a todos,
Estoy intentando hacer una especie de album de fotos, pero no todas mis fotos tienen las mismas dimensiones. Cómo puedo hacer para cargar en un TImage un archivo para que se vea la imagen completa (las dimensiones de la imagen es mayor que la del TImage)?
He buscado por el foro pero no termino de encontrar lo que busco.
Gracias a todos. |
|
| Volver arriba |
|
 |
rayder Master

Registrado: 03 Mar 2004Mensajes: 207
|
Publicado: Jue 28 Abr, 2005 11:12 am Asunto: |
|
|
Por lo que comentas, puedes poner la propiedad AutoSize del TImage a True, de esta forma el TImage se ajustará automáticamente a las dimensiones de la imagen que estas cargando, y para refrescar la imagen cargada.
| Código: |
Image1->Picture->LoadFromFile("D:\\imagen\\imagen.bmp");
Image1->Refresh();
|
_________________ Un saludo
Rayder |
|
| Volver arriba |
|
 |
code1980 Invitado
|
Publicado: Jue 28 Abr, 2005 11:33 am Asunto: |
|
|
| Gracias por tu respuesta rayder, pero lo que necesito es justamente lo contrario, que la imagen se ajuste al tamaño del TImage. |
|
| Volver arriba |
|
 |
rayder Master

Registrado: 03 Mar 2004Mensajes: 207
|
Publicado: Jue 28 Abr, 2005 6:10 pm Asunto: |
|
|
Buscando por la ayuda del builder 6 ent, he localizado lo siguiente:
| Código: |
You can replace the picture in an image control at any time. If you assign a new graphic to a picture that already has a graphic, the new graphic replaces the existing one.
To replace the picture in an image control, assign a new graphic to the image control’s Picture object.
Creating the new graphic is the same process you used to create the initial graphic , but you should also provide a way for the user to choose a size other than the default size used for the initial graphic. An easy way to provide that option is to present a dialog box.
With such a dialog box in your project, add an include statement for BMPDlg.hpp in the .cpp file for your main form. You can then attach an event handler to the File|New menu item’s OnClick event. Here’s an example:
void __fastcall TForm1::New1Click(TObject *Sender)
{
Graphics::TBitmap *Bitmap;
// make sure focus is on width field
NewBMPForm->ActiveControl = NewBMPForm->WidthEdit;
// initialize to current dimensions as default ...
NewBMPForm->WidthEdit->Text = IntToStr(Image->Picture->Graphic->Width);
NewBMPForm->HeightEdit->Text = IntToStr(Image->Picture->Graphic->Height);
if (NewBMPForm->ShowModal() != IDCANCEL){ // if user does not cancel dialog...
Bitmap = new Graphics::TBitmap(); // create a new bitmap object
// use specified dimensions
Bitmap->Width = StrToInt(NewBMPForm->WidthEdit->Text);
Bitmap->Height = StrToInt(NewBMPForm->HeightEdit->Text);
Image->Picture->Graphic = Bitmap; // replace graphic with new bitmap
CurrentFile = EmptyStr; //indicate unnamed file
}
}
Note: Assigning a new bitmap to the picture object’s Graphic property causes the picture object to destroy the existing bitmap and take ownership of the new one. The VCL handles the details of freeing the resources associated with the previous bitmap automatically.
|
Lo que ocurre es que me da un error de compilación. Al incluir el BMPDlg.hpp, me dice, entre otras cosas
| Código: |
[C++ Error] Unit1.cpp(7): E2209 Unable to open include file 'BMPDlg.hpp'
|
he buscado por el ordenador, pero no lo he encontrado el dichoso ficheros BMPDlg.hpp
Te lo pongo por si te puede orientar, sigo con el tema. _________________ Un saludo
Rayder |
|
| Volver arriba |
|
 |
_Leo Site Admin

Registrado: 11 Ago 2002Mensajes: 1875Ubicación: Lanzarote - Islas Canarias (España)
|
Publicado: Jue 28 Abr, 2005 6:35 pm Asunto: |
|
|
| Si usas C++Builder 6 puedes poner la propiedad "Proportional" a "true". Y si usas una versión anterior puedes hacerlo jugando con la propiedad "Stretch" y las dimensiones del TImage. |
|
| Volver arriba |
|
 |
rayder Master

Registrado: 03 Mar 2004Mensajes: 207
|
Publicado: Vie 29 Abr, 2005 1:16 pm Asunto: |
|
|
Pues como siempre, Leo aporta su saber.
En builder 6 funciona a la perfección, lo probaré en builder 5, pero en casa, en el curro tengo 6. _________________ Un saludo
Rayder |
|
| Volver arriba |
|
 |
|