|
Hellow
would you please help me to erase a line in C#.Here I used Drawline(x1,y1,x2,y2) method to draw a line in a panel.I need to create a tool just like in MS paint to erase it.Is there any way to do like that.I tried to erase with by drawing a rectangle with back ground color same to the panel...but its not working fine.
Here is my e-mail ID --subinraju007@gmail.com
|
|
|
|
|
There are many ways to accomplish this, but it seems to me that the easiest way is for you to redraw your image without the line being drawn. A common approach is to implement your drawing as a set of objects that are responsible for drawing themselves, then you just call redraw using these objects, so if you don't want the line to be redrawn you just omit the call to this object.
|
|
|
|
|
The code of WMSplitter studied:
the Input pin read data by StreamOnAsyncReader::Read,which is derived from IStream,
then sample is sent to the Output pines by WMFDemuxFilter::OnStreamSample,which is derived from IWMReaderCallbackAdvanced and IWMReaderCallback.
I don't know what things being done during the data from IStream::Read to IWMReaderCallbackAdvanced::OnStreamSample.
Can I debug it step by step?
Hi,Markliu-codeproject
|
|
|
|
|
Hello all,
I seem to have a problem creating bitmaps with alpha with the following code:
BITMAPINFO tBMI;
ZeroMemory (&tBMI, sizeof tBMI);
tBMI.bmiHeader.biSize = sizeof tBMI.bmiHeader;
tBMI.bmiHeader.biWidth = nSizeX;
tBMI.bmiHeader.biHeight = -nSizeY;
tBMI.bmiHeader.biPlanes = 1;
tBMI.bmiHeader.biBitCount = 32;
tBMI.bmiHeader.biCompression = BI_RGB;
HBITMAP hBmp = CreateDIBitmap(hdc, &tBMI.bmiHeader, CBM_INIT, pData, &tBMI, DIB_RGB_COLORS);
All works fine under normal circumstances, but if it happens that the data are completely transparent (all pixels have alpha set to 0), the behavior suddenly changes and instead of a completely transparent bitmap, the function chooses to ignore the alpha channel and creates a bitmap filled with black color (presumably because the RGB channels were set to 0 in the original data).
Is this some Microsoft hack to maintain compatibility or what? Is there a way to prevent it? Thanks for any hints.
|
|
|
|
|
I know people argue with me here about this, but there really is very little
support for ARGB in the old GDI bitmaps. Some functions may honor the alpha
channel but many ignore it.
The exception is DIBSections...
Try CreateDIBSection instead - I think you'll find much more consistent
results with your 32bpp ARGB bitmaps
Mark
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
Thanks for the answer. I have tried it, but unfortunately, the same "heuristics" applies to CreateDIBSection as well.
I ended up using CreateIconFromResourceEx & DrawIconEx combination. Sounds a bit strange for such a "simple" task as displaying a RGBA image data...
|
|
|
|
|
Vlasta_ wrote: but unfortunately, the same "heuristics" applies to CreateDIBSection as well.
Hmm, I guess that depends on how you display the bitmap. There's not many choices for
that in GDI with ARGB data either.
Vlasta_ wrote: I ended up using CreateIconFromResourceEx & DrawIconEx combination.
Ok, whatever works I personally prefer to use GDI+ for ARGB over something like that.
Cheers,
Mark
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
Agreed, I'm using GDI+ for 32bpp bitmaps in a project now and it's worked just fine.
|
|
|
|
|
Hmmm... I'd like to have the applications compatible with many Windows versions (including Windows 98 and NT4). It is OK, if things look ugly on the older versions, but the application should run.
So, I was drawing using an imagelist with this single bitmap. Maybe the optimization was inside the image list.
|
|
|
|
|
gdiplus could do it, but...it would increase the size of the installer too much for just this simple task. and who knows, maybe it will have the same problem (it is built upon the classic gdi, isn't it?)
besides I like agg better for the vector stuff
...but thanks for the recommendation, it is a good advice, my needs are just a bit special.
|
|
|
|
|
Vlasta_ wrote: it is built upon the classic gdi, isn't it?
No. It is an extension. It does a lot of stuff GDI does not.
Mark
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
As long as you found a solution, there's nothing wrong with that!
As for the imagelist, maybe a ILC_COLOR32 imagelist would work, since that uses a
dibsection internally, but I don't see any support to render an image from the
imagelist using the alpha channel values.
Mark
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
yes, I was using ILC_COLOR32 and it worked correctly in all cases except when every pixels' alpha was 0. So the weird behavior only appeared in this single case, it was enough to change the alpha of the first pixel to 1 and it suddenly started to work as expected. That's why I was calling it "optimization" .
I believe it is worth mentioning somewhere in the documentation... something like: BTW, dear Windows user if you create completely transparent 32-bits bitmap, we will ignore the alpha channel.
|
|
|
|
|
Vlasta_ wrote: That's why I was calling it "optimization"
Not a very optimal optimization.
What function were you using to draw the bitmap? I'd like to play with that a bit.
Mark
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
With ImageList_Draw.
Hm, "optimization" is not a good word. Older Windows did not support alpha at all and when the support was introduced, the functions were probably extended to handle it. But, I assume, due to compatibility issues someone decided to incorporate this "optimization" and when 32bit bitmap is used and it is completely transparent, it kicks in.
|
|
|
|
|
Hello,
i am writing a 3d program using DirectX. Now i want to play a piece of sound with DirectSound, but the initilization was not accomplished.
the code i have written below,
....
CoInitialize(NULL);
if (FAILED( hResult = CoCreateInstance(
CLSID_DirectMusicLoader ,
NULL,
CLSCTX_INPROC,
IID_IDirectMusicLoader8,
(void**) &pLoader)))
{
return SOUNDERROR_MUSICLOADER;
}
if (FAILED( hResult = CoCreateInstance(
CLSID_DirectMusicPerformance,
NULL,
CLSCTX_INPROC,
IID_IDirectMusicLoader8,
(void**) &pPerformance)))
{
return SOUNDERROR_MUSICPERFORMANCE;
}
....
the initial of DirectMusicLoader succeed,
but wenn DirectMusicPerformance is initilized, it returned failure.
Does anyone knows how can i solve the problem?
thx anyway.
mwolf122
|
|
|
|
|
Hey guys
im having a problem getting DoubleBuffer to work.
on my form i have a panel on which i dynamically draw a time line with intervals, arrows, arrowheads ect. The panel is docked to the form, when u resize the form the panel resizes with it and then redraws the time line.
now all that works perfect but the image flickers as i resize the form, i searched through some articles to see how to enable double buffering and did just that... but the flicker is still there
my forms constructor is as follows
public Form1()
{
InitializeComponent();
canvas = new Rectangle(0, 0, panel1.Width, panel1.Height);
calcVariables();
SetStyle(ControlStyles.AllPaintingInWmPaint |
ControlStyles.UserPaint |
ControlStyles.DoubleBuffer |
ControlStyles.ResizeRedraw,
true);
}
what am i doing wrong?
i can e-mail u the demo project if it wil help
thanx
Harvey Saayman - South Africa
Junior Developer
.Net, C#, SQL
think BIG and kick ASS
you.suck = (you.passion != Programming)
|
|
|
|
|
Hi Harvey,
IIRC the SetStyles way of getting DoubleBuffered works as is provided you:
- either do it before the Control becomes visible (or has its handle created?);
- or apply Control.UpdateStyle() after the SetStyles stuff.
Luc Pattyn [Forum Guidelines] [My Articles]
This month's tips:
- before you ask a question here, search CodeProject, then Google;
- the quality and detail of your question reflects on the effectiveness of the help you are likely to get;
- use PRE tags to preserve formatting when showing multi-line code snippets.
|
|
|
|
|
stil nothing...
i now have this as my constructor..
public Form1()
{
SetStyle(ControlStyles.AllPaintingInWmPaint |
ControlStyles.UserPaint |
ControlStyles.DoubleBuffer |
ControlStyles.ResizeRedraw,
true);
InitializeComponent();
canvas = new Rectangle(0, 0, panel1.Width, panel1.Height);
calcVariables();
UpdateStyles();
}
any ideas?
Harvey Saayman - South Africa
Junior Developer
.Net, C#, SQL
think BIG and kick ASS
you.suck = (you.passion != Programming)
|
|
|
|
|
Hi,
It works fine for me; I use it all the time, in the constructor, for Panel derivatives.
The "Board" Panel in my Sokoban article is an example.
I don't know how well it works for Forms; if they contain several Controls,
I would not be surprised the Form has a lot of repaints and continues to show
some flicker.
Luc Pattyn [Forum Guidelines] [My Articles]
This month's tips:
- before you ask a question here, search CodeProject, then Google;
- the quality and detail of your question reflects on the effectiveness of the help you are likely to get;
- use PRE tags to preserve formatting when showing multi-line code snippets.
|
|
|
|
|
hey,
according to what i read doubleBuffer does is it draws to a temp bitmap and then displays the bitmap instead of drawing each line on the form / panel
now while this flicker is going on i can defiantly see specific parts disappear and reappear for example arrow heads i draw in the timeline
so i must be doing something wrong setting the property...
is there any chance i could e-mail the demoProject to you to have a look?
thanx
Harvey Saayman - South Africa
Junior Developer
.Net, C#, SQL
think BIG and kick ASS
you.suck = (you.passion != Programming)
|
|
|
|
|
Hello Harvey,
Have you tried enabling the DoubleBuffering on the panel (where you do your drawing)?
this.SetStyle(
ControlStyles.UserPaint |
ControlStyles.AllPaintingInWmPaint |
ControlStyles.DoubleBuffer
, true)
All the best,
Martin
|
|
|
|
|
Hey
is it possible to draw inside of a rectangle? The idea is to draw a pretty complicated time line(using mostly graphics.DrawString()) for our in house app were rewriting, but i want to reserve the right to move it later (in the code)
is there some way to do this?
thanx
Harvey Saayman - South Africa
Junior Developer
.Net, C#, SQL
think BIG and kick ASS
you.suck = (you.passion != Programming)
|
|
|
|
|
Hi,
a Graphics object performs clipping, normally to the borders of the applicable Control.
e.g. if you have a Panel, its OnPaint will provide a Graphics object with the clip region
set to correspond to the Panel's size.
You can reduce the drawable area by:
1. setting a smaller clip region
2. choose a smaller Control
I typically prefer 2, hence I add a Panel that gets the size I want my OnPaint to handle.
you were not very specific, the above assumes a .NET environment, and a rectangle with
horizontal and vertical edges (not a rotated one).
Luc Pattyn [Forum Guidelines] [My Articles]
This month's tips:
- before you ask a question here, search CodeProject, then Google;
- the quality and detail of your question reflects on the effectiveness of the help you are likely to get;
- use PRE tags to preserve formatting when showing multi-line code snippets.
modified on Friday, March 7, 2008 5:58 AM
|
|
|
|
|
hey there
Yup, c# .net & visual studio 2008...
it makes sense to use a panel, ill try it
the rectangle isn't rotated, what i need to do is draw a time line, and then have lines across it to represent intervals on that time line. Its a tiny bit more complicated than that but in essence thats what i need.
the reason i want to do it in a separate "box" is so that i can dynamically draw this time line instead of just figuring out the coordinates because at a later stage i might want to move or resize it (its going into a control I'm developing)
thanx so mush for the idea, ill let u know how it went!
Harvey Saayman - South Africa
Junior Developer
.Net, C#, SQL
think BIG and kick ASS
you.suck = (you.passion != Programming)
|
|
|
|
|