473,503 Members | 12,103 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Checkered background for images with varying Alpha

Hi all, I'm looking for the right way to create a checkered background
in a PictureBox. I will be applying various images to this PictureBox
and I want to to see the checkered background based on the level of
alpha in the image.

I have an algorithm that will traverse a bitmap's pixel and on a pixel
by pixel basis determine the alpha of the image. But my problem is
where to put this algorithm. If I put it in here:
protected override void OnPaintBackground(PaintEventArgs pevent)

it seems to just constantly be invoked whether or not anything is being
done to the image. It may be that the very assignment I'm doing inside
this method is causing it to be reinvoked - i.e. I assign to this.Image
inside this method. Though if that were the case, I would expect the
call stack to grow as time progressed, but it never does.

Any hints as to how to integrate this code into a class that extends
PictureBox? A URL where someone else has done this would also be
useful.

Thanks,
Novice

Apr 21 '06 #1
3 3603
I have never done anything like this, but my instict would say you
would want to throw this algorithm into a function and then call the
function when ever you change background images.

I would assume that OnPaintBackground is getting called call constantly
to since you picture is constantly being redrawn for some reason.

So my suggestion would be to run you algorithm on form load and during
any other event where the picture is actually changed (such as a button
click or something).

This is just a stab in the dark though.

- Patrick

Apr 21 '06 #2
I've got it working.. kinda...

The other problem is that there are a bunch of controls (an arbitrary
number) that can modify the PictureBox... so I think the right place
for this is the OnPaintBackground or OnPaint. This seems to be
combining things well enough, but now I have two other problems:
1. I get a non-straight line drawn in a seemingly random spot outside
of the PictureBox control... it is so weird... I have no idea how my
OnPaint (within the class that extends PictureBox) would even have
access to that part of the Panel (since it is outside of the
PictureBox).
2. The other problem is that there seems to be some issue with scaling
the image/bitmap I create to the image that belongs to the PictureBox

Anybody know of a publicly accessible C# source code that does this?
link?

Thanks,
Novice

Apr 21 '06 #3
Okay more or less solved the problems - turns out in a PictureBox's
OnPaint event handler you HAVE to use the graphics from the event - not
from an image you create. I.E. this is bad
Bitmap resultBMP = new Bitmap(imageWidth, imageHeight);
using (Graphics graphics = Graphics.FromImage(resultBMP))
{
//code
}

This is good:
Graphics graphics = e.Graphics;
//code

For some screwy reason the "bad" code would make a random curved line
(almost looked like a random scratch) appear outside of the control's
constraints which is just nutty!

..Net voodoo/magic

Novice

Apr 21 '06 #4

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

Similar topics

12
11325
by: Tania | last post by:
I have a scenic picture for the background of a page. I would like to make a table, with an opaque background, over top to hold content, that will still somewhat show my page background. How do I...
6
4921
by: Michael Rozdoba | last post by:
I've had some trouble getting IE to behave in respect of applying absolute positioning to a span on an a:hover. I can get it to work, but I don't understand why certain code causes it to fail to...
3
4965
by: Greg Heilers | last post by:
Hello everyone... If one has a <div> that is completely filled with a background-image; how does one style it so that the image *continues* to fill the <div> top-to-bottom, left-to-right; if...
7
2927
by: Mitchell Vincent | last post by:
I've been trying to get a standard toolbar to play nice with some nice icons that I have. When I put them on a button or anything they look perfect, but through an imagelist and on a toolbar they...
3
4862
by: blaq | last post by:
My latest project is almost done. It looks great in Firefox; I only have two IE bugs left to squash, yay! Please refer to http://www.blaqzone.com/Temp/Popfuel/ . Crib notes: - "reset.css" is...
7
8294
by: Guliver | last post by:
Hello. I'm configuring the apearence of my forum and I have a question for anyone who can help me. I have a backgroud picture and I would like it to be visible but I'm trying to mantain a...
4
3917
by: Chris | last post by:
Hello, I have two div's, div1 is a lot bigger and is the parent of div2, and div1 also has a background image. What I would like to do, is set a background color for the smaller nested div2,...
4
2805
by: Philipp Kraus | last post by:
Hi, I have one problem with my position of my background image. I have created one div-tag that has a background image, which should be fixed during scrolling. On the left side of the div is my...
0
1592
by: Bint | last post by:
Hi, I want to create 24 bit PNG image files (red, green, blue, alpha) with PHP -- that's easy enough. However, I would like to include a background color value as well, as a default. The...
0
7212
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7098
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...
0
7296
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,...
0
7364
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...
0
5604
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
5026
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...
0
4696
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...
0
3186
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...
0
3174
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

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.