|
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)
|
|
|
|
|
hey
im done doing the basic drawing of the time line, works like a charm!
just out of curiosity, my step brother(a .Net dev as well) mentioned something about double buffering to "combat" the flicker effect.
i put the panel i drew the time line on docked on a form, when i resize the form i call Invalidate() and everything works great... Accept for the flickering
how would i go about implementing the doubleBuffer?
thanx
Harvey Saayman - South Africa
Junior Developer
.Net, C#, SQL
think BIG and kick ASS
you.suck = (you.passion != Programming)
|
|
|
|
|
Hi,
flickering is due to the amount of time it takes from erasing the first pixel to repainting
the last one. There is no perfect solution, but there are a lot of things that can help a lot:
1.
make sure not to waste CPU cycles in your paint code.
e.g. try using existing pens, brushes, fonts, whatever rather than creating (and disposing)
new ones all the time.
2.
the Control.DoubleBuffered property (since .NET 2.0) is useful; set it true, and .NET will
do all painting for it in an invisible bitmap then paint that in a flash to the screen.
It is transparant to your code, nothing really needs to be changed.
If only one Panel is flicker-critical, just set the DoubleBuffered property for that Panel;
you can set it for the entire Form, but then a larger area will have to be copied from
bitmap to screen every time.
3.
if that is insufficient, it becomes much more complicated.
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.
|
|
|
|
|
once again thanx!
im gona try that now... cuz i am creating brushes and pens and rectangles in the paint method and disposing them at the end of it
ill see how it works after a instantiate them in the class and decide if doubleBuffering is necessary
Harvey Saayman - South Africa
Junior Developer
.Net, C#, SQL
think BIG and kick ASS
you.suck = (you.passion != Programming)
|
|
|
|
|
Hey guys
Im busy working on a control project, in a nutshell its a clock that i draw using GDI+ (i think)
my problem is this, the DrawWhatEver() doesnt work if i use my own graphics object...
private void UserControl1_Load(object sender, EventArgs e)
{
Graphics graphics = this.CreateGraphics();
drawClock(graphics);
}
but i works when i use the OnPaint's e.graphics object
protected override void OnPaint(PaintEventArgs e)
{
drawClock(e.Graphics);
base.OnPaint(e);
}
What is up with that?
thanx
Harvey Saayman - South Africa
Junior Developer
.Net, C#, SQL
think BIG and kick ASS
you.suck = (you.passion != Programming)
|
|
|
|
|
Well, I'm not really up on all the C# and .NET crap, but in the underlying OS, all painting takes place during the processing of the WM_PAINT message which results in invoking the OnPaint method. In your UserControl1_Load method, just call something like Invalidate() on the window to get a WM_PAINT message sent so it updates its contents. Basically, you update the state of the data and it gets displayed in the OnPaint method. If you want to keep them in snych, you need to invoke painting when you change the data.
Doing my part to piss off the religious right.
|
|
|
|
|
HarveySaayman wrote: What is up with that?
"The Load event occurs after the control is created, but before the control becomes visible for the first time."
Drawing on an invisible control will be, well, invisible
Mark
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
haha, now i get it!
Harvey Saayman - South Africa
Junior Developer
.Net, C#, SQL
think BIG and kick ASS
you.suck = (you.passion != Programming)
|
|
|
|
|
Hi,
here are my guidelines for painting in general:
there are several steps to draw something so it becomes visible on the screen:
1.
decide upon what object you want to draw; it normally is a Control (e.g. a Panel) or a
Form itself. I prefer to add a Panel to a Form, then draw on the Panel.
2.
create some variables (Rectangle, struct, class, whatever) that hold the parameters of
your drawing. For a rectangle that could be top and left coordinate, and width+height,
or just a Rectangle. etc.
3.
create a Paint handler for that Panel, and do all your drawing in there, using the
Graphics class and your variables.
4.
when you want to change things, modify the variables and call Panel.Invalidate() or
one of its overloads (for selective invalidation).
5.
If you want to animate things, perform the move (step 4) inside the Tick handler
of a Windows.Forms.Timer
BTW: if you need to create some objects (Fonts, Pens, Brushes, ...) either keep them
alive in class members (hence create them only once); or create them inside the Paint
handler and don't forget to call Dispose() on them.
Remark: you very rarely need CreateGraphics; OnPaint offers a Graphics object for free.
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 there,
thanx allot!
this will defiantly help me with the drawing of things,
im gona try drawing my time line on a panel now...
thanx again
Harvey Saayman - South Africa
Junior Developer
.Net, C#, SQL
think BIG and kick ASS
you.suck = (you.passion != Programming)
|
|
|
|
|
HarveySaayman wrote: Graphics graphics = this.CreateGraphics();
I don't understand why so many people use this method. It is *wrong*. What led you to use it ? Is there an MS sample out there that uses it ?
As you've discovered, handling hte paint event is the right way to draw your form. CreateGraphics is good to draw something temporary, like a rubberband. What you draw is lost on the first paint event.
Christian Graus - Microsoft MVP - C++
"also I don't think "TranslateOneToTwoBillion OneHundredAndFortySevenMillion FourHundredAndEightyThreeThousand SixHundredAndFortySeven()" is a very good choice for a function name" - SpacixOne ( offering help to someone who really needed it ) ( spaces added for the benefit of people running at < 1280x1024 )
|
|
|
|
|
Christian Graus wrote: What led you to use it
exploration, im new to drawing so im "playing" around with what im able to do and getting suggestions from you guys, so that i can use these newly discovered "puzzle pieces" in a real world application.
the idea is to explore the drawing class and better understand how it works so that i can write a better control for my application.
im not using Graphics graphics = this.CreateGraphics(); anymore, ive seen the errors in my way
thanx
Harvey Saayman - South Africa
Junior Developer
.Net, C#, SQL
think BIG and kick ASS
you.suck = (you.passion != Programming)
|
|
|
|
|
That's cool - I'm not having a shot at you, just generally curious why so many people seem to 'discover' this way of drawing, if there's some book or sample at the bottom of it.
Christian Graus - Microsoft MVP - C++
"also I don't think "TranslateOneToTwoBillion OneHundredAndFortySevenMillion FourHundredAndEightyThreeThousand SixHundredAndFortySeven()" is a very good choice for a function name" - SpacixOne ( offering help to someone who really needed it ) ( spaces added for the benefit of people running at < 1280x1024 )
|
|
|
|
|