I need to change that from 100 * 100, to 50 * 50Code:Bitmap bmp = new Bitmap(tileImageList[currentMap[i, k]]);
Any idea's how?
the bitmap is an image of mine..
Printable View
I need to change that from 100 * 100, to 50 * 50Code:Bitmap bmp = new Bitmap(tileImageList[currentMap[i, k]]);
Any idea's how?
the bitmap is an image of mine..
You can't resize an existing Bitmap object. You have to create a new Bitmap object using the constructor that takes dimensions, create a Graphics object for it, then use the appropriate overload of Garphics.DrawImage to draw the original Bitmap onto the new one at the desired location with the desired size. The original will be scaled accordingly.
Thanks
Well, I have tested it with an image, and it cuts the image off, is my code incorrect?
ThanksCode:private Bitmap resizeBitmap(Bitmap bitmap, Size newSize)
{
Bitmap bmp = new Bitmap(newSize.Width, newSize.Height);
Graphics g = Graphics.FromImage(bmp);
g.DrawImage(bitmap, new Point(0, 0));
bitmap.Dispose();
bitmap = null;
g.Dispose();
g = null;
return bmp;
}
Try this:
c# Code:
private Bitmap resizeBitmap(Bitmap bitmap, Size newSize) { Bitmap bmp = new Bitmap(newSize.Width, newSize.Height); Graphics g = Graphics.FromImage(bmp); g.DrawImage(bitmap, new Rectangle(Point.Empty, newSize)); bitmap.Dispose(); bitmap = null; g.Dispose(); g = null; return bmp; }
Also, for such things where you would like to change an existing variable, it is often cumbersome to have to declare a new variable just to hold the new bitmap. In this case, the ref keyword shines. If I were you, I would tackle the problem like this:
Where calling it would be something like this:Code:private void ResizeBitmap(ref Bitmap sourceBitmap, Size destinationSize)
{
Bitmap newBmp = new Bitmap(destinationSize.Width, destinationSize.Height);
Graphics graphics = Graphics.FromImage(newBmp);
graphics.DrawImage(sourceBitmap, new Rectangle(Point.Empty, destinationSize));
sourceBitmap = newBmp;
}
Code:Bitmap bmpToResize = new Bitmap(@"C:\Documents and Settings\Fromethius\My Documents\My Pictures\Character.bmp");
ResizeBitmap(ref bmpToResize, new Size(70, 70));
e.Graphics.DrawImage(bmpToResize, Point.Empty);
Thanks, @ your second post, my images are from my Resources; not a file path..
Err.. It doesn't really matter. It was just an example. Just supply a Bitmap as the parameter..
:ehh: