jpeg 이미지를 업로드하고 데이터베이스에 바이트 배열로 저장하고 있습니다. 그러나 내가 이미지를 검색하고 '다른 이름으로 저장'을 선택하면 이미지가 PNG가되고 파일 크기가 60-70 % 커집니다. 다음은 변환을 수행하는 함수입니다. 아무도 왜 이것이 일어나고 있는지 제안 할 수 있습니까?업로드 된 jpeg를 바이트 배열로 변환 할 때 png로 끝나나요?
는private byte[] ResizeImage(UploadedFile file, int maxWidth, int maxHeight)
{
int canvasWidth = maxWidth;
int canvasHeight = maxHeight;
using (Bitmap originalImage = new Bitmap(file.InputStream))
{
int originalWidth = originalImage.Width;
int originalHeight = originalImage.Height;
Bitmap thumbnail = new Bitmap(canvasWidth, canvasHeight); // create thumbnail canvas
using (Graphics g = Graphics.FromImage((System.Drawing.Image)thumbnail))
{
g.SmoothingMode = SmoothingMode.Default;
g.InterpolationMode = InterpolationMode.Default;
g.PixelOffsetMode = PixelOffsetMode.Default;
//Get the ratio of original image
double ratioX = (double)canvasWidth/(double)originalWidth;
double ratioY = (double)canvasHeight/(double)originalHeight;
double ratio = ratioX < ratioY ? ratioX : ratioY; // use which ever multiplier is smaller
// Calculate new height and width
int newHeight = Convert.ToInt32(originalHeight * ratio);
int newWidth = Convert.ToInt32(originalWidth * ratio);
// Calculate the X,Y position of the upper-left corner
// (one of these will always be zero)
int posX = Convert.ToInt32((canvasWidth - (originalWidth * ratio))/2);
int posY = Convert.ToInt32((canvasHeight - (originalHeight * ratio))/2);
//g.Clear(Color.White); // Add white padding
g.DrawImage(originalImage, posX, posY, newWidth, newHeight);
}
/* Display uploaded image preview */
ImageConverter converter = new ImageConverter();
byte[] imageData = (byte[])converter.ConvertTo(thumbnail, typeof(byte[])); // Convert thumbnail into byte array and set new binary image
return imageData;
}
}
저는 C# 전문가는 아니지만 'Bitmap originalImage = new Bitmap (file.InputStream)'을 사용하여 JPG를 비트 맵으로 변환하는 것입니까? PNG는 비트 맵 형식이므로 'originalImage'는 PNG로 제공됩니다. – gaborsch