colors - Multiple Intermittent Errors with Seemingly Simply Graphics Method C# -



colors - Multiple Intermittent Errors with Seemingly Simply Graphics Method C# -

i have simple method analyzes sample image in picturebox , increases value of reddish channel. similar other methods analyze other color channels. user given alternative of choosing sample image containing desired color changes , applying original image.

everything working fine until added trackbar enable user alter how much red, green, or bluish they'd add together or subtract sample image. now, works fine on first run. getting "cross-thread operation not valid" error, seem have resolved that. after first run, picturebox1 dissapears @ random , replaced dreaded reddish x. other times, picturebox1 has color changes applied @ total power, regardless of trackbar setting. other times, error stating "object in utilize elsewhere." have, best of understanding of concept, tried locking code errors out, has had no effect. have thoroughly researched these problems both here , elsewhere, found no solutions (other have implemented). code follows:

edit: fwiw, got rare "object not set instance of object" error, in regard int y. unable recreate it. also, i'm curious, when i'm running multiple methods such red(), green(), , blue(), there preferred way run them (other running them from, example, picturebox click)?

my primary problems go on intermittent reddish x in picturebox1, , intermittent frequent "object in utilize elsewhere." error. give thanks much.

private object lockobject = new object(); private void red() { // declare initial variables int xred = 64; // work around "cross-thread operation not valid" error. may vs issue, not actual coding error. if (trkcolor.invokerequired) trkcolor.invoke(new methodinvoker(delegate { xred = trkcolor.value; })); else xred = trkcolor.value; // bitmap picturebox bitmap bmp = (bitmap)picturebox1.image; lock (lockobject) { // search through each pixel via x, y coordinates, examine , create changes. dont allow values exceed 255 or fall under 0. (int y = 0; y < bmp.height; y++) (int x = 0; x < bmp.width; x++) { color c = bmp.getpixel(x, y); int myred = c.r, mygreen = c.g, myblue = c.b; myred += xred; if (myred > 255) myred = 255; bmp.setpixel(x, y, color.fromargb(255, myred, mygreen, myblue)); } // assign new bitmap picturebox picturebox1.image = (bitmap)bmp; } }

c# colors picturebox trackbar

Comments

Popular posts from this blog

java - How to set log4j.defaultInitOverride property to false in jboss server 6 -

c - GStreamer 1.0 1.4.5 RTSP Example Server sends 503 Service unavailable -

Using ajax with sonata admin list view pagination -