1
I have a method to which I pass the parameter System.Drawing.Image
and the percentage that this image will get after the resize.
public static Image ResizeImagem(Image imgFoto, int percentual)
{
float nPorcentagem = ((float)percentual / 100);
int fonteLargura = imgFoto.Width; //armazena a largura original da imagem origem
int fonteAltura = imgFoto.Height; //armazena a altura original da imagem origem
int origemX = 0; //eixo x da imagem origem
int origemY = 0; //eixo y da imagem origem
int destX = 0; //eixo x da imagem destino
int destY = 0; //eixo y da imagem destino
//Calcula a altura e largura da imagem redimensionada
int destWidth = (int)(fonteLargura * nPorcentagem);
int destHeight = (int)(fonteAltura * nPorcentagem);
//Cria um novo objeto bitmap
Bitmap bmImagem = new Bitmap(destWidth, destHeight, PixelFormat.Format24bppRgb);
//Define a resolu~ção do bitmap.
bmImagem.SetResolution(imgFoto.HorizontalResolution, imgFoto.VerticalResolution);
//Crima um objeto graphics e defina a qualidade
Graphics grImagem = Graphics.FromImage(bmImagem);
grImagem.InterpolationMode = InterpolationMode.HighQualityBicubic;
//Desenha a imge usando o método DrawImage() da classe grafica
grImagem.DrawImage(imgFoto,
new Rectangle(destX, destY, destWidth, destHeight),
new Rectangle(origemX, origemY, fonteLargura, fonteAltura),
GraphicsUnit.Pixel);
grImagem.Dispose(); //libera o objeto grafico
return bmImagem;
}
But I need to get the size of this file, in bytes for me to perform the Resize
until the image is 200KB.
You need the size of any file, right? Has any special reason for this to be directly related to
System.Drawing.Image
?– Maniero
@bigown, I have a method that gets Image, I will post
– Rod
@bigown I edited the question, I think it became clearer
– Rod
I don’t think so. It either didn’t help or confirmed what I was saying, no matter what’s in this file, you want its size and period. It would be clearer if you show that being an image makes a difference. I’ll answer what I think solves the problem. If it’s not that, you talk and I try to get better.
– Maniero