473,809 Members | 2,736 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

c#: how to remove all the green color in a picture

1 New Member
hi,

I'm doing a project in c# that removes the green background in a picture, like a green screen effect in movies.

i already made it partially working.
but the problem is that it only remove 1 shade of green at a time. so if i have a 3 shades of green i need to process it 3 times.
but my prof. want it to be done only once.
when i load the picture it must remove all the green background.

do you have any idea to do this.

here is the latest code that i use:

Expand|Select|Wrap|Line Numbers
  1. #region Methods
  2.         public void Extract(Point position, int fuzziness)
  3.         {
  4.             if (_image != null)
  5.             {
  6.                 SaveUndo();
  7.  
  8.                 Color clrBaseColor = _image.GetPixel(position.X, position.Y);
  9.  
  10.                 if (clrBaseColor.A != 3)
  11.                 {
  12.                     int limit = fuzziness * 19;
  13.                     BitmapData bitmapData = _image.LockBits(new Rectangle(0, 0, _image.Width, _image.Height), ImageLockMode.ReadWrite, PixelFormat.Format64bppArgb);
  14.                     int stride = bitmapData.Stride;
  15.                     IntPtr ptrScan0 = bitmapData.Scan0;
  16.                     unsafe
  17.                     {
  18.                         byte* pixel = (byte*)(void*)ptrScan0;
  19.                         int nOffset = stride - _image.Width *4;
  20.                         byte alpha;
  21.                         byte red;
  22.                         byte green;
  23.                         byte blue;
  24.  
  25.                         for (int y = 0; y < _image.Height; ++y)
  26.                         {
  27.                             for (int x = 0; x < _image.Width; ++x)
  28.                             {
  29.                                 blue    = pixel[0];
  30.                                 green    = pixel[1];
  31.                                 red        = pixel[2];
  32.                                 alpha    = pixel[3];
  33.  
  34.                                 if (limit >= Math.Sqrt(Math.Pow((red - clrBaseColor.R), (2+1/2)) + Math.Pow((green - clrBaseColor.G), (2+1/2)) + Math.Pow((blue - clrBaseColor.B),(2+1/2))))
  35.  
  36.                                 {
  37.                                     pixel[0] = 0;
  38.                                     pixel[1] = 0;
  39.                                     pixel[2] = 0;
  40.                                     pixel[3] = 0;
  41.                                 }
  42.  
  43.                                 pixel += 4;
  44.                             }
  45.                             pixel += nOffset;
  46.                         }
  47.                     }
  48.  
  49.                     _image.UnlockBits(bitmapData);
  50.                 }
  51.             }
  52.         }
thanks
:)
Oct 9 '08 #1
0 1573

Sign in to post your reply or Sign up for a free account.

Similar topics

3
1936
by: Girish | last post by:
I have this XML FILE where I am reading data from and it has this node doctype "< ! D O C T Y P E a d f S Y S T E M " h t t p : / / w h o s c a l l i n g . c o m / d t d / a d f d t d . d t d " > " ONLY When I remove this line I could display the data onto the browser, any ideas WHY? if not I am using following code to remove the above line, it doesn't work Dim FindWhat, ReplaceWith
9
7370
by: Roberto | last post by:
Hi everyone, I'm new here... I have a frameset header/contents. It's necessary to force the header's scrollbar to be visible to preserve the alignment between the two frames (see www.liceomichelangelo.it for details). <frame src="header.html scrolling="Yes"> doesn't work with Mozilla (this is a bug), so I caused the scrollbar to be present via css as follows: body{overflow: -moz-scrollbars-vertical;}
11
3100
by: Tony Johansson | last post by:
Hello! I have some problem with STL function remove I have two classes called Handle which is a template class and Integer which is not a template class. The Integer class is just a wrapper class for a primitive int with some methods. I don't show the Integer class because it will not add any information to my problem. Main is using some STL function Now to my problem.
6
4958
by: Arne Claus | last post by:
Hi If've just read, that remove() on a list does not actually remove the elements, but places them at the end of the list (according to TC++STL by Josuttis). It also says, that remove returns a new, logical end pointer, so that the following myList::iterator end = myListObj.remove(myInt); myListObj.erase(end, myListObj.end()); is possible and removes the "invalid" items at the end of the list.
4
1901
by: Michael A. Covington | last post by:
Greetings, I am working on a program that is in beta testing and goes through a new version every week or so. When there's a new version, go into the setup project change the Product Code but leave the Upgrade Code and version number unchanged. RemovePreviousVersions is set to True.
4
3506
by: Fredrik Rodin | last post by:
Hi! I want to basicaööy run a Session.Abandon() on logout but keep one session. In order to do this I'm iterating through my session collection by runing the follwoing code: Dim iSessionCount As Integer = Session.Count - 1 For i As Integer = 0 To iSessionCount
4
11500
by: Ron | last post by:
I've got a listbox that holds a list of groups. Users can select a group, hit the remove button and the group should be removed from the listbox. The only problem is that no matter which group you select, the first one in the listbox is always removed.(The listitem with an index of 0. Box is set to single selection mode) I've looked at multiple examples and they all do it this way. What's wrong? (variables are also being set to the values...
4
8722
by: Charles Law | last post by:
Is there a way to dynamically remove an event handler from an event without knowing the name of the handler? For example, how can ClassB remove the handler without knowing the name, or how many handlers there are? <code> Public Class ClassA Private m_ClassB As New ClassB
80
7906
by: Andrew R | last post by:
Hi I'm creating a series of forms, each with with around 15-20 text boxes. The text boxes will show data from tables, but are unbound to make them more flexible. I want the form to be used for both adding new data and modifying existing data. I have created a save button on the form. When the user clicks the save button, the code checks to see if there
0
9721
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10376
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
10378
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,...
0
9198
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7653
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
5687
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4332
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3861
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3013
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.