473,387 Members | 1,493 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Image Transparency in overlapping PictureBox objects.

I am making an application that streams video from a web camera onto the
client area of a PictureBox on a Windows CLR Form in MS Visual Studio 2005
(using C++).
The streaming video works fine, and now I am trying to create an image
overlay.
I am assuming that the best way for me to do this is to create a second
PictureBox that lays over the streaming video. I would then need to draw
directly into the bitmap shown in the overlaying PictureBox and have most of
the pixels in that image be transparent (i.e. showing the streaming video
from the underlying picturebox). I have attempted to create a class called
myPictBox that inherits from PictureBox and overrides both the OnPaint and
OnPaintBackground methods, but I really don't know what I am doing. I think
what I want to do is essentially equivalent to the problem of creating a
nonrectangular custom control, though I will not need to respond to mouse
click events as a form control would.

Can anyone offer me any suggestions about this problem?
Am I on the right track, at least?

A stripped down version of how I think this should be solved is shown below
(as is suggested by an article in the MSDN forums). This code results in a
black rectangle overlaying my video stream.

------ File: MyPictBox.h ----------------------
pragma once
#pragma managed

using namespace System;
using namespace System::ComponentModel;
using namespace System::Collections;
using namespace System::Windows::Forms;
using namespace System::Data;
using namespace System::Drawing;

namespace v1 {
public ref class MyPictBox: public PictureBox {
protected: virtual property CreateParams^ CreateParams {
CreateParams^ get () override {
CreateParams^ cp = __super::CreateParams;
cp->ExStyle |= 0x20; // WS_EX_TRANSPARENT
return cp;
}
}
protected: virtual void OnPaintBackground(PaintEventArgs^ pevent)
override {
// Don't paint the background.
}
protected: virtual void OnPaint(PaintEventArgs^ pe) override {
// Paint background image
if (this->BackgroundImage != nullptr) {
Bitmap^ bmp = gcnew Bitmap(this->BackgroundImage);
bmp->MakeTransparent(Color::White);
pe->Graphics->DrawImage(bmp, 0, 0);
}
// Draw opaque portion of control
Pen^ myPen = gcnew Pen(Color::Red,3.0f);
Point point1 = Point(0,50);
Point point2 = Point(50,50);
pe->Graphics->DrawLine(myPen, point1, point2);
delete myPen;
}
}; // class MyPictBox
} // namespace v1
-----------------------------------------------

Jul 28 '08 #1
0 3136

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

Similar topics

0
by: Simon Harvey | last post by:
Hi everyone, Any help with the following would be very greatfully received. I've been having a lot of problems trying to get the standard winforms toolbar to display my images correctly. The...
10
by: Woody Splawn | last post by:
I have a button that I would like to put on a form, actually a panel on a form. The problem is that it's transparency color is magenta and I can not find a way to make the button look right. The...
18
by: Andrew Christiansen | last post by:
Hey all. The images I create in photoshop with semi-transparent pixels (for instance in Photoshop text with a dropshadow with a transparent canvas) I've been saving in PNG format and then using...
1
by: M West | last post by:
continuation of my previous post, thanks to all those that contributed with answers I am creating a control that will take an image and make parts of it transparent, this is done by creating and...
6
by: Rlrcstr | last post by:
I've seen posts all over the place that talk all around this, but I haven't seen anything that resolves the issue. Is it possible to make a picturebox have a transparent background? I've tried...
4
by: ShieldsJared | last post by:
Im looking for help making a good GUI out of pure images. I would like to embed the common controls and such, but I want to make a nice looking GUI, similar to that of, say Windows Media Player. ...
1
by: Marge | last post by:
I imported a project from VB6 ok except for the fact that a couple of gif files which have transparent backgounds nolonger display correctly. On VB6 the images were loaded into their own image...
8
by: Linsolv | last post by:
I have seen many similar questions to mine, and I think I might have found one that was almost the same, but none of the solutions worked that I found. I have a C# Windows form application, with...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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
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
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...

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.