开发者

Drawing Image size auto-increases, System.Drawing.Image, C#, ASP.NET

开发者 https://www.devze.com 2023-03-03 23:35 出处:网络
I want to draw an image by reading it from file sytem image file, and render it on a document, below: if (File.Exists(imageFilePath))//all image file are 16*16 in pixel

I want to draw an image by reading it from file sytem image file, and render it on a document, below:

if (File.Exists(imageFilePath))   //all image file are 16*16 in pixel
                {
                    Bitmap bitmap = new Bitmap(18, 18);
                    Graphics graphics = Graphics.FromImage(bitmap);

                    Image image = Image.FromFil开发者_JAVA技巧e(imageFilePath);
                    graphics.DrawImage(image, 1, 1); //1 pixel space in between
                }

However, gray images renders the correct size (18*18 in pixel), whereas, colour images are cut off, or have to increase the BitMap size (e.g. Bitmap(23, 23). I want to all images have the same size! The image sizes are all the same on the file system.

It is a bit of urgency. Any idea would be very much appreicated!

Solution below:

   if (File.Exists(imageFilePath))
            {
                Bitmap bitmap = new Bitmap(18, 18);
                Graphics graphics = Graphics.FromImage(bitmap);

                Image image = Image.FromFile(imageFilePath);
                graphics.DrawImage(image, 1, 1, **18, 18**);                  

            }
0

精彩评论

暂无评论...
验证码 换一张
取 消