heightmap theme now auto resizes, but warns when doing so.

This commit is contained in:
UnknownShadow200 2018-12-09 13:17:00 +11:00
parent f7636da0d3
commit b0ba0294d3
2 changed files with 21 additions and 6 deletions

View File

@ -145,7 +145,7 @@ namespace MCGalaxy.Commands.Building {
width = resizedWidth; height = resizedHeight; width = resizedWidth; height = resizedHeight;
} }
Bitmap Resize(Bitmap bmp, int width, int height) { static Bitmap Resize(Bitmap bmp, int width, int height) {
Bitmap resized = new Bitmap(width, height); Bitmap resized = new Bitmap(width, height);
using (Graphics g = Graphics.FromImage(resized)) { using (Graphics g = Graphics.FromImage(resized)) {
g.InterpolationMode = InterpolationMode.HighQualityBicubic; g.InterpolationMode = InterpolationMode.HighQualityBicubic;

View File

@ -17,6 +17,7 @@
*/ */
using System; using System;
using System.Drawing; using System.Drawing;
using System.Drawing.Drawing2D;
using System.IO; using System.IO;
using System.Net; using System.Net;
using MCGalaxy.Network; using MCGalaxy.Network;
@ -78,11 +79,11 @@ namespace MCGalaxy.Generator {
if (bmp == null) return false; if (bmp == null) return false;
int index = 0, oneY = lvl.Width * lvl.Length; int index = 0, oneY = lvl.Width * lvl.Length;
using (bmp) { try {
if (lvl.Width != bmp.Width || lvl.Length != bmp.Height) { if (lvl.Width != bmp.Width || lvl.Length != bmp.Height) {
p.Message("The size of the heightmap is {0} by {1}.", bmp.Width, bmp.Height); p.Message("&cSize of the heightmap does not match Width x Length of the map");
p.Message("The width and length of the new level must match that size."); p.Message("&cAs such, the map may not look accurate.");
return false; bmp = Resize(bmp, lvl.Width, lvl.Length);
} }
using (PixelGetter pixels = new PixelGetter(bmp)) { using (PixelGetter pixels = new PixelGetter(bmp)) {
@ -110,10 +111,24 @@ namespace MCGalaxy.Generator {
index++; index++;
} }
} }
} // Cannot use using { } here because bmp may be reassigned
} finally { bmp.Dispose(); }
return true; return true;
} }
static Bitmap Resize(Bitmap bmp, int width, int height) {
Bitmap resized = new Bitmap(width, height);
using (Graphics g = Graphics.FromImage(resized)) {
g.InterpolationMode = InterpolationMode.NearestNeighbor;
g.SmoothingMode = SmoothingMode.None;
g.PixelOffsetMode = PixelOffsetMode.None;
g.DrawImage(bmp, 0, 0, width, height);
}
bmp.Dispose();
return resized;
}
static bool IsShorterBy(int height, PixelGetter pixels, int x, int z) { static bool IsShorterBy(int height, PixelGetter pixels, int x, int z) {
if (x >= pixels.Width || x < 0 || z >= pixels.Height || z < 0) return false; if (x >= pixels.Width || x < 0 || z >= pixels.Height || z < 0) return false;
int neighbourHeight = pixels.Get(x, z).R; int neighbourHeight = pixels.Get(x, z).R;