|
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)
|
|
|
|
|
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.
|
|
|
|
|