Drawing a big image to real coordinates
-
Hi, I have got a big topographical jpg file that I want to display in a form on a picturebox in its real coordinates that ranges X from 50 000 to 75 000 and Y from 2 800 000 to 2 825 000. this will make it very easy for me to get the mouse coords in real coords as the user invokes the Mousedown event. It will also make it easier for me to draw real features in its real coordinates. I have got the code:
Image image = Image.FromFile(@"C:\Images\2529DA.jpg");
Pen myPen = new Pen(Color.Black);
Graphics formGraphics = this.picGrid.CreateGraphics();
formGraphics.Clear(picGrid.BackColor);formGraphics.DrawImage(image, 0, 0, 1000, 1000);
This shows the topomap nicely on the screen but with the local picturebox coords from 0 to 1000. If I change the code to
formGraphics.DrawImage(image, 50000, 2800000, 25000, 25000);
This previous code then puts the map WAY offscreen to the south-east ! I tried fiddling with the following code but no luck.
formGraphics.DrawImageUnscaled(image,0, 0);
formGraphics.DrawImageUnscaledAndClipped(image, rect1);please help ! cheers Ian
-
Hi, I have got a big topographical jpg file that I want to display in a form on a picturebox in its real coordinates that ranges X from 50 000 to 75 000 and Y from 2 800 000 to 2 825 000. this will make it very easy for me to get the mouse coords in real coords as the user invokes the Mousedown event. It will also make it easier for me to draw real features in its real coordinates. I have got the code:
Image image = Image.FromFile(@"C:\Images\2529DA.jpg");
Pen myPen = new Pen(Color.Black);
Graphics formGraphics = this.picGrid.CreateGraphics();
formGraphics.Clear(picGrid.BackColor);formGraphics.DrawImage(image, 0, 0, 1000, 1000);
This shows the topomap nicely on the screen but with the local picturebox coords from 0 to 1000. If I change the code to
formGraphics.DrawImage(image, 50000, 2800000, 25000, 25000);
This previous code then puts the map WAY offscreen to the south-east ! I tried fiddling with the following code but no luck.
formGraphics.DrawImageUnscaled(image,0, 0);
formGraphics.DrawImageUnscaledAndClipped(image, rect1);please help ! cheers Ian
-
You want to fit a 25000x25000 bitmap in a 1000x1000 bitmap without losing precision? :wtf:
Yes, (I mean yes, I want to loose the precision in order to know where he is) I need to get the user to select an area he wants to zoom into with the mouse. I want to get the e.X and e.Y of the beginning and end of his zoom and redraw the image meaning i have to move and scale the image with this new info. I checked later and saw that the image has a resolution of 6500 x 6500 although it covers and area of 25 kilometers by 25 kilometers. Does this help ? Ian
-
Yes, (I mean yes, I want to loose the precision in order to know where he is) I need to get the user to select an area he wants to zoom into with the mouse. I want to get the e.X and e.Y of the beginning and end of his zoom and redraw the image meaning i have to move and scale the image with this new info. I checked later and saw that the image has a resolution of 6500 x 6500 although it covers and area of 25 kilometers by 25 kilometers. Does this help ? Ian
Use the following class
using System;
using System.Drawing;
using System.Drawing.Drawing2D;namespace some_namespace
{
class Transformation
{
// world: the real world your bitmap represents
// bitmap: your (unscaled) bitmap
// screen: the portion of the screen that you display the image (a picture box maybe)Matrix matrix\_world; // bitmap to world Matrix inv\_matrix\_world; // world to bitmap Matrix matrix\_bitmap; // screen to bitmap Matrix inv\_matrix\_bitmap; // bitmap to screen Size bitmap\_size; Size screen\_size; public Transformation(PointF worldOrigin, SizeF worldSize, Size bitmapSize, Size screenSize) { matrix\_world = new Matrix(); matrix\_bitmap = new Matrix(); bitmap\_size = bitmapSize; screen\_size = screenSize; // if you want the native y-points up coord system for the world, uncomment '-' and // '+ worldSize.Height' below matrix\_world.Scale(worldSize.Width / (float)bitmap\_size.Width, /\* - \*/ worldSize.Height / (float)bitmap\_size.Height); matrix\_world.Translate(worldOrigin.X, worldOrigin.Y /\* + worldSize.Height \*/, MatrixOrder.Append); inv\_matrix\_world = matrix\_world.Clone(); inv\_matrix\_world.Invert(); Reset(); } // Reset transformation to the 'screen portion displays entire bitmap' public void Reset() { matrix\_bitmap.Reset(); matrix\_bitmap.Scale((float)bitmap\_size.Width / (float)screen\_size.Width, (float)bitmap\_size.Height / (float)screen\_size.Height); inv\_matrix\_bitmap = matrix\_bitmap.Clone(); inv\_matrix\_bitmap.Invert(); } // transform to 'screen portion displays the rectangular portion of the bitmap // defined by the displayOrigin point and the displaySize' public void Transform(PointF displayOrigin, SizeF displaySize) { matrix\_bitmap.Reset(); matrix\_bitmap.Scale(displaySize.Width / (float)screen\_size.Width, displaySize.Height / (float)screen\_size.Height); matrix\_bitmap.Translate(displayOrigin.X, displayOrigin.Y, MatrixOrder.Append); inv\_matrix\_bitmap = matrix\_bitmap.Clone(); inv\_matrix\_bitmap.Invert(); }
-
Use the following class
using System;
using System.Drawing;
using System.Drawing.Drawing2D;namespace some_namespace
{
class Transformation
{
// world: the real world your bitmap represents
// bitmap: your (unscaled) bitmap
// screen: the portion of the screen that you display the image (a picture box maybe)Matrix matrix\_world; // bitmap to world Matrix inv\_matrix\_world; // world to bitmap Matrix matrix\_bitmap; // screen to bitmap Matrix inv\_matrix\_bitmap; // bitmap to screen Size bitmap\_size; Size screen\_size; public Transformation(PointF worldOrigin, SizeF worldSize, Size bitmapSize, Size screenSize) { matrix\_world = new Matrix(); matrix\_bitmap = new Matrix(); bitmap\_size = bitmapSize; screen\_size = screenSize; // if you want the native y-points up coord system for the world, uncomment '-' and // '+ worldSize.Height' below matrix\_world.Scale(worldSize.Width / (float)bitmap\_size.Width, /\* - \*/ worldSize.Height / (float)bitmap\_size.Height); matrix\_world.Translate(worldOrigin.X, worldOrigin.Y /\* + worldSize.Height \*/, MatrixOrder.Append); inv\_matrix\_world = matrix\_world.Clone(); inv\_matrix\_world.Invert(); Reset(); } // Reset transformation to the 'screen portion displays entire bitmap' public void Reset() { matrix\_bitmap.Reset(); matrix\_bitmap.Scale((float)bitmap\_size.Width / (float)screen\_size.Width, (float)bitmap\_size.Height / (float)screen\_size.Height); inv\_matrix\_bitmap = matrix\_bitmap.Clone(); inv\_matrix\_bitmap.Invert(); } // transform to 'screen portion displays the rectangular portion of the bitmap // defined by the displayOrigin point and the displaySize' public void Transform(PointF displayOrigin, SizeF displaySize) { matrix\_bitmap.Reset(); matrix\_bitmap.Scale(displaySize.Width / (float)screen\_size.Width, displaySize.Height / (float)screen\_size.Height); matrix\_bitmap.Translate(displayOrigin.X, displayOrigin.Y, MatrixOrder.Append); inv\_matrix\_bitmap = matrix\_bitmap.Clone(); inv\_matrix\_bitmap.Invert(); }