RSS Forums RSS
Please support our C# advertiser: Programming Forums
Views: 344 | Replies: 5 | Thread Tools  Display Modes
Reply
Join Date: Jul 2008
Posts: 4
Reputation: mode17 is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
mode17 mode17 is offline Offline
Newbie Poster

Please help me!!!!

  #1  
Oct 20th, 2008
Hi,

I'm a beginner in c# and I'm now work in a project with image editing.
i already figure how to do this manually but my professor wants it automatically.
and i tried to call the class type after i load the image but it doesn't work.

here is my codes for the removing it manually.
#region Methods
public void Extract(Point position, int fuzziness)
{
if (_image != null)
{
SaveUndo();

Color clrBaseColor = _image.GetPixel(position.X, position.Y);

if (clrBaseColor.A != 0)

{


BitmapData bitmapData = _image.LockBits(new Rectangle(0, 0, _image.Width, _image.Height), ImageLockMode.ReadWrite, PixelFormat.Format32bppArgb);
int stride = bitmapData.Stride;
IntPtr ptrScan0 = bitmapData.Scan0;
unsafe
{
int count = 0;
int limit = (fuzziness + count) * 20;
byte* pixel = (byte*)(void*)ptrScan0;
int nOffset = stride - _image.Width * 4;
byte alpha;
byte red;
byte green;
byte blue;



for (int y = 0; y < _image.Height; ++y)
{
for (int x = 0; x < _image.Width; ++x)
{

blue = pixel[0];
green = pixel[1];
red = pixel[2];
alpha = pixel[3];

//if (limit >= Math.Sqrt (Math .Pow ((red - clrBaseColor.R),2)+ Math .Pow ((green- clrBaseColor.G),2) +Math .Pow ((blue-clrBaseColor.B),2)))
if (Math.Abs(red - clrBaseColor.R) < limit && Math.Abs(green - clrBaseColor.G) < limit && Math.Abs(blue - clrBaseColor.B) < limit )

// {
//if (limit >= Math.Abs(Math.Sqrt(Math.Pow((red - clrBaseColor.R), 2) + Math.Pow((green - clrBaseColor.G), (2 + 1 / 2)) + Math.Pow((blue - clrBaseColor.B), 2))))
{
pixel[0] = 0;
pixel[1] = 0;
pixel[2] = 0;
pixel[3] = 0;
}
pixel += 4;
}
pixel += nOffset;
//}
}
count = count - 1;
}

_image.UnlockBits(bitmapData);
}
}
}


thanks
AddThis Social Bookmark Button
Reply With Quote  
Join Date: Aug 2008
Posts: 1,289
Reputation: LizR will become famous soon enough LizR will become famous soon enough 
Rep Power: 4
Solved Threads: 128
LizR LizR is offline Offline
Nearly a Posting Virtuoso

Re: Please help me!!!!

  #2  
Oct 20th, 2008
OK, so you have working code. What stops it working automatically? Do you get an error? What values are you passing your method when you called it after the image load? What did debugging show you?
Did I just hear "You gotta help us, Doc. We've tried nothin' and we're all out of ideas" ? Is this you? Dont let this be you! I will put in as much effort as you seem to.
Reply With Quote  
Join Date: Jul 2008
Posts: 4
Reputation: mode17 is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
mode17 mode17 is offline Offline
Newbie Poster

Re: Please help me!!!!

  #3  
Oct 20th, 2008
Originally Posted by LizR View Post
OK, so you have working code. What stops it working automatically? Do you get an error? What values are you passing your method when you called it after the image load? What did debugging show you?


yes i have but its not automatic
i still need to load the picture to a form and the codes were executed by pressing a button.

i tried to make a series of codes same as the one's i used for the manual.
i just set a specific x, y to get the color value of the pixel .
but still it does work.

the debuger did not flag any errors so i don't know were were i got wrong
Reply With Quote  
Join Date: Aug 2008
Posts: 1,289
Reputation: LizR will become famous soon enough LizR will become famous soon enough 
Rep Power: 4
Solved Threads: 128
LizR LizR is offline Offline
Nearly a Posting Virtuoso

Re: Please help me!!!!

  #4  
Oct 20th, 2008
Well faking pressing a button is usually easy enough, and sending a point to your method looks reasonable - so, the question is, what code did you have that didnt work?
Did I just hear "You gotta help us, Doc. We've tried nothin' and we're all out of ideas" ? Is this you? Dont let this be you! I will put in as much effort as you seem to.
Reply With Quote  
Join Date: Jul 2008
Posts: 4
Reputation: mode17 is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
mode17 mode17 is offline Offline
Newbie Poster

Re: Please help me!!!!

  #5  
Oct 21st, 2008
sorry for the late reply i was busy in my studies in school had no time to check on this.

well i tried to set again the specific coordinates where i will get the color that i will set as a comparison for determine the color to be deleted.

but when i do this i encountered an error :
StackOverflowException this happens when i directly call the method for removing the green part of the picture.

#region Methods

private void ShowPhotograph()
{
//if (_preview == null)
//{
// _preview = new Bitmap(this.picPhotograph.Width, this.picPhotograph.Height);
// using (Graphics paintGraphics = Graphics.FromImage(_preview))
// {
// paintGraphics.Clear(Color.Transparent);
// paintGraphics.DrawImage(this.Photograph.Image, 0, 0, this.picPhotograph.Width, this.picPhotograph.Height);
// }
//}
//this.picPhotograph.Image = _preview;

this.picPhotograph.Image = this.Photograph.Image;
this.picPhotograph.Cursor = Cursors.Default;

ShowPhotograph(); ------> here were the error occurse.
btnUndo.Enabled = this.Photograph.Undoable;
this.picPhotograph.Refresh();

}

private Rectangle GetOperateRect(Point position, int toolSize)
{
Rectangle rctRusule = new Rectangle(position.X - (int)Math.Floor(toolSize / 2.0), position.Y - (int)Math.Floor(toolSize / 2.0), toolSize, toolSize);

rctRusule.X = (rctRusule.X < 0) ? 0 : rctRusule.X;
rctRusule.Y = (rctRusule.Y < 0) ? 0 : rctRusule.Y;
if (rctRusule.Right >= _preview.Width - 1)
{
rctRusule.Width -= rctRusule.Right - _preview.Width + 1;
}
if (rctRusule.Bottom >= _preview.Height - 1)
{
rctRusule.Height -= rctRusule.Bottom - _preview.Height + 1;
}

return rctRusule;
}
#endregion
}
}


i found some syntax in msdn but i'm not sure on how to use these.
is there any way that i can prevent the overflowing.

thanks
Reply With Quote  
Join Date: Aug 2008
Posts: 1,289
Reputation: LizR will become famous soon enough LizR will become famous soon enough 
Rep Power: 4
Solved Threads: 128
LizR LizR is offline Offline
Nearly a Posting Virtuoso

Re: Please help me!!!!

  #6  
Oct 22nd, 2008
You get an overflow because you repeatedly call yourself and it wont end.
Did I just hear "You gotta help us, Doc. We've tried nothin' and we're all out of ideas" ? Is this you? Dont let this be you! I will put in as much effort as you seem to.
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.



Other Threads in the C# Forum
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

Thread Tools Display Modes
Forums | Blogs | Tutorials | Code Snippets | Whitepapers | RSS Feeds | Advertising
All times are GMT -4. The time now is 9:24 pm.
Newsletter Archive - Sitemap - Privacy Statement - Acceptable Use Policy - Contact Us
Forum system based on vBulletin Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC