473,624 Members | 2,254 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Known problem with LinearGradientB rush?

_DD

It seems that there is some odd interaction with LinearGradientB rush
that depends on positioning. A simple test:

---------

Rectangle Square = new Rectangle(..... );

in Paint:

LinearGradientB rush ShadeBrush = new LinearGradientB rush(
Square, Color.White, Color.Black, 90.0F, true);

g.FillRectangle (ShadeBrush, Square);

---------

This should draw a rectangle with White at the top, blending into
Black at the bottom.

This sometimes works as expected, but sometimes draws a one-
pixel BLACK line across the top edge.

Since the same rect is used for the gradient and for the Fill, you'd
think that nothing could go wrong here. Any ideas?

PS: To top it off, It seems position-sensitive. Changing the Y
position of the Square can cause this wto work correctly.
Also changing the vertical size of the Square object can make thiis
display correctly.
Jan 11 '07 #1
8 6500
It seems that there is some odd interaction with LinearGradientB rush
that depends on positioning.
Try turning on the antialiasing. Are you using a rectangle represented
in float? How about a transform on the Graphics object in float? Those
could easily have a rounding/truncation issue, especially without
antialiasing enabled.

Jan 11 '07 #2
This is a known problem. A workaround is to make the brush area slightly
larger than the area to be filled. (1 pixel bigger)
--
Bob Powell [MVP]
Visual C#, System.Drawing

Ramuseco Limited .NET consulting
http://www.ramuseco.com

Find great Windows Forms articles in Windows Forms Tips and Tricks
http://www.bobpowell.net/tipstricks.htm

Answer those GDI+ questions with the GDI+ FAQ
http://www.bobpowell.net/faqmain.htm

All new articles provide code in C# and VB.NET.
Subscribe to the RSS feeds provided and never miss a new article.

_DD wrote:
It seems that there is some odd interaction with LinearGradientB rush
that depends on positioning. A simple test:

---------

Rectangle Square = new Rectangle(..... );

in Paint:

LinearGradientB rush ShadeBrush = new LinearGradientB rush(
Square, Color.White, Color.Black, 90.0F, true);

g.FillRectangle (ShadeBrush, Square);

---------

This should draw a rectangle with White at the top, blending into
Black at the bottom.

This sometimes works as expected, but sometimes draws a one-
pixel BLACK line across the top edge.

Since the same rect is used for the gradient and for the Fill, you'd
think that nothing could go wrong here. Any ideas?

PS: To top it off, It seems position-sensitive. Changing the Y
position of the Square can cause this wto work correctly.
Also changing the vertical size of the Square object can make thiis
display correctly.
Jan 11 '07 #3
_DD
On 11 Jan 2007 08:12:39 -0800, "not_a_comm ie" <no********@gma il.com>
wrote:
>It seems that there is some odd interaction with LinearGradientB rush
that depends on positioning.

Try turning on the antialiasing. Are you using a rectangle represented
in float? How about a transform on the Graphics object in float? Those
could easily have a rounding/truncation issue, especially without
antialiasing enabled.
I've tried float and int versions of the same. Same result. You'd
think that the int version should work.
Jan 11 '07 #4
_DD
>_DD wrote:
>It seems that there is some odd interaction with LinearGradientB rush
that depends on positioning. A simple test:

Rectangle Square = new Rectangle(..... );

in Paint:
LinearGradientB rush ShadeBrush = new LinearGradientB rush(
Square, Color.White, Color.Black, 90.0F, true);
g.FillRectangle (ShadeBrush, Square);

This sometimes works as expected, but sometimes draws a one-
pixel BLACK line across the top edge.
On Thu, 11 Jan 2007 20:40:24 +0100, "Bob Powell [MVP]"
>This is a known problem
It's a Microsoft bug? Well, at least I only wasted a day and a half on
it (damn, damn, damn). Has anyone filed the bug with Microsoft? (They
don't seem to take those very seriously)

Having assumed that the MS library would have been debugged by now, I
ended up writing lots of test code, converting back and forth from
float to int, etc. Pretty tough debugging, given that the app uses
animation, and it was turning up seemingly at random.

From one test, I found that moving a drawn object from Y=249 to Y=250
introduced the black line. That magic number also changed when the
object's size was changed. Since the graphics in this case require
smooth animation of object position and size, the lines were popping
in an out all over the screen as the objects crossed these magical
borders (what determines that?). It looked horrible, of course.

I didn't turn up any mention of this artifact in google searches. (I
even checked your FAQ, Bob. You may want to add this)
>. A workaround is to make the brush area slightly
larger than the area to be filled. (1 pixel bigger)
I had tried inflating the brush, and it seemed to eliminate the random
line. But it introduced its own problems:

Some of the shaded areas get as narrow as 3 pixels (perspective-shrink
during animation). That means that a 1-pixel miss results in a very
visible 33% change in the outer color. This is not as ugly as the
black lines, but still a noticeable glitch.

And with the inflated brush, there's now no way to get a pure white or
pure black row of pixels on the outer edge of a 3 pixel wide object,
as the crossfade is already at 20% (1 pixel out of 5) when the brush
hits the object edge. But then the bug will pop in and randomly draw a
pure white or black edge.

--

Bob, have you worked with this enough to know:

Does this occur with other, nonlinear, gradient types? That could be
a workaround.

Does antialiasing fix this?

Is this a deeper problem than just two MS guys who didn't round in the
same direction? Early on, I tried writing my own gradient using a
series of Pens, but that seemed to do the same thing. That would
indicate a bug inherent to the internal coordinate mechanism.
Jan 12 '07 #5
_DD
On 11 Jan 2007 08:12:39 -0800, "not_a_comm ie" <no********@gma il.com>
wrote:
>It seems that there is some odd interaction with LinearGradientB rush
that depends on positioning.

Try turning on the antialiasing. Are you using a rectangle represented
in float? How about a transform on the Graphics object in float? Those
could easily have a rounding/truncation issue, especially without
antialiasing enabled.
I simplified the test to just one integer rectangle and a gradient
brush that used that rectangle. The same integer rectangle is handed
to the gradient brush and to the FillRect. Pretty much what I quoted
in the original post. That's about as simple as you can get. No
transforms. No floats in the test.

I hooked up NumericUpDowns to change the position of the rectangle.
As the rectangle's position changes by one pixel, the black lines (or
bright white lines, depending) pop in an out of existence.

It's like quantum physics or something! Heisenberg's LinearGradient
theory. <g>

It does look like an odd bug in GDI+ internals. I'm surprised that
this is not documented somewhere. I'll check into antialiasing, but it
doesn't seem like it will help, given the simplicity of the test case.

Does anyone know if this happened in earlier GDI (non +)?
Jan 12 '07 #6
Hi,

_DD wrote:
>
It's a Microsoft bug? Well, at least I only wasted a day and a half on
it (damn, damn, damn). Has anyone filed the bug with Microsoft? (They
don't seem to take those very seriously)
In the contrary, there is an excellent response from the Microsoft team
to these inputs from users. Please remember that WPF is a brand new
technology, released in November 2006, and that you must count with
childhood problems.

For bug reports, please refer to the MSDN WPF forum here:
http://forums.microsoft.com/MSDN/Sho...eID=1&PageID=0

Also of value, the WPF community site:
http://wpf.netfx3.com/

You may also want to contact people at Microsoft through their blog, for
example Karsten
http://blogs.msdn.com/karstenj/default.aspx

Greetings,
Laurent
--
Laurent Bugnion [MVP ASP.NET]
Software engineering: http://www.galasoft-LB.ch
PhotoAlbum: http://www.galasoft-LB.ch/pictures
Support children in Calcutta: http://www.calcutta-espoir.ch
Jan 12 '07 #7
_DD
On Fri, 12 Jan 2007 10:31:01 +0100, "Laurent Bugnion [MVP]"
<ga*********@bl uewin.chwrote:
>Hi,

_DD wrote:
>>
It's a Microsoft bug? Well, at least I only wasted a day and a half on
it (damn, damn, damn). Has anyone filed the bug with Microsoft? (They
don't seem to take those very seriously)

In the contrary, there is an excellent response from the Microsoft team
to these inputs from users. Please remember that WPF is a brand new
technology, released in November 2006, and that you must count with
childhood problems.
Hi Laurent,

Thanks for your reply. I am glad to hear that the WPF team is on top
of things. However I have filed about 10 bug reports in the past,
mostly about VS2005. I have not yet seen a single one resolved. They
are usually dismissed as 'won't fix' or 'by design' (It's not a bug,
it's a feature?).

Some of the reported bugs were easy to reproduce, and were
subsequently reported by others--with similar dismissals.

So it probably depends on which team is handling fixes. I do hope MS
changes their policy though. After the frustration, I have stopped
filing bug reports. I just try to avoid the trouble spots. I suspect
that other developers have arrived at the same conclusion. I can't see
how that helps Microsoft in the long run.
Jan 12 '07 #8
Hi,

_DD wrote:
Hi Laurent,

Thanks for your reply. I am glad to hear that the WPF team is on top
of things. However I have filed about 10 bug reports in the past,
mostly about VS2005. I have not yet seen a single one resolved. They
are usually dismissed as 'won't fix' or 'by design' (It's not a bug,
it's a feature?).

Some of the reported bugs were easy to reproduce, and were
subsequently reported by others--with similar dismissals.

So it probably depends on which team is handling fixes. I do hope MS
changes their policy though. After the frustration, I have stopped
filing bug reports. I just try to avoid the trouble spots. I suspect
that other developers have arrived at the same conclusion. I can't see
how that helps Microsoft in the long run.
Totally understand your frustration. I must say, we were lucky to have
rather good results with bug submissions (not WPF, in this case it was
IE). What we did was going through our regional Microsoft representative
(I work in german Switzerland, we went through Germany). We got a bug
fix a few weeks later. That was pretty good. Of course, working for
Siemens is an advantage.

That said, the WPF team is very very enthusiastic about their work
(well, they should ;-) so the response is excellent. I first contacted
them privately, and got answers to all my queries. If you follow the WPF
developers' blogs, and see what they work on, it's a great way to post
questions and follow-up.

Courage!
Laurent
--
Laurent Bugnion [MVP ASP.NET]
Software engineering: http://www.galasoft-LB.ch
PhotoAlbum: http://www.galasoft-LB.ch/pictures
Support children in Calcutta: http://www.calcutta-espoir.ch
Jan 12 '07 #9

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
8924
by: Daniel | last post by:
Hi, I use paint event to draw gradient on a Panel. But how to get the label to be transaparent on a gradient draw Panel? Thank you. Regards, Daniel
4
1477
by: Adam Maltby | last post by:
Hi, I need to do a transparent label but with a difference. I have drawn on my form a custom background using CreateGraphics as I needed an ellipse looking fill in a rectangle - so the actual background colour of the form is still set to "control" colour. If I use the background transparent setting instead of seeing my drawn on background and it's gradient i see the forms background colour. If the label was on a solid coloured bit of...
1
8230
by: Kenneth Siewers Møller | last post by:
Hi there I have a custom label control (GradientLabel) which enherits from Label and basically just paints the background of a label in a gradient. In my code I have the following for the overidden OnResize event: protected override void OnPaint(PaintEventArgs e) { Graphics g = e.Graphics;
1
2459
by: DigitalMythic | last post by:
Just to set the scene, I have a listbox in an application which im working on. The List box will have owner drawn items in it when it has items. To start with the listbox is empty. What Im trying to do is have it so that when the listbox is empty, the background is gradient filled with a message for the user in the middle. See code below: if (lstRecoveryItems.Items.Count == 0) //{
0
3034
by: David Gouge | last post by:
Hi All, appreciate that this is more gdi+ than c# but always seem to get good answers here, so here goes... In a nutshell, all i want to do is add a gradient background to a ListView. I have gotten so far by: Adding the following to the constructor: this.SetStyle(ControlStyles.UserPaint, true);
2
1936
by: Robinson | last post by:
Haven't had much luck googling this one: I want to draw a line with a gradient fill, that is a line connecting two shapes in a graphics program, where each shape is a different colour (say, Red -Blue). Now I suppose I can draw a filled-polygon (rotating it to the correct position to avoid awkward end-point issues), but I'm wondering if there is any easier way ;). Thanks, Robin
5
5139
by: cblackburn | last post by:
Hi all, I am in the situation where I have a GraphicsPath that I want to draw onto a System.Drawing.Graphics. I want the line to be coloured in a gradient from one end to the other. I have tried to implement this using a LinearGradientBrush but that does not follow the path of the line, it simply creates a one directional gradient and the line is rendered ontop of that. Does anyone have a suggestion about how to go about implementing this...
2
6581
by: =?Utf-8?B?Y3JlYXZlczA2MjI=?= | last post by:
I have a nested datagrid in a xaml file, the parent datagrid loads the vendor information and the details loads the documents for that vendor in a datagrid. Everything is working fine until I click in the child datagrid and then go to the combobox and choose another vendor. When the new vendor is loaded nothing shows in the datagrid but the itemsource shows the info is there. Know if I click on the child cell and then click back on the...
7
8876
by: prpradip | last post by:
I have used ListView in my Form. I have set OwnerDraw = true. And I have the DrawItem Function as private void listView1_DrawItem(object sender, DrawListViewItemEventArgs e) { if (e.Item.Checked) ControlPaint.DrawCheckBox(e.Graphics, 0, e.Bounds.Top + 1, 15, 15, ButtonState.Flat | ButtonState.Checked); else ...
0
8170
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8675
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8619
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8334
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
1
6108
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5561
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4078
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4173
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
1482
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.