diff --git a/Tests/Kernels/GraphicTest/Kernel.cs b/Tests/Kernels/GraphicTest/Kernel.cs index d6a6a43516..ab9d54f599 100644 --- a/Tests/Kernels/GraphicTest/Kernel.cs +++ b/Tests/Kernels/GraphicTest/Kernel.cs @@ -117,7 +117,9 @@ private void DoTest(Canvas aCanvas) aCanvas.DrawImage(bitmap, new Point(0, 0)); aCanvas.DrawImage(bitmap2, new Point(200, 0)); - + //Scale Bitmap + aCanvas.DrawImage(bitmap,0,0,50,50); + aCanvas.DrawImageAlpha(bitmap3, new Point(0, 300)); /* Drawing ellipses */ diff --git a/source/Cosmos.System2/Graphics/Canvas.cs b/source/Cosmos.System2/Graphics/Canvas.cs index 427f1d084b..bd5d6efca7 100644 --- a/source/Cosmos.System2/Graphics/Canvas.cs +++ b/source/Cosmos.System2/Graphics/Canvas.cs @@ -855,7 +855,48 @@ public virtual void DrawImage(Image image, int x, int y) } } } - + + private int[] scaleImage(Image image, int newWidth, int newHeight) + { + int[] pixels = image.rawData; + int w1 = (int)image.Width; + int h1 = (int)image.Height; + int[] temp = new int[newWidth * newHeight]; + int x_ratio = (int)((w1 << 16) / newWidth) + 1; + int y_ratio = (int)((h1 << 16) / newHeight) + 1; + int x2, y2; + for (int i = 0; i < newHeight; i++) + { + for (int j = 0; j < newWidth; j++) + { + x2 = ((j * x_ratio) >> 16); + y2 = ((i * y_ratio) >> 16); + temp[(i * newWidth) + j] = pixels[(y2 * w1) + x2]; + } + } + return temp; + } + /// + /// Draw a Scaled Bitmap. + /// + /// Image to Scale. + /// X coordinate. + /// Y coordinate. + /// Desired Width. + /// Desired Height. + public virtual void DrawImage(Image image, int x, int y,int w,int h) + { + int[] pixels = scaleImage(image, w, h); + for (int _x = 0; _x < w; _x++) + { + for (int _y = 0; _y < h; _y++) + { + Global.mDebugger.SendInternal(pixels[_x + _y * w]); + DrawPoint(new Pen(Color.FromArgb(pixels[_x + _y * w])), x + _x, y + _y); + } + } + } + /// /// Draw image with alpha channel. ///