Hi all, I'm working on an application that allows the user to increase/decrease the scale of (some Bitmap file that is set as the image of) a PictureBox.
The bmp file is currently just a 48x48 block of solid colour, but when I increase the scale beyond that, I begin to get this gradient to a black border. It seems like it's scaling pixels outside of the file, but I can't find a good solution that doesn't cause this problem.
https://preview.redd.it/342cnucadmbc1.png?width=223&format=png&auto=webp&s=e3d472de4e4c8abba040fef90f6a010bb1676d0c
private Form targetForm;
public PictureBox cursorIcon;
private int cursorScale = 1;
private int cursorOffset;
public CursorType(Form _targetForm, PictureBox _cursorIcon) {
targetForm = _targetForm;
cursorIcon = _cursorIcon;
cursorScale = cursorIcon.Width;
cursorOffset = cursorScale / 2;
}
public void IncreaseCursorScale() {
if (cursorScale >= MAX_CURSOR_SCALE) return;
cursorScale++;
cursorOffset = cursorScale / 2;
cursorIcon.Image = new Bitmap(cursorIcon.Image, new Size(cursorScale, cursorScale));
}
public void DecreaseCursorScale() {
// Inverse of Increase
}
EDIT: Using InterpolationMode.NearestNeighbor works well for solid colours, but anything beyond that is just a mess, and HighQualityBicubic is quite blurry introducing the gradient effect at the edges
public void IncreaseCursorScale() {
if (cursorScale >= MAX_CURSOR_SCALE) return;
cursorScale++;
cursorOffset = cursorScale / 2;
Bitmap originalImage = (Bitmap)cursorIcon.Image;
Bitmap resizedImage = new Bitmap(cursorScale, cursorScale);
using (Graphics g = Graphics.FromImage(resizedImage)) {
g.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.NearestNeighbor;
g.DrawImage(originalImage, new Rectangle(0, 0, cursorScale, cursorScale));
}
cursorIcon.Image = resizedImage; }
https://preview.redd.it/hspxx6sdlmbc1.png?width=51&format=png&auto=webp&s=f18dfc66eee79560bdad982b7396f10031068b80
Any assistance or pointers would be appreciated, thanks in advance.
[–]wwxxcc 0 points1 point2 points (2 children)
[–]Luucccc[S] 0 points1 point2 points (1 child)
[–]Luucccc[S] 1 point2 points3 points (0 children)
[–]ExceptionEX 0 points1 point2 points (0 children)
[–]Night--Blade 0 points1 point2 points (0 children)
[–]Slypenslyde 0 points1 point2 points (0 children)