Featured post

c# - Usage of Server Side Controls in MVC Frame work -

i using asp.net 4.0 , mvc 2.0 web application. project requiremrnt have use server side control in application not possibl in noraml case. ideally want use adrotator control , datalist control. i saw few samples , references in codepleax mvc controllib howwver found less useful. can tell how utilize theese controls in asp.net application along mvc. note: please provide functionalities related adrotator , datalist controls not equivalent functionalities thanks in advace. mvc pages not use normal .net solution makes use of normal .net components impossible. a normal .net page use event driven solution call different methods service side mvc use actions , view completly different way handle things. also, mvc not use viewstate normal .net controlls require. found article discussing mixing of normal .net , mvc.

WPF: Color under the pointer -


i have control gradiant background. on mousedown or mouseup event want capture color pixel immeidately under mouse pointer. how that?

i created behavior can attached image object grab color, 100% wpf. here behavior; tweaked work "visual", not image.

[note: hardcoded 96dpi creation of rendertargetbitmap... milage may vary]

using system.componentmodel; using system.windows; using system.windows.controls; using system.windows.input; using system.windows.interactivity; using system.windows.media; using system.windows.media.imaging;  namespace company.solution.project.utilities.behaviors {     [description("used sample color under mouse image when mouse pressed. ")]     public class imagebehaviormousedownpointsampletocolor : behavior<image>     {         public static readonly dependencyproperty selectedcolorproperty =             dependencyproperty.register("selectedcolor", typeof(color),                                         typeof(imagebehaviormousedownpointsampletocolor),                                         new uipropertymetadata(colors.white));           public color selectedcolor         {             { return (color)getvalue(selectedcolorproperty); }             set { setvalue(selectedcolorproperty, value); }         }           protected override void onattached()         {             base.onattached();              associatedobject.mousemove += associatedobject_mousemove;             associatedobject.mousedown += associatedobject_mousedown;         }          protected override void ondetaching()         {             base.ondetaching();              associatedobject.mousemove -= associatedobject_mousemove;             associatedobject.mousedown -= associatedobject_mousedown;         }          private void associatedobject_mousedown(object sender, mousebuttoneventargs e)         {             samplepixelforcolor();         }          private void associatedobject_mousemove(object sender, mouseeventargs e)         {             if (e.leftbutton == mousebuttonstate.pressed)             {                 samplepixelforcolor();             }         }          private void samplepixelforcolor()         {             // retrieve coordinate of mouse position in relation supplied image.             point point = mouse.getposition(associatedobject);              // use rendertargetbitmap visual, in case image has been transformed.             var rendertargetbitmap = new rendertargetbitmap((int)associatedobject.actualwidth,                                                             (int)associatedobject.actualheight,                                                             96, 96, pixelformats.default);             rendertargetbitmap.render(associatedobject);              // make sure point within dimensions of image.             if ((point.x <= rendertargetbitmap.pixelwidth) && (point.y <= rendertargetbitmap.pixelheight))             {                 // create cropped image @ supplied point coordinates.                 var croppedbitmap = new croppedbitmap(rendertargetbitmap,                                                       new int32rect((int)point.x, (int)point.y, 1, 1));                  // copy sampled pixel byte array.                 var pixels = new byte[4];                 croppedbitmap.copypixels(pixels, 4, 0);                  // assign sampled color solidcolorbrush , return conversion.                 selectedcolor = color.fromargb(255, pixels[2], pixels[1], pixels[0]);             }          }               }            } 

Comments

Popular posts from this blog

c# - Usage of Server Side Controls in MVC Frame work -

cocoa - Nesting arrays into NSDictionary object (Objective-C) -

ios - Very simple iPhone App crashes on UILabel settext -