I'm doing quite a bit of graphics work that involves displaying material on a cartesian coordinate graph using GDI+ methods (DrawLine, DrawRectangle, etc) in the Paint routines of a PictureBox.
I'm always having to deal with scaling, rotation matrices and the other complications because the picturebox needs to have it's 'world' scaled rotated and translated before displaying normal Cartesian coords properly. Even with all this, it's always extra work to handle the fact that pens and some other graphics objects then draw their sizes transformed as well, and mouse events don't necessarily return points correctly.
Many years ago, I used TrueBasic and it had a drawing component that you could set up as simple as giving the width, height and everything transformed accordingly. I'm looking for a dotnet component that will give me a similiar object so I can stop having to customize the existing picturebox. Paid components are fine, but I have to be able to use GDI+ to draw in it or it must support something similiar. I do *not* want to use graphing/charting components that require the graphics objects/points to be stored in their own arrays or other unique systems. I want to do the drawing myself.
please use System.Drawing namespace in your project.
where you find the Graphics class which will give you all option to Draw anything by using cartesian co-ordinate system.
public partial class WaveDisplay : UserControl
int _XDivision; //Total X Division
[DefaultValue(10.0f)]//1 Volt per Division
[DefaultValue(10.0f)]//1 Sec per Division
public int XDivisions
_XDivision = value;
public int YDivisions
_YDivision = value;
public float VoltagePerDivision
_voltsPerDivision = value;
public float TimePerDivision
_timePerDivision = value;
public override Image BackgroundImage
base.BackgroundImage = value;
public override ImageLayout BackgroundImageLayout
base.BackgroundImageLayout = value;
_voltsPerDivision = 10.0f;
_timePerDivision = 10.0f;
_XDivision = 10;
_YDivision = 10;
_s = new Sample();
protected override void OnPaint(PaintEventArgs e)
Graphics g = e.Graphics;
if (BackgroundImage != null)
Brush b = null;
b = new SolidBrush(this.BackColor);
Pen pen = new Pen(ForeColor);
Rectangle r = new Rectangle(ClientRectangle.Left, ClientRectangle.Top, ClientRectangle.Width, ClientRectangle.Height);
r.Inflate(new Size((int)(-ClientRectangle.Width * 0.1f),(int) (-ClientRectangle.Height * 0.1f)));
double xPixelPerDiv = (double)r.Width / (double)_XDivision;
double yPixelPerDiv = (double)r.Height /(double)_YDivision;
double TimePerUnit = _timePerDivision/_XDivision;
double VoltsPerUnit = _voltsPerDivision/_YDivision;
string s1 = null;
for (int i = 0; i <= _XDivision; i++)
g.DrawLine(pen, new Point((int)(r.Left + xPixelPerDiv * i), r.Top),
new Point((int)(r.Left + xPixelPerDiv * i), r.Bottom));
s1 = (_timePerDivision * i).ToString();
g.DrawString(s1, Font, new SolidBrush(ForeColor), new PointF((int)(r.Left + xPixelPerDiv * i), r.Bottom + 10));
for (int i = 0; i <= _YDivision; i++)
g.DrawLine(pen, new Point((int)(r.Left), (int)(r.Bottom - i * yPixelPerDiv)),
new Point((int)(r.Right), (int)(r.Bottom - i * yPixelPerDiv)));
s1 = (_voltsPerDivision * i).ToString();
g.DrawString(s1, Font, new SolidBrush(ForeColor), new PointF(r.Left - 15, (int)(r.Bottom - yPixelPerDiv * i)));
Thanks, I'm aware that the math can be done manually. I was hoping for a third-party component so I could focus my efforts elsewhere and not have to focus on writing code for the existing drawing components.
I learnt from an article I read that dx11 can't be used with vb in ease way. So, the available tutorials are limited to dx 5, 6, 7, 8 and 9. And my system has dx11 installed. So, I wanted to un-install dx11 and replace it with dx 8 or 9 but is not successful because dx 1r is higher than 8 and 9. How can I do the replacement?
The runtime is used by most games and may be already installed if you have installed some games on your system. The SDK is only required if you want to use DX for your own programs (it includes the runtime).
From the above runtime download link:
The DirectX runtime cannot be uninstalled
So you should try to use your version first. If you really need a development system with an older DX version, you must setup one using an old Windows version.
I am following a request to write C++ code for a label that contains several text elements in one single line, varying by font, size, color.... Ok, that can be done easily in GDI+ by measuring each element's width and then execute a DrawString for each of the text elements starting at its calculated position.
So far, I failed miserably.
The horizontal text positions did not appear to be correct. I reverted now to very simple text measuring tests which confused me even more.
Test 1: Use of MeasureString
With the same font, the width of the string "MM" does not match the double with of the string "M". This cannot be explained with eventual rounding problems.
Test2: Use of MeasureCharacterRanges
Used the same font as for the first test. The width of "MM" is now exactly double of the width of "M". But: The width of the "M" ist lightyears away from the measurement result in the first test.
I have added one more test which is using standard GDI, and I have changed the GDI+ font to units of pixels. Unfortunately, this third test shows results which do not match the previous results at all.
Does anybody have an idea why I get so different results?
Since I had not only added a third test but also changed the code of the first tests I am appending the full example here; the results I found have been added as comments:
void ApplWindow_TextDrawTest(HDC hDC)
Gdiplus::Graphics *G = new Gdiplus::Graphics(hDC);
Gdiplus::Font TextFont(L"Calibri", 36, Gdiplus::FontStyle::FontStyleBold, Gdiplus::Unit::UnitPixel);
constwchar_t *Text1M = L"M";
Gdiplus::PointF TextOrigin1M(0, 0);
constwchar_t *Text2M = L"MM";
Gdiplus::PointF TextOrigin2M(0, 50);
//--- Test #1: using MeasureString ----------
G->MeasureString(Text1M, (INT)wcslen(Text1M), &TextFont, TextOrigin1M, &MyFormat, &TextBounds1M);
G->MeasureString(Text2M, (INT)wcslen(Text2M), &TextFont, TextOrigin2M, &MyFormat, &TextBounds2M);
//--- Results: Text 1 Width= 44.414 ("M")//--- Text 2 Width= 76.828 ("MM")//--- Test #2: using MeasureCharacterRanges ----------
Gdiplus::RectF LayoutRect(0, 0, 1000, 100);
CRanges.First = 0; CRanges.Length = 1;
CRanges.First = 1; CRanges.Length = 1;
CRanges.First = 0; CRanges.Length = 2;
G->MeasureCharacterRanges(Text2M, (INT)wcslen(Text2M), &TextFont, LayoutRect, &MyFormat, 3, RegionsList);
RCode = RegionsList.GetBounds(&TextBounds1M, G); // Result: Text 1 Width = 32.000 ("M")
RCode = RegionsList.GetBounds(&TextBounds1M, G); // Result: Text 1 Width = 32.000 ("M"; the second char)
RCode = RegionsList.GetBounds(&TextBounds2M, G); // Result: Text 2 Width = 64.000 ("MM")//--- Test #3: using the good old GDI ----------int MapModeResult = SetMapMode(hDC, MM_TEXT); // MM_TEXT is equivalent to Unit::UnitPixel?
HFONT TextFont3 = CreateFont(36, 0, 0, 0, FW_BOLD, false, false, false, ANSI_CHARSET, OUT_TT_ONLY_PRECIS, CLIP_DEFAULT_PRECIS, CLEARTYPE_QUALITY, VARIABLE_PITCH | FF_DONTCARE, L"Calibri");
HGDIOBJ PrevFont = SelectObject(hDC, TextFont3);
BOOL RFlg = GetCharABCWidthsFloat(hDC, (UINT)'M', (UINT)'M', &ABCCharData); // Results: abcfA = 2.000; abcfB = 22.000; abcfC = 2.000//--- End of Test ---delete G;
I am looking for an image editor control to integrate with my asp.net website project.I have tried Telerik "RadImageEditor" but it does not fulfill my needs like.
1-Control Canvas size.
2-Save image with Provided DPI
3-After Saving can edit the Saved image (like in photoshop where objects are seperate and can be edited any time after) if this is not possible then it should have selection option so that i can select any part of image and can edit it.
can u pls suggest me some controls that can itegrate with asp.net website project.
I once heard that one of the advantages of PNG (over jpg eg.) is that when used on a webpage the image comes through in "blocks" making the site more responsive, while jpg had to be loaded in "one go".
Did I dream this or is this really so?
(I could only find things like transparancy, better for logo's etc... where jpg is better for real photos)
I thought it was the other way round. You can use progressive jpg where the image starts blocky and is rendered in increasing detail as the rest arrives.
PNG does have a rep for being better for 'geometric' stuff as opposed to photos.
Software rusts. Simon Stephenson, ca 1994. So does this signature. me, 2012
That's not quite right. You can have an interlaced JPG just as easily as you can have a progressive PNG. Where PNG has the advantage is if you save it as progressive. Progressive PNGs use a two dimensional interlace, which results in it doing 7 passes, instead of 4 passes - which means that you see something within 1/64 of the time you would see the whole item.
It's worth being aware that no matter which option you choose, you would end up increasing the size of the none progressive/interlaced image.
progressive JPG (an uncommon but perfectly legal variation) allows for JPGs to be transferred in a series of images, each with higher resolution. the final image gets sharper as you go.
interlaced PNG allows you to transfer pixels out of the standard order - they are transferred in a fixed pattern that's basically an ever-finer grid. the receiver would just the duplicate pixels it has received until all have been transferred.
any speedup depends entirely on the reader being smart enough to display the images progressively.
privatevoid openGLControl_OpenGLDraw(object sender, RenderEventArgs e)
// Get the OpenGL object.
OpenGL gl = openGLControl.OpenGL;
// Clear the color and depth buffer.
gl.Clear(OpenGL.GL_COLOR_BUFFER_BIT | OpenGL.GL_DEPTH_BUFFER_BIT);
gl.Color(1.0f, 1.0f, 1.0f);
for (i = 0; i <= 30; i++)
gl.EvalCoord1((float)i / 30.0);
// display the control points
gl.Color(1.0f, 1.0f, 0.0f);
for (i = 0; i <4; i++)
The &ctrlpoints[i] in gl.Vertex(&ctrlpoints[i]) was displayed to be an error.
What error; please do not expect people to guess what messages you are seeing. I cannot find a description for either a Vertex function, or class constructor; is this something you have created yourself?
I am working in C++. I am trying to draw a perpendicular hash mark from the start of a sloped line. My code below draws a perpendicular line but when the slope of the original line changes the hash mark appears to change length. When the line is close to horizontal the hash mark looks longest and shortest when the line is close to vertical. I believe the problem is the fixed value for HashLength. Can you show a better way to calculate the end of the perpendicular line(px2,py2) so my hash mark always looks the same size.