 |
|
 |
Hi,
I've changed this program a little bit: changed the PenStyle in PS_DASHDOTDOT, and the pen width to 1 pixel.
Now the program writes a red dash-dot-dot line, but the spaces between the dashes and dots are drawn too (with the inverse of the background-color). I expected these spaces to be not changed at all.
I wanted to use a PM_DASHDOTDOT pen in XOR-mode in another application, and here the problem is the same.
Does anyone have a solution? What am I doing wrong?
|
|
|
|
 |
|
 |
/* to be example to the xoring problem
* i ve written a simple namespace to referance to standat GDI.
* But the GDIDraw namespace
* doesnt referance to whole methots such as drawing rectangles or other shapes
* but can easily be enhanged if necessary */
/* original code by sedatkurt
* c++ port by eymre 2/2007 */
namespace GDIDraw {
using namespace System;
using namespace System::Drawing;
using namespace System::Collections;
using namespace System::ComponentModel;
using namespace System::Windows::Forms;
using namespace System::Data;
enum class PenStyles
{
PS_SOLID=0
,PS_DASH=1
,PS_DOT=2
,PS_DASHDOT=3
,PS_DASHDOTDOT=4
,PS_NULL=5
,PS_INSIDEFRAME=6
,PS_USERSTYLE=7
,PS_ALTERNATE=8
,PS_STYLE_MASK=0x0000000F
,PS_ENDCAP_ROUND= 0x00000000
,PS_ENDCAP_SQUARE= 0x00000100
,PS_ENDCAP_FLAT= 0x00000200
,PS_ENDCAP_MASK = 0x00000F00
,PS_JOIN_ROUND= 0x00000000
,PS_JOIN_BEVEL= 0x00001000
,PS_JOIN_MITER= 0x00002000
,PS_JOIN_MASK= 0x0000F000
,PS_COSMETIC= 0x00000000
,PS_GEOMETRIC= 0x00010000
,PS_TYPE_MASK= 0x000F0000
};
enum class drawingMode
{
R2_BLACK= 1 /* 0 */
,R2_NOTMERGEPEN= 2 /* DPon */
,R2_MASKNOTPEN= 3 /* DPna */
,R2_NOTCOPYPEN= 4 /* PN */
,R2_MASKPENNOT= 5 /* PDna */
,R2_NOT= 6 /* Dn */
,R2_XORPEN= 7 /* DPx */
,R2_NOTMASKPEN= 8 /* DPan */
,R2_MASKPEN= 9 /* DPa */
,R2_NOTXORPEN= 10 /* DPxn */
,R2_NOP= 11 /* D */
,R2_MERGENOTPEN= 12 /* DPno */
,R2_COPYPEN= 13 /* P */
,R2_MERGEPENNOT= 14 /* PDno */
,R2_MERGEPEN= 15 /* DPo */
,R2_WHITE= 16 /* 1 */
,R2_LAST= 16
} ;
public ref class GDI
{
private:
IntPtr hdc;
System::Drawing::Graphics ^grp;
public:
void BeginGDI(System::Drawing::Graphics ^g)
{
grp=g;
hdc=grp->GetHdc();
}
void EndGDI()
{
grp->ReleaseHdc(hdc);
}
IntPtr CreatePEN(
PenStyles fnPenStyle, // pen style
int nWidth, // pen width
int crColor // pen color
)
{
return CreatePen(fnPenStyle,nWidth,crColor);
}
IntPtr CreatePEN(
PenStyles fnPenStyle, // pen style
int nWidth, // pen width
Color cl // pen color
)
{
return CreatePen(fnPenStyle,nWidth,RGB(cl.R, cl.G, cl.B));
}
bool DeleteOBJECT(IntPtr hObject)
{
return DeleteObject(hObject);
}
IntPtr SelectObject(
IntPtr hgdiobj // handle to object
)
{
return SelectObject(hdc,hgdiobj);
}
void MoveTo(int X,int Y)
{
MoveToEx(hdc,X,Y,0);
}
void LineTo(int X,int Y)
{
LineTo(hdc,X,Y);
}
int SetROP2(drawingMode fnDrawMode)
{
return SetROP2(hdc,fnDrawMode);
}
private:
[System::Runtime::InteropServices::DllImportAttribute("gdi32.dll")]
static int SetROP2(
IntPtr hdc, // handle of device context
drawingMode fnDrawMode // drawing mode
) ;
[System::Runtime::InteropServices::DllImportAttribute("gdi32.dll")]
static bool MoveToEx(
IntPtr hdc, // handle to device context
int X, // x-coordinate of new current position
int Y, // y-coordinate of new current position
int oldp// pointer to old current position
);
[System::Runtime::InteropServices::DllImportAttribute("gdi32.dll")]
static bool LineTo(
IntPtr hdc, // device context handle
int nXEnd, // x-coordinate of line's ending point
int nYEnd // y-coordinate of line's ending point
);
[System::Runtime::InteropServices::DllImportAttribute("gdi32.dll")]
static IntPtr CreatePen(
PenStyles fnPenStyle, // pen style
int nWidth, // pen width
int crColor // pen color
);
[System::Runtime::InteropServices::DllImportAttribute("gdi32.dll")]
static bool DeleteObject(IntPtr hObject // handle to graphic object
);
[System::Runtime::InteropServices::DllImportAttribute("gdi32.dll")]
static IntPtr SelectObject(
IntPtr hdc, // handle to device context
IntPtr hgdiobj // handle to object
);
public:
static int RGB(int R,int G,int B)
{
return (R|(G<<8)|(B<<16));
}
};
};
SIG: maybe later
|
|
|
|
 |
|
 |
Sedat bey merhaba, benim bir sorum olacaktı; managed c++ calisiyorum, bitirme projem image segmentation ile ilgili, renkli bir image alıyorum picturebox nesnesine, bunu gray level a cevirip islem yapmak istiyorum, çünkü pixellerin gradientlerini hesaplayacagim; A,R,G,B degerlerinden bir sekilde kurtulup tek bir gray deger elde etmek istiyorum her bir pixel icin, bunu en kolay nasil yapabilirim, yardimci olursaniz cok sevinirim..
|
|
|
|
 |
|
|
 |
|
 |
Hi,
I read your article. It really helpful for us.
I need one basic clarification in your article. Actually in this program whenever we draw the line over the rectangle objects, the pen color of the line will be changed to another. How we can keep the original pencolor when we draw over the rectangle ?
Regards,
Prakash.
A Journey of thousand miles must begin with a single step.
|
|
|
|
 |
|
 |
Hi.when İ write this article i d not enough known GDI+,for about 2 years i ve been writin a visio like chartin program(Process Management and Automation Soft.).i m an old VC++ developer so ve used old gdi several times.
but in exploring gdi+ with ildasm i ve seen if u r using gdi+ u dont need to draw self erasing lines,so u dont need xor drawing.GDI+'s invalidate command can erase background very quickly like direcx.so first u need to force gdi+
doublebuffering and allpainting in wmpaint.wmpaint is a message fired when any invalidation.so u must handle it after such setting.In your form constructor,after intializecomponent write,
this.SetStyle(ControlStyles.UserPaint,true);
this.SetStyle(ControlStyles.AllPaintingInWmPaint,true);
this.SetStyle(ControlStyles.DoubleBuffer,true);
after then override WndProc and take control WmPaint messages.
after then u look up MS Visio,u ll never see xor drawing and forget this article pls.
by Sedat Kurt
|
|
|
|
 |
|
 |
I started using GDI+ recently; here is some code sample which describes a problem I am facing
Bitmap * m_pSelectedImage;
// Create a Bitmap object
m_pSelectedImage = Bitmap::FromStream(m_pStream);
All my drawing etc happens here
..
…
At some point, I want to DELETE that file that the stream was created from
_unlink(“Image.jpg”); FAILS with a return -1, indicating a sharing violation
BUT I if I just LOAD the file from disk, then _unlink() it, it works fine, that is if the
// Create a Bitmap object
m_pSelectedImage = Bitmap::FromStream(m_pStream);
is NOT executed, although I am trying to delete and NUL the Bitmap object before calling _unlink();
delete m_pSelectedImage;
m_pSelectedImage = NULL;
Any help will be appreciated
Cheers
Alex
|
|
|
|
 |
|
 |
This example was the perfect solution I've been looking for. I've been pulling my hair out trying to do "rubber band" operations in my POCKET PC 2003 .Net program. I was doing it by drawing the background to a bitmap then "poping" the bipmap to erase the lines/rectangle, but it just doesn't quite do the trick for me. I had to add a few more API calls because PPC .net doesn't support graphics.gethdc() command.
BTW This made me finally take the time to re-learn how to tap into the API (VB numbs the mind "spoonfed" programming). Now my program looks more professional.
Thank you!!!!
|
|
|
|
 |
|
|
 |
|
 |
You could have used the ControlPaint.DrawReversibleLine Method to draw the lines.
|
|
|
|
 |
|
 |
Unfortunately, the ControlPaint class is no better than just using the Graphics class drawing routines. Yes, you can set the "pen styles", but there is still no way of doing the XOR drawing needed to make a rubber band line. sedatkurt has a truly neat workaround compared to others I've seen and tried. It is cumbersome, but it gets the job done. Cool,
|
|
|
|
 |
|
 |
ControlPaint.DrawReversibleLine, ControlPaint.DrawReversibleRectangle, ControlPaint.DrawReversibleFrame do implement XOR drawing you should try it.
|
|
|
|
 |
|
 |
Have tried it. Spent too much time playing with the geometry and that's NOT what I was interested in doing
Carl
|
|
|
|
 |
|
 |
i think there is no need to implement a solution just using .net classes.Plus ,i ve knwn ControlPaint class already,but pls tell me how i can use ControlPaint class in my own control's Graphics interface,ok?as i known unsing ControlPaint class we only can draw lines and etc.. on windows desktop.
|
|
|
|
 |
|
 |
if u wanna write a screensaver it may be solution.
|
|
|
|
 |
|