|
There's no reason why it wouldn't work in C#. But I do recommend he use pointers to work with the bitmap bits.
"Blessed are the peacemakers, for they shall be called sons of God." - Jesus
"You must be the change you wish to see in the world." - Mahatma Gandhi
|
|
|
|
|
I'm not sure exactly what causes this, I did notice that you're not skipping the word alignment bytes. This rarely causes a problem, though, even though it's not recommended.
Also, what method are you using in the C++ DLL to create the DIB?
Also, have you considered using pointers, rather than Marshall.ReadByte/WriteByte?
"Blessed are the peacemakers, for they shall be called sons of God." - Jesus
"You must be the change you wish to see in the world." - Mahatma Gandhi
|
|
|
|
|
Thanks so much for your help!
On the brink of insanity, I stumbled across a solution, from who else but a CodeProject contributor, Thomas. He wrote a Twain interface for .NET that can be found here:
http://www.codeproject.com/dotnet/twaindotnet.asp. His class contains code for extracting a Bitmap from a HBITMAP.
This has certainly been a tough intro to C# for me! I find it strange that the GDI+ library has a FromBITMAPINFO() function that takes a pointer to a BITMAPINFO structure and the bits and returns a new Bitmap object. However, this is not exposed in C#.
|
|
|
|
|
Hello,
I wanted to know if you think that it is possible to write a control based on RichTextBox so that it can support the page view (like word)?
Or it is better to write this component basing it on Control?
Or do you have another option?
Thanks a lot for your answers..
Kerad
|
|
|
|
|
|
Can someone show me how to draw a raised rectangle on a form using GDI+ ?
When the user click the rectangle, then it must be lower.
KeyDown = lower;
KeyUp = raised;
Thanks
|
|
|
|
|
I need something like this:
System.Drawing.Graphics formGraphics = null;
System.Drawing.Pen myPen;
formGraphics = pictureBox1.CreateGraphics();
myPen = new System.Drawing.Pen(System.Drawing.Color.Black,1);
formGraphics.DrawLine(myPen, 5, 5, 105, 5);
formGraphics.DrawLine(myPen, 15, 35, 95, 35);
formGraphics.DrawLine(myPen, 5, 5, 15, 35);
formGraphics.DrawLine(myPen, 105, 5, 95, 35);
SolidBrush darkGrayBrush = new SolidBrush(Color.Gray);
Point point1 = new Point(5, 5);
Point point2 = new Point(105, 5);
Point point3 = new Point(15, 35);
Point point4 = new Point(95, 35);
Point point5 = new Point(5, 5);
Point point6 = new Point(15, 35);
Point point7 = new Point(105, 5);
Point point8 = new Point(95, 35);
Point[] curvePoints = new Point[]
{
point1,
point2,
point3,
point4,
point5,
point6,
point7,
point8
};
formGraphics.FillPolygon(darkGrayBrush, curvePoints);
but just raised, lower and clickable.
How?
|
|
|
|
|
So you need a rounded-edge rectangle? Right now I have the code for a raised, sunken, etched, or bump border for a rectangle, but not for a rounded-edge rectangle.
"Blessed are the peacemakers, for they shall be called sons of God." - Jesus
"You must be the change you wish to see in the world." - Mahatma Gandhi
|
|
|
|
|
jdunlap:
Can you show me the code for a raised / sunken rectangle?
|
|
|
|
|
If you just need sunken and raised borders, you can use .NET's built-in implementation - System.Windows.Forms.ControlPaint.DrawBorder:
But the ControlPaint.DrawBorder method doesn't do etched and bump borders, where as the code below does:
public enum BorderStyle
{
Raised,Sunken,Etched,Bump
};
public static void DrawBorder(Graphics g,
Rectangle rect,
BorderStyle border,
Color color)
{
BorderStyle inner=BorderStyle.Raised;
BorderStyle outer=BorderStyle.Raised;
switch(border)
{
case BorderStyle.Raised:
inner=BorderStyle.Raised;
outer=BorderStyle.Raised;
break;
case BorderStyle.Sunken:
inner=BorderStyle.Sunken;
outer=BorderStyle.Sunken;
break;
case BorderStyle.Etched:
inner=BorderStyle.Raised;
outer=BorderStyle.Sunken;
break;
case BorderStyle.Bump:
inner=BorderStyle.Sunken;
outer=BorderStyle.Raised;
break;
}
DrawThinBorder(g,rect,outer,color,inner==outer);
rect.Offset(1,1);
rect.Width-=2;rect.Height-=2;
DrawThinBorder(g,rect,inner,color,false);
}
public static void DrawThinBorder(Graphics g,
Rectangle rect,
BorderStyle border,
Color color)
{DrawThinBorder(g,rect,border,color,false);}
public static void DrawThinBorder(Graphics g,
Rectangle rect,
BorderStyle border,
Color color,
bool outer)
{
if(border==BorderStyle.Raised)
{
DrawUpperCorner(g,rect,new Pen((outer?ColorHelper.LightenColor(color,1):color)));
DrawLowerCorner(g,rect,new Pen(ColorHelper.DarkenColor(color,(outer?3:1))));
}else
{
DrawUpperCorner(g,rect,new Pen(ColorHelper.DarkenColor(color,(outer?1:2))));
DrawLowerCorner(g,rect,new Pen((outer?ColorHelper.LightenColor(color,1):color)));
}
}
public static void DrawUpperCorner(Graphics g, Rectangle rect, Pen pen)
{
g.DrawLine(pen,rect.X, rect.Y,rect.X,rect.Y+rect.Height);
g.DrawLine(pen,rect.X, rect.Y,rect.X+rect.Width,rect.Y);
}
public static void DrawLowerCorner(Graphics g, Rectangle rect, Pen pen)
{
g.DrawLine(pen,rect.X+rect.Width, rect.Y,rect.X+rect.Width,rect.Y+rect.Height);
g.DrawLine(pen,rect.X, rect.Y+rect.Height,rect.X+rect.Width,rect.Y+rect.Height);
}
BTW, the LightenColor and DarkenColor methods return a lighter or darker version of the color passed in. I can send you the code for them if you like, but I don't want to post it here, as it's too long.
"Blessed are the peacemakers, for they shall be called sons of God." - Jesus
"You must be the change you wish to see in the world." - Mahatma Gandhi
|
|
|
|
|
jdunlap:
You can email me the code on: java2@mail.dk
Thanks
|
|
|
|
|
Hi All
I am converting am App from Visual DataFlex to c#...
I need to have global function keys (like pressing F2 to save a record), but these keys must be available to a form at all times.
I also need to use the Enter key as a next Tab in all controls on a form.
I tryed KeyPress, but it does not trap Function Keys...
Thanks
Riaan
|
|
|
|
|
Hi Riaan,
set the form's KeyPreview property to true and take the KeyUp event for all control keys you want to trap.
Dave
|
|
|
|
|
If these commands are menu items, check the Shortcut property on each menu item. This ties into the accelerator key for that command.
α.γεεκ Fortune passes everywhere. Duke Leto Atreides
|
|
|
|
|
How can i make the label Text or the Button Text appear Vertical instead of the default Horizontal?
|
|
|
|
|
There's no property that helps you doing that. You have to draw the text on your own. Look at the MSDN library for the Graphics.DrawString method to see an example.
Greets,
Dave
|
|
|
|
|
I'm new with attributes in c#
List say I have like the example on here
[Test("ID")]
public string ID
{getters and setters}
if I have a method load that loads data I want to map the column ID directly to the property.
I guess what I'm saying is by calling the attibute named "ID" and it would be pointing to the address of the property?
Does anyone have any pointers, I'm lost.
thanks
nick
|
|
|
|
|
by the way thats a SqlDataReader mapping a datarow to an object
|
|
|
|
|
using System;
using System.Reflection;
namespace SolidAvatar
{
public class TestAttribute : Attribute
{
private string m_FieldName;
public TestAttribute(string fieldName)
{
m_FieldName = fieldName;
}
public string FieldName
{
get
{ return m_FieldName; }
}
public static string GetFieldValue(object candidate, string fieldName)
{
System.Type type = candidate.GetType ();
foreach (PropertyInfo propInfo in type.GetProperties())
{
object[] attribs = propInfo.GetCustomAttributes (typeof (TestAttribute), true);
if (attribs.Length > 0)
{
TestAttribute testAttrib = (TestAttribute)attribs[0];
if (testAttrib.FieldName == fieldName)
{
return (string)propInfo.GetValue (candidate, null);
}
}
}
return string.Empty;
}
}
class MyClass
{
[Test ("ID")]
public string ID
{
get
{ return string.Empty; }
set
{}
}
public static void Main()
{
MyClass myClass = new MyClass ();
string idValue = TestAttribute.GetFieldValue (myClass, "ID");
}
}
}
α.γεεκ Fortune passes everywhere. Duke Leto Atreides
|
|
|
|
|
a) any general info / links on performance comparison greatly appreciated
b) comments on the following?
I've been comparing GDI vs. GDI+ for one case: drawing a N point PolyLine.
For a fairly large number of points, GDI+ takes about 4x the time of GDI. (for a few points it's about 10x)
Transforms don't seem to affect the time, a float point array actually seems faster, The graphics.PageUnit is set to pixels, Pen is width -1 (aka one pixel)
Well, it could be worse, but a factor of 4 still seems though for me. Any idea on how to improve performance?
"Der Geist des Kriegers ist erwacht / Ich hab die Macht" StS
sighist | Agile Programming | doxygen
|
|
|
|
|
Lack of performance is not due to the code being managed since the System.Drawing namespace does direct interoped GDI+ calls, and then GDI+ manage everything.
In addition, I believe GDI+ has a few of complex rendering modes being introduced, such as anti-aliasing. It's possible that even if you don't use anti-aliasing the loops have a few if()then() that, once intensively iterated, just cause what you see.
In fact, desassembling the stuff would give the answer.
I happen to start to work (personal project) on that topic sometimes near in the future. And indeed, I will have to decide whether GDI+ can be a good basis, or if I'll Bresenham all that stuff (know what I mean!). Will see if I post a few results.
|
|
|
|
|
Stephane Rodriguez. wrote:
know what I mean
absolutely, I did graphics programming back when video memory wasn't linear
Thanks for the info. Would be interested in any findings.
Related question - do you have any ideas/infos about merging .NET and "classic" GDI?
"Der Geist des Kriegers ist erwacht / Ich hab die Macht" StS
sighist | Agile Programming | doxygen
|
|
|
|
|
peterchen wrote:
Related question - do you have any ideas/infos about merging .NET and "classic" GDI?
This guy, which has eaten the pill two months ago, has written a book[^] in interop, and provides the preinteroped GDI32 library on the CD-ROM.
|
|
|
|
|
GDI+ does not currently make use of any hardware acceleration that may be provided by your video card driver. Later versions most likely will - but not the current release.
http://www.bobpowell.net/why_so_slow.htm[^]
--
Russell Morris
"Have you gone mad Frink? Put down that science pole!"
|
|
|
|
|
|