Ir para conteúdo

POWERED BY:

Arquivado

Este tópico foi arquivado e está fechado para novas respostas.

Ilano

Dimensionar imagens usando o componente Image

Recommended Posts

Olá pessoal,

 

Estou fazendo um web site e preciso saber como faço para dimensionar um grupo de imagens em um quadro de tamanho único, ou seja, qualquer imagem q abrir deverá caber neste quadro, tem como fazer isso?

 

Grato,

 

Ilano.

Compartilhar este post


Link para o post
Compartilhar em outros sites

Veja se essa função te ajuda:public static Bitmap ScaleBitmap(Bitmap inputBmp, double xScaleFactor, double yScaleFactor) { //Create a new bitmap object based on the input Bitmap newBmp = new Bitmap( (int)(inputBmp.Size.Width * xScaleFactor), (int)(inputBmp.Size.Height * yScaleFactor), PixelFormat.Format24bppRgb);//Graphics.FromImage doesn't like Indexed pixel format //Create a graphics object attached to the new bitmap Graphics newBmpGraphics = Graphics.FromImage(newBmp); //Set the interpolation mode to high quality bicubic //interpolation, to maximize the quality of the scaled image newBmpGraphics.InterpolationMode = InterpolationMode.HighQualityBicubic; newBmpGraphics.ScaleTransform((float)xScaleFactor, (float)yScaleFactor); //Draw the bitmap in the graphics object, which will apply //the scale transform //Note that pixel units must be specified to ensure the framework doesn't attempt //to compensate for varying horizontal resolutions in images by resizing; in this case, //that's the opposite of what we want. Rectangle drawRect = new Rectangle(0, 0, inputBmp.Size.Width, inputBmp.Size.Height); newBmpGraphics.DrawImage(inputBmp, drawRect, drawRect, GraphicsUnit.Pixel); //Return the bitmap, as the operations on the graphics object //are applied to the bitmap newBmpGraphics.Dispose(); //newBmp will have a RawFormat of MemoryBmp because it was created //from scratch instead of being based on inputBmp. Since it it inconvenient //for the returned version of a bitmap to be of a different format, now convert //the scaled bitmap to the format of the source bitmap return ConvertBitmap(newBmp, inputBmp.RawFormat); }

Compartilhar este post


Link para o post
Compartilhar em outros sites

×

Informação importante

Ao usar o fórum, você concorda com nossos Termos e condições.