Click here to Skip to main content
15,899,026 members
Home / Discussions / C#
   

C#

 
GeneralRe: TcpClient for Windows Mobile 6 Pin
leppie1-Sep-08 3:02
leppie1-Sep-08 3:02 
GeneralRe: TcpClient for Windows Mobile 6 Pin
leslie wu1-Sep-08 3:21
leslie wu1-Sep-08 3:21 
GeneralRe: TcpClient for Windows Mobile 6 Pin
leppie1-Sep-08 3:25
leppie1-Sep-08 3:25 
GeneralRe: TcpClient for Windows Mobile 6 Pin
leslie wu1-Sep-08 4:59
leslie wu1-Sep-08 4:59 
GeneralRe: TcpClient for Windows Mobile 6 Pin
leppie1-Sep-08 5:37
leppie1-Sep-08 5:37 
GeneralRe: TcpClient for Windows Mobile 6 Pin
leslie wu1-Sep-08 6:02
leslie wu1-Sep-08 6:02 
GeneralRe: TcpClient for Windows Mobile 6 Pin
leppie1-Sep-08 6:42
leppie1-Sep-08 6:42 
QuestionJPEG compression, HELP ME! Pin
thucbv31-Aug-08 23:44
thucbv31-Aug-08 23:44 
AnswerRe: JPEG compression, HELP ME! Pin
Manas Bhardwaj1-Sep-08 0:27
professionalManas Bhardwaj1-Sep-08 0:27 
AnswerRe: JPEG compression, HELP ME! Pin
blackjack21501-Sep-08 1:34
blackjack21501-Sep-08 1:34 
GeneralRe: JPEG compression, HELP ME! Pin
thucbv1-Sep-08 7:38
thucbv1-Sep-08 7:38 
GeneralRe: JPEG compression, HELP ME! Pin
blackjack21501-Sep-08 7:44
blackjack21501-Sep-08 7:44 
QuestionTracing Invalidate calls (Windows Forms) Pin
Jon Hulatt31-Aug-08 22:58
Jon Hulatt31-Aug-08 22:58 
AnswerRe: Tracing Invalidate calls (Windows Forms) Pin
Frank Horn31-Aug-08 23:58
Frank Horn31-Aug-08 23:58 
AnswerRe: Tracing Invalidate calls (Windows Forms) Pin
leppie1-Sep-08 2:11
leppie1-Sep-08 2:11 
GeneralRe: Tracing Invalidate calls (Windows Forms) Pin
Jon Hulatt1-Sep-08 2:15
Jon Hulatt1-Sep-08 2:15 
QuestionHow do I draw a single color transparently? Pin
Megidolaon31-Aug-08 22:47
Megidolaon31-Aug-08 22:47 
AnswerRe: How do I draw a single color transparently? Pin
oobimoo31-Aug-08 23:29
oobimoo31-Aug-08 23:29 
GeneralRe: How do I draw a single color transparently? Pin
Megidolaon1-Sep-08 22:56
Megidolaon1-Sep-08 22:56 
QuestionDrawing a big image to real coordinates Pin
ianhunt0131-Aug-08 22:39
ianhunt0131-Aug-08 22:39 
AnswerRe: Drawing a big image to real coordinates Pin
oobimoo1-Sep-08 0:18
oobimoo1-Sep-08 0:18 
GeneralRe: Drawing a big image to real coordinates Pin
ianhunt011-Sep-08 1:03
ianhunt011-Sep-08 1:03 
GeneralRe: Drawing a big image to real coordinates Pin
oobimoo1-Sep-08 8:19
oobimoo1-Sep-08 8:19 
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();
        }


        // pretty obvious what they do
        //
        public void ScreenToBitmap(Point[] points)
        {
            matrix_bitmap.TransformPoints(points);
        }

        public void BitmapToScreen(Point[] points)
        {
            inv_matrix_bitmap.TransformPoints(points);
        }

        public void BitmapToWorld(Point[] points)
        {
            matrix_world.TransformPoints(points);
        }

        public void WorldToBitmap(Point[] points)
        {
            inv_matrix_world.TransformPoints(points);
        }

        public void ScreenToWorld(Point[] points)
        {
            ScreenToBitmap(points);
            BitmapToWorld(points);
        }

        public void WorldToScreen(Point[] points)
        {
            WorldToBitmap(points);
            BitmapToScreen(points);
        }
    }
}

Initialize the class by passing the appropriate sizes for your world (25,000x25,000) your bitmap (6,500x6,500) your picture box (1000x1000) and your origin point (a few milions if i remember well from your prevous post). In the initial state you must have your image drawn in the picture box by the graphics.DrawImage(bitmap, 0,0,1000,1000) call. When you want to zoom into a rectangle specified by two points taken from the mouse input (e.g pointMouseDown, pointMouseUp) first you transform these points to the original bitmap coords.
Point[] pts = new Point[]{pointMouseDown,pointMouseUp};
transformation.ScreenToBitmap(pts);
// and drawing
graphics.DrawImage(bitmap,new Rectangle(0,0,1000,1000), pts[0].X,pts[0].Y,pts[1].X-pts[0].X,
pts[1].Y-pts.[0].Y,GraphicUnit.Pixel);
// dont forget to inform transformation object for the zoom
transformation.Transform(pts[0],new Size(pts[1].X-pts[0].X,ts[1].Y-pts.[0].Y);

Whenever you want you can get the world coords of a screen point with the ScreenToWorld method and vice versa.
If you want to zoom out to the initial state just graphics.DrawImage(bitmap, 0,0,1000,1000) and call the Reset method of the transformation object.
\
Regards
GeneralRe: Drawing a big image to real coordinates Pin
ianhunt012-Sep-08 5:49
ianhunt012-Sep-08 5:49 
QuestionFather class how to use the special sub-category type [modified] Pin
huangrongchuan31-Aug-08 21:43
huangrongchuan31-Aug-08 21:43 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.