visual studio 2008 - .NET Graphics Image -
I have many images that I want to put in a window form. The images themselves are 85 x 85. Each image has a white background with a cylinder object (of different sizes) that can be located at any location of the image.
For example:
Image 1: top left corner
image 2 (25, 35): 85W a cylinder image upper left corner x 85h
I am thinking that what is programmatic is possible with prescribed status (25, 35) or (28, 42) .NET Graphics Library.
Actually what I want to do, repeat the cylinder in a certain coordinate, (10, 10) from the top left corner.
Bitmap class that provides a pixel color bitmap, the X and Y coordinates are given. A technique is probably to run rows and columns of data to determine at least X and Y coordinates, where there is a non-white pixel present. This technique is not enough if the images are small and / or the call calling GetPixel is rather slow since it is not a major idea.
Another approach [] received bitmap image data in a byte and then non-some knowledge of the way bytes This approach bytes array to determine the location of the white pixels of a given bitmap walk Required to be laid out (for example 32 bit, 24 bit, 1 bit, etc.).
To get the bytes for a bitmap, you get a bitmap data object to lock an area of the bitmap bitmap on the phone bitmap and to a bitmap. After this you use the BitmapData object's stride and height properties to determine the size of the need to prevent the byte array bitmap.
I tested and tested the following method, which seems to work faster on a pair, made the test images to detect the location of an oval.
Private point detection space (bitmap origin) {bitmap source = zero; (! Original.PixelFormat = PixelFormat.Format32bppArgb) // if the original bitmap 32 bpp, so changes in ARGB format have not already, {source = new Bitmap (original.Width, original.Height, PixelFormat.Format32bppArgb ); Source.SetResolution (Original HorizontalResolution, Original. VerticalResolution); Use (graphics g = graphics. Framesize (source)) {g.DrawImageUnscaled (original, 0, 0); }} And {source = original; Memory BitmapData sourceData =} // Lock source bitmap source.LockBits (new Rectangle (0, 0, source.Width, source.Height), ImageLockMode.ReadOnly, PixelFormat.Format32bppArgb); // Copy image data binary array int imageSize = sourceData.Stride * sourceData.Height; Byte [] SourceBuffer = new byte [image size]; Marshall.Copy (source.d. scan 0, sourcebuffer, 0, images); // unlock source bitmap source. Unlockbits (source data); Int sourceIndex = 0; Int pixeltal = 0; Int height = source.Height; Int width = source.Width; Int Threshold = 255 * 3; Int minX = width; Int miny = height; // for the Entry Line (int y = 0; y and lt; height; y ++) {sourceIndex = y * sourceData.Stride; // for Iterate pixels (int x = 0; x and lieutenant; width; x ++) {// compute pixel brightness (i.e. total of red, green and blue values) pixelotl = sourcebuffer [sourceindex + 1] + sahab buffer [ Sourceindex + 2] + sourbuffer [sourceindexx3]; If (pixeltol & tht; threshold) {minX = Math.Min (minX, x); Minwai = Mathammin (Minwai, Y); } SourceIndex + = 4; }} Return to new point (Minx, Minwye); }
Comments
Post a Comment