|
I wanted to draw the lines with higher precision for one of my project. So instead of using point structure, I thought to make a use of pointF strucuture. I made one sample application to test how precision differs in case I use pointF strucutre then point. Following is the sample code which i written to draw a lines on my form :
protected override void OnPaint(PaintEventArgs e)
{
base.OnPaint (e);
e.Graphics.DrawLine(new Pen(System.Drawing.Color.Red),new PointF(20.0F, 100.0F), new PointF(100.0F, 100.0F));
e.Graphics.DrawLine(new Pen(System.Drawing.Color.Green),new PointF(20.0F, 100.51F), new PointF(40.0F, 100.51F));
}
As per above code, I tried to draw 2 lines with very minimal difference in y co ordinates. I was shocked to find out that pointF rounds the co ordinate value while drawing the line. As per above example, if I keep Y co ordinates for 2nd line between 100.00 to 100.50, I can see only one line drawn as lines are drawn with the same co ordinates. But if I keep the Y co ordinates for 2nd line even 100.51 then I can see two seperates lines. This means pointF strucutre rounded the y co ordinate value to 101 and that is why i could see two different line. I tried to check the things by increasing and decreasing the resolution of my screen but it didn't help. If such is the behaviour then there is no difference between the point and pointf and we can not get the better precision then 1 pixel while plotting a drawing.
Can any one pls explain me above behaviour? I want to draw the lines with higher resolution so can anyone give me the idea of how to achieve it? I hope I'm clear with my question and expectation?
|
|
|
|
|
It is impossible to get higher resolution than 1 pixel. That's the smallest point the hardware can draw, regardless of what the software asks for. The impact of rounding will vary (appear to take effect) differently on screens with a different pixel density (dpi), but pixel density can't be changed without changing the hardware.
|
|
|
|
|
Graham,
Thanks for your reply.
Rob Graham wrote: It is impossible to get higher resolution than 1 pixel
If we can not get resolution higher than 1 pixel then what is the need of having two seperates structures i.e. point and pointF. Merely passing the values in float doesn't make sense if internally it is going to get rounded off.
|
|
|
|
|
If you for an example use a transform that scales the graphics by 1000%, you can make use of the higher precision. The rounding will take place after the scaling but before the actual drawing, so if you specify a rectangle with the size 0.53 x 0.78, it will draw a rectangle with the size 5 x 8 pixels.
Have you tried to change the InterpolationMode and SmoothingMode of the Graphics object? That might change how the coordinates are rounded.
---
b { font-weight: normal; }
|
|
|
|
|
Thanks for your reply Guffa.
I see a ray of hope from your reply. I have not worked extensively on GDI. So I'm not getting exactly what you are trying to say. Can you elaborate on your reply or send me some links or material which I can refer?
|
|
|
|
|
KrunalC wrote: So I'm not getting exactly what you are trying to say.
What about it didn't you get?
---
b { font-weight: normal; }
|
|
|
|
|
Hi All.
I have 2 time 1. After
2. Before
I need to know what is the different between those time.
I will explain - After can be like date and time as 07.06.06 16:54
Before can be like date and time as 08.06.06 15:54
What i need is to know what is the time that pass from the time Before until time After.
How can i found this time ?
I need to know for example how many second from one time to the other - or how many minutes...
Thanks.
|
|
|
|
|
You can use the System.DateTime struct and its Subtruct function.
Regards,
Shy.
|
|
|
|
|
ok , and how can i calculat the different of the times ?
Pass all the Time param ? ( i meen that check if the day is same / month / hour ) ? Is there any simple way ? Like Time1 - Time 2
|
|
|
|
|
DateTime tm1 = ...;
DateTime tm2 = ...;
TimeSpan ts = tm2 - tm1;
System.Console.Writeln ("Difference in mins = " + ts.TotalMinutes); /ravi
|
|
|
|
|
When a user opens a file associated with your program you may want the new instance to pass along the file to the first instance and exit. One problematic way of doing this is using the Visaul Basic MainForm.Invoke and StartupNextInstanceEventHandler. However, this library won't work with MONO/Linux and for some reason it connects to the network while invoking the thread, triggering a nasty firewall popup.
Is there any C# alternative or is it possible to improve on the code to avoid the network and mono problems? Please and Thank you!
using System;
using System.Windows.Forms;
using Microsoft.VisualBasic.ApplicationServices;
class Program
{
[STAThread]
static void Main(string[] args) { new App().Run(args); }
class App : WindowsFormsApplicationBase
{
public App()
{
IsSingleInstance = EnableVisualStyles = true;
ShutdownStyle = Microsoft.VisualBasic.ApplicationServices.ShutdownMode.AfterMainFormCloses;
StartupNextInstance += new StartupNextInstanceEventHandler(NextInstance);
}
protected override void OnCreateMainForm()
{
MainForm = new Form1();
((Form1)MainForm).Args = new string[CommandLineArgs.Count];
CommandLineArgs.CopyTo(((Form1)MainForm).Args, 0);
}
protected void NextInstance(object sender, StartupNextInstanceEventArgs eventArgs)
{
string[] args = new string[eventArgs.CommandLine.Count];
eventArgs.CommandLine.CopyTo(args, 0);
MainForm.Invoke(new Form1.InstanceDelegate(((Form1)MainForm).processParameters), new object[] { MainForm, args });
}
}
}
public void processParameters(object sender, string[] args)
{
if (WindowState == FormWindowState.Minimized)
WindowState = FormWindowState.Normal;
if (args != null && args.Length != 0)
openFiles(args);
}
// Mikzi L. Freeman
|
|
|
|
|
Mikzi, it is possible to pass objects around to other threads:
void FooBar(object state)
{
object[] thePassedObjects = (object[])state;
}
ThreadPool.QueueUserWorkItem(FooBar, new object[] {"hello", "world", "!"});
You can pass objects to the UI thread by calling the Invoke or BeginInvoke on some Control:
delegate void OurDelegate(string s, object o, int i);
void OurFunction(string s, object o, int i)
{
}
....
myControl.Invoke((OurDelegate)OurFunction, "hello", new object(), 5);
|
|
|
|
|
This seems like a simple implementation using invoke, but I'm unsure of how to get a handle to the main instance form without using VB.net MainForm.
static void Main(string[] args)
{
bool granted;
using (Mutex mutex = new Mutex(false, "mutexName", out granted))
{
if (granted) Application.Run(new Form1());
else xxx.Invoke(new Form1.InstanceDelegate(xxx.processParameters), new object[] { xxx, args });
}
}
// Mikzi L. Freeman
|
|
|
|
|
Hi!
In order to be able to invoke a method on the first instance's form you've got to have a reference to this form, of course.
One idea would be to let the first instance register a remoting server and the second instance access this remoting server.
Perhaps this is done internally in VB.NET's MainForm, it could explain the firewall message.
You could use the new (for .NET 2.0) ipc channel instead of a tcp channel, perhaps this doesn't trigger a firewall alert.
Regards,
mav
Regards,
mav
--
Black holes are the places where god divided by 0...
|
|
|
|
|
The client server method does work. It solves the problems with not relying on Visual Basic libraries as well as working with Mono/Linux. It requires some coding however, and it needs the ip address and a port number. Might be possible to simplify the process further than this...
[STAThread]
static void Main(string[] args)
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
new App();
}
class App
{
private static Form1 mainform;
private Mutex mutex;
public App()
{
bool owned; int port = 1392;
mutex = new Mutex(false, "Form1", out owned);
if (!owned)
{
ChannelServices.RegisterChannel(new TcpChannel(), true);
string str = "tcp://" + Dns.GetHostEntry(Dns.GetHostName()).AddressList[0] + ":" + port + "/" + typeof(RemoteServer).GUID.ToString();
((RemoteServer)Activator.GetObject(typeof(RemoteServer), str)).ActivateInstance(Environment.GetCommandLineArgs());
}
else
{
ChannelServices.RegisterChannel(new TcpChannel(port), true);
RemotingConfiguration.RegisterWellKnownServiceType(typeof(RemoteServer), typeof(RemoteServer).GUID.ToString(), WellKnownObjectMode.Singleton);
Application.Run(mainform = new Form1());
}
}
private class RemoteServer : MarshalByRefObject
{
public void ActivateInstance(string[] args)
{ args[0] = null; mainform.Invoke(new Form1.InstanceDelegate(((Form1)mainform).processParameters), new object[] { mainform, args }); }
}
}
// Mikzi L. Freeman
|
|
|
|
|
iwant to know the barcode font "the name of the bar code font"
|
|
|
|
|
|
I have a dll I'm coding in one solution, and a test project in another.
Does the referenced dll reloads in the test project, after recompiling the dll?
|
|
|
|
|
|
Partially, yes...
I don't want my dll to reference the test project.
I want my test project to reference the dll, and auto update every time I recompile the dll.
Is it possible?
|
|
|
|
|
|
And just delete the test project after I'm done coding the dll?
|
|
|
|
|
No need to delete it. Each project in your solution will build to different assemblies: your test project will build to an exe (assumedly) and your dll project will build to a seperate dll. When you're done building the dll, you just use the dll and ignore the test project. They'll get built into different assemblies and different directories, so there won't be any confusion about which files belong to which project.
Tech, life, family, faith: Give me a visit.
I'm currently blogging about: Messianic Instrumentals (with audio)
The apostle Paul, modernly speaking: Epistles of Paul
Judah Himango
|
|
|
|
|
Cool! Thanks!
|
|
|
|
|
Hello
I have to use a Win32 API in a C# project (VS 2K5). I want to create a API wrapper class in C++. And then use it from my C# code.
I tried to use P/Invoke in C# to create a wrapper class, some of the methods didn’t work because Pointers to memory were not working..
QUESTION 1
Now how do I create a wrapper class, save it as dll and use it in C#. Please tell me whole procedure.
Because when I try to create a C++ project The VS2005 gives me a list of templates to choose from like “CLR Console Application” “Windows Forms Application”, etc etc
Question 2
My project has a method that continuously reads a block of PCM data from an external radio receiver connected to the computer through USB.
Is there and way to listen to that signal through C#. IS PCM just like audio signal … if not how do I convert it into audio.
------------------------------------------------------------------------------------------------
I am writing an example of the function I have to write and tell me what type of project I have to make and what procedure I have to follow.
<br />
#include "stdafx.h"<br />
#include <stdio.h><br />
#include <windows.h><br />
<br />
typedef int (__stdcall *FNCOpenRadioDevice)(int iDeviceNum);<br />
typedef BOOL (__stdcall *FNCCloseRadioDevice)(int hRadio);<br />
typedef BOOL (__stdcall *FNCSetAtten)(int hRadio, BOOL fAtten);<br />
typedef BOOL (__stdcall *FNCSetPower)(int hRadio, BOOL fPower);<br />
typedef BOOL (__stdcall *FNCSetAGC)(int hRadio, int iAGC);<br />
typedef BOOL (__stdcall *FNCCodecStart)(int hRadio,void (__stdcall *CallbackFunc)(void *),<br />
void *CallbackTarget);<br />
typedef BOOL (__stdcall *FNCCodecStop)(int hRadio);<br />
typedef unsigned int (__stdcall *FNCCodecRead)(int hRadio,void *Buf,unsigned int Size);<br />
<br />
typedef struct {<br />
int hRadio;<br />
FILE *IFFile;<br />
FNCCodecRead CodecRead;<br />
} CallbackContext;<br />
<br />
void __stdcall CodecCallback(void *Target)<br />
{<br />
unsigned int i;<br />
char Buf[4096];<br />
CallbackContext *Ctx=(CallbackContext *)Target;<br />
<br />
while ((i=Ctx->CodecRead(Ctx->hRadio,Buf,sizeof(Buf)))!=0) <br />
fwrite(Buf,i,1,Ctx->IFFile);<br />
}<br />
int main(int argc, char* argv[])<br />
{<br />
HMODULE dll=LoadLibraryA("wrg303api.dll");<br />
if (!dll) {puts("WRG303API.DLL not found !"); return 0;}<br />
<br />
FNCOpenRadioDevice OpenRadioDevice=(FNCOpenRadioDevice)GetProcAddress(dll,"OpenRadioDevice");<br />
FNCCloseRadioDevice CloseRadioDevice=(FNCCloseRadioDevice)GetProcAddress(dll,"CloseRadioDevice");<br />
FNCSetAtten SetAtten=(FNCSetAtten)GetProcAddress(dll,"SetAtten");<br />
FNCSetPower SetPower=(FNCSetPower)GetProcAddress(dll,"SetPower");<br />
FNCSetAGC SetAGC=(FNCSetAGC)GetProcAddress(dll,"SetAGC");<br />
FNCCodecStart CodecStart=(FNCCodecStart)GetProcAddress(dll,"CodecStart");<br />
FNCCodecStop CodecStop=(FNCCodecStop)GetProcAddress(dll,"CodecStop");<br />
FNCCodecRead CodecRead=(FNCCodecRead)GetProcAddress(dll,"CodecRead");<br />
<br />
int hRadio=OpenRadioDevice(0);<br />
if (!hRadio) {puts("No WR-G303 device could be opened !");FreeLibrary(dll); return 0;}<br />
<br />
if (SetPower(hRadio,TRUE)) puts("The device is turned ON"); else puts("The device failed to turn ON");<br />
if (SetAtten(hRadio,FALSE)) puts("The attenuator is OFF"); else puts("The attenuator failed to turn OFF");<br />
if (SetAGC(hRadio,3)) puts("The AGC is FAST"); else puts("The AGC failed to switch");<br />
<br />
FILE *f=fopen("IF2.pcm","wb");<br />
<br />
CallbackContext Ctx;<br />
<br />
Ctx.hRadio=hRadio;<br />
Ctx.IFFile=f;<br />
Ctx.CodecRead=CodecRead;<br />
if (!CodecStart(hRadio,CodecCallback,&Ctx)) puts("Codec streaming couldn't be started!");<br />
else {<br />
puts("Codec streaming properly started!");<br />
while (!ftell(f) ) <br />
{<br />
}<br />
CodecStop(hRadio);<br />
fclose(f);<br />
}<br />
<br />
if (CloseRadioDevice(hRadio)) puts("The device is closed properly"); else puts("The device failed to close");<br />
<br />
FreeLibrary(dll);<br />
<br />
return 0;<br />
}<br />
o O º(`'·.,(`'·., ☆,.·''),.·'')º O o°
»·'"`»* *☆ t4ure4n ☆* *«·'"`«
°o O º(,.·''(,.·'' ☆`'·.,)`'·.,)º O o°
|
|
|
|
|