|
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
{
Matrix matrix_world;
Matrix inv_matrix_world;
Matrix matrix_bitmap;
Matrix inv_matrix_bitmap;
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;
matrix_world.Scale(worldSize.Width / (float)bitmap_size.Width,
worldSize.Height / (float)bitmap_size.Height);
matrix_world.Translate(worldOrigin.X,
worldOrigin.Y , MatrixOrder.Append);
inv_matrix_world = matrix_world.Clone();
inv_matrix_world.Invert();
Reset();
}
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();
}
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();
}
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);
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);
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
|
|
|
|
|
Awesome,
Thanks a lot - the whole matrix issue was a bit daunting but it makes more sense now. I will dig in right now and try it out.
cheers
Ian
|
|
|
|
|
Father class how to use the special sub-category type (such as the sub-class form TableAdapter of a table), the current idea is traversal all the things on the form(such as traversing all controls on the sub-form), if found what I need, I want to transform its type into I want. But now what trouble me is i could not get the type neither trying to change the object into the type I needed nor using reflection to get the type. Thanks a lot.
Code is as follows:
private void findcontrol(Control.ControlCollection controls)
{
foreach (Control ctrl in controls)
{
if (ctrl.GetType().Name == "XXTableAdapter")
{
}
findcontrol(ctrl.Controls);
}
}
|
|
|
|
|
Did you run your question through an automatic translator or something? I can hardly understand a thing.
Try again...
Despite everything, the person most likely to be fooling you next is yourself.
|
|
|
|
|
apologize for my poor english first,i have writen the question again ,could you understand what i want to say now
|
|
|
|
|
It would be better if you posted the actual code that you try to use. It's hard to tell which errors in the code comes from mistakes typing it in and which errors it is that cause the actual problem.
You can do like this to get access to controls of a specific type:
private void findcontrol(Control.ControlCollection controls) {
foreach (Control ctrl in controls) {
WhateverControlYouWant whatEver = ctrl as WhateverControlYouWant;
if (whatEver != null) {
}
findcontrol(ctrl.Controls);
}
}
Here's a generic version of the method, taking a type and a delegate for whatever to do with the control:
private void ProcessControls<T>(Control.ControlCollection controls, Action<T> action) {
foreach (Control ctrl in controls) {
T t = ctrl as T;
if (t != null) {
action(t);
}
ProcessControls<T>(ctrl.Controls, action);
}
}
Usage example:
ProcessControls<Button>(this, delegate(Button b){ b.Enabled = false; });
Despite everything, the person most likely to be fooling you next is yourself.
modified on Monday, September 1, 2008 12:45 PM
|
|
|
|
|
Thanks a lot.I could understand the first example and i will improve my code.And i will try the second example since i haven`t used such kind of type(ProcessControls<t>).
But what truely trouble me now is the special type i want just could find on the sub-class.In my case,the XXTableAdapter was defind when i added a Dataset in the project.But when i designing the father class i could not used this type.
modified on Monday, September 1, 2008 10:06 PM
|
|
|
|
|
from gmail to aol, without change in any of message data....
|
|
|
|
|
are you trying to do that in a C# program??
if so then id imagine youd have to use gmail's and aol's API's if they even have any...
|
|
|
|
|
If we will use imap.... its possible or not? I gone through RFC3501(IMAP), also overviewed RFC2822(Internet Message format). But i am not getting any clue. I build connection and mail fetch program. but what next for tranfer?
|
|
|
|
|
Hello
Do someone know how to get the device id of a pocket PC?
Best regards
dghdfghdfghdfghdgh
|
|
|
|
|
Please check this link
[^]
Cheers!!
Brij
|
|
|
|
|
how do i deploy it to my pocket
dghdfghdfghdfghdgh
|
|
|
|
|
I want to get a parameter(for example "Path of Data") from user in commandline.
How can I do it?
Hello Friends
|
|
|
|
|
Your Main method accepts a string array as a parameter. This contains what the user (or a shortcut) passed from the command line.
Cheers,
Vıkram.
"if abusing me makes you a credible then i better give u the chance which didnt get in real" - Adnan Siddiqi.
|
|
|
|
|
Please find below:
public static void Main (string[] args)
{
if (args.Length > 0)
{
System.Console.WriteLine (args[0]);
try
{
long number = long.Parse (args[0]);
System.Console.WriteLine ("Number = " + number);
}
catch (System.FormatException e)
{
System.Console.WriteLine ("FormatException" + e);
}
return;
}
System.Console.WriteLine ("Please enter a number");
}
Cheers!!
Brij
|
|
|
|
|
There's this cunning command called GetCommandLineArgs in the Environment class. This should help.
|
|
|
|
|
|
I wonder what exactly you want. But for getting the controls on a page you can have a loop like this
foreach (Controls c in this.Controls)
Ahsan Ullah
Senior Software Engineer
|
|
|
|
|
I have seen some strings formatted like @"Hello World!", or something like that in code i have downloaded on the internet, and i was really wondering what that '@' symbol does. What's the difference between "Hello World!" and @"Hello World!"? Just curious.
void Play() { try { throw Ball(); } catch (Glove) { } finally { Play(); } }
"Failure is only the opportunity to begin again, this time more wisely."
"Don't ask for a light load, but rather ask for a strong back."
|
|
|
|
|
In the case of @"Hello World!" I don't believe it does anything. However
in a directory string
@"C:\Program Files\Common Files"
you don't have to escape the "\" like you would with out it.
"C:\\Program Files\\Common Files"
|
|
|
|
|
|
Ok, thanks. Live and learn.
void Play() { try { throw Ball(); } catch (Glove) { } finally { Play(); } }
"Failure is only the opportunity to begin again, this time more wisely."
"Don't ask for a light load, but rather ask for a strong back."
|
|
|
|
|
I use it a lot when I want large strings, like pieces of xml, to be readable in code.
with @ you can write something like this:
string xml = @"
<xml>
<test>
<value>1</value>
<value>2</value>
</test>
</xml>"
instead of:
string xml = "<xml><test><value>1</value><value>2</value></test></xml>"
Dawn is nature's way of telling you to go to bed.
|
|
|
|