내가 asp.net.NET의 Drawing.Graphics.FromImage()가 빈 검은 이미지
에 업로드 된 JPEG 크기를 조정하기 위해 노력하고있어 반환은 그래서 이동 :
이Image original = Image.FromStream(myPostedFile.InputStream);
int w=original.Width, h=original.Height;
using(Graphics g = Graphics.FromImage(original))
{
g.ScaleTransform(0.5f, 0.5f); ... // e.g.
using (Bitmap done = new Bitmap(w, h, g))
{
done.Save(Server.MapPath(saveas), ImageFormat.Jpeg);
//saves blank black, though with correct width and height
}
}
이 처녀 검은 JPEG 저장 어떤 나는 그것을 준다. 내가 done
비트 맵으로 바로 입력 이미지 스트림을 경우 비록, 그것은 다시 압축 않고 같이 잘 저장 :
Image original = Image.FromStream(myPostedFile.InputStream);
using (Bitmap done = new Bitmap(original))
{
done.Save(Server.MapPath(saveas), ImageFormat.Jpeg);
}
내가 g 몇 가지 마술을해야합니까?
UPD : 내가 시도 :
Image original = Image.FromStream(fstream);
int w=original.Width, h=original.Height;
using(Bitmap b = new Bitmap(original)) //also tried new Bitmap(w,h)
using (Graphics g = Graphics.FromImage(b))
{
g.DrawImage(original, 0, 0, w, h); //also tried g.DrawImage(b, 0, 0, w, h)
using (Bitmap done = new Bitmap(w, h, g))
{
done.Save(Server.MapPath(saveas), ImageFormat.Jpeg);
}
}
같은 이야기 - 정확한 치수의 순수한 검은
감사합니다. 나는 조금 다르게했지만 코드는 좋은 그림이었습니다 – joox
** 이미지의 배경이있는 곳을 정확히 ** 정확히 채웠습니까 **? –
g.DrawImage 줄에 (img, drect); ,이 코드는 백그라운드를 채 웁니다! – Myra