473,657 Members | 2,389 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 OnPaintBackgrou nd(PaintEventAr gs 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 3606
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 OnPaintBackgrou nd 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 OnPaintBackgrou nd 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(imageWid th, imageHeight);
using (Graphics graphics = Graphics.FromIm age(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
11342
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 do this?
6
4933
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 display the repositioned block. See an example at http://www.digitalrat.co.uk/test2/index.html Can anyone explain what IE thinks it's doing? The page is ugly as I've ripped most of the content & styling out to
3
4977
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 the viewer adjusts the font-size on his browser? I have everything sized in em's, so that the actual <div> "box" resizes along with the text, but the background-image will not resize if the text is "zoomed". I can not find anything pertaining
7
2936
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 all have this blue aura around them. I assume that is from the transparency, but I don't understand why almost any other control displays them properly.. There really is no replacement for the toolbar (without paying!), so I hope someone can tell...
3
4873
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 a safety net that establishes some basic values. Coded by Matt Wilcox, found at meyerweb.com/eric/thoughts/2004/09/15/emreallyem-undoing-htmlcss/#comment-989 ..
7
8299
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 background color so the leters are visible too. If i use an alpha filter apllied to the background (td.background{filter:Alpha(Opacity=80);) I'll get the all forum whith an opacity of 80%... If i use an alpha filter apllied to the background color...
4
3930
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, but at the same time it is transparent and the background image of div1 shines through. I hope my explanation is a bit clear. Is this kind of effect at all possible, without using a background image for
4
2819
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 menu-div, so the content div is shown round 25% from the left browser side. In this content div I would like to position a image on the left or right side. I need a background-attachment: static, because the layout position is the div, not the...
0
1605
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 Wikipedia article for PNG images states that PNG includes "ancillary" chunks, one of which is the background value: Ancillary chunks Other image attributes that can be stored in PNG files include gamma values,
0
8842
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
8740
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
8513
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
6176
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
5642
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
4173
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
4330
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
1970
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1733
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.