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**);
}
精彩评论