Why can't we ask standard questions on stackoverflow anymore?

I posted a basic question on StackOverflow and was inundated with negative downvotes in a matter of seconds.
I apologized at the start if the question was unclear, but all of this is for naught. I had no idea that I needed to be a writer to raise a question. And all I asked for was a basic explanation regarding a fingerprint reader, so it’s no surprise they’re ranked low. github library

1 Like

Probably a question best asked to StackOverflow. My own experiences there haven’t been exactly positive either, but i’m not going to sit here and slag off another site.

1 Like

a man gotta get out that anger inside hes chest otherwise he will explode

its been a very exhausting two months
I have been working so hard on my website from writing content to building other stuff and just when I start to earn some money google launched the core update in may so my ranking dropped. the amount of anger that I had those days was deadly so I picked up myself and said that this is just a bump in the road and it will get back and the only thing I need to do is keep doing what I do best. and the website start to pick up some traffic again. and the same thing happend during another core update at September 12 i lost 60% of my traffic, so I did the same thing kept doing what I know best, and it recover 20%, and now this spam update that took all my traffic like a bullet to the head.

so i got back to my old project that i had hoping to earn some cash out of it and this what brought me to stackoverfllow. so i appologize for talking bad about some website that has no effect on my life. and im sorry for even posting this post

Have you got a link to the question on Stack Overflow? My experience of the site has been generally very good and I’d be interested to see what you got downvoted for. You can also DM me a link if you don’t want to post it publicly.

Nah, don’t be sorry. Life can deal you lemons sometimes and things can just suck.

2 Likes

Stackoverflow is a big community and has sites for nearly any kind of question. The stackoverflow you talk about I guess is the ones for software developing help. On this site you get help if you have a well precised problem on any kind of code. It is not a platform to ask for a best practice or best library etc. you need to do your own homework first and when you get stucked at a very defined point you will get help.

1 Like

as soon i saw the downvote i deleted it

that what dev should do help each other because what you dont know another know it. but what i dont understand is this read this before you ask , with bold line , like if you dont read it they are going to cut my check if i had one, i did not come to read i came cause i have a problem and i want some answers. and why you even downvoting a question this is beyond my comprehension, we all know that devs are not sociable or im not i dont like seeing people what i like is my computer , vs, notepad and xampp , i dont want to read your rules so i can ask a question what in the name of god this nonsens is. if google did not roll out its stupid, demonic updates i will not be coming to your website

You don’t like people but you want them to spent their free time for you without doing a bit of self investigation like reading the forum rules?

So don’t expect answer from me here too

how i can improve this code

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Drawing.Imaging;
using System.IO;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace Morphotop
{
    public unsafe partial class Form1 : Form
    {

        public Form1()
        {
            InitializeComponent();
            //BDS_Callback callback = Callback;

        }
        [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Ansi, Pack = 1)]
        public struct BDS_Image
        {
            public unsafe uint m_magic;
            public unsafe uint m_version;
            public unsafe uint m_width;
            public unsafe uint m_height;
            public unsafe uint m_flags;
            public IntPtr m_image;
            public unsafe uint m_count;
            public unsafe uint m_checksum;
            public unsafe fixed byte m_rfu[25];
        }
        [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
        public unsafe delegate int BDS_Callback(IntPtr i_i_deviceHandle,
                                   BDS_Image* i_p_currentImage, IntPtr i_p_inputData,
                                    IntPtr o_p_outputData, IntPtr i_p_userData);

        public  unsafe int CallbackPointer(IntPtr i_i_deviceHandle, BDS_Image* i_p_currentImage, IntPtr i_p_inputData,
                                    IntPtr o_p_outputData, IntPtr i_p_userData)
        {
            try
            {
                uint size = i_p_currentImage->m_width * i_p_currentImage->m_height;
                byte[] data = new byte[size];
                byte[] height = new byte[i_p_currentImage->m_height];
                byte[] width = new byte[i_p_currentImage->m_width];
                IntPtr pointer = Marshal.AllocHGlobal(data.Length);
                Marshal.Copy(i_p_currentImage->m_image, data, 0, data.Length);
                Marshal.FreeHGlobal(pointer);

                 SetPicture(pictureBox1, ConvertToBitmap(data, width.Length, height.Length));
            }
            catch
            {
            }
            return 0;
        }
        private  void SetPicture(PictureBox img, Bitmap bmp)
        {
            try
            {
                if (img.InvokeRequired)
                {
                    img.Invoke(new MethodInvoker(
                    delegate()
                    {
                        pictureBox1.Image = bmp;
                    }));
                }
                else
                {
                    pictureBox1.Image = bmp;
                }
            }
            catch
            {
            }
        }
        public void Initialize()
        {


            // int res5 = OpenBioDevice(i_p_handle, 0, out device_handle, user_data);
        }
        private void Capture_Click(object sender, EventArgs e)
        {




            int p = BDS_SetParametersForDirectMode(i_p_handle, 1);
            BDS_Image* resdet = BDS_GetDirectImage(i_p_handle, 0, 5000);
            uint size = resdet->m_width * resdet->m_height;
            byte[] data = new byte[size];
            byte[] height = new byte[resdet->m_height];
            byte[] width = new byte[resdet->m_width];
            if (data.Length != null)
            {
                IntPtr pointer = Marshal.AllocHGlobal(data.Length);
                try
                {
                    Marshal.Copy(resdet->m_image, data, 0, data.Length);
                    Marshal.FreeHGlobal(pointer);
                    File.WriteAllBytes("test",data);
                    Bitmap bmp =ConvertToBitmap(data, width.Length, height.Length);
                    bmp.Save(Directory.GetCurrentDirectory()+"\\test.jpg");
                    pictureBox2.Image = bmp;
                }
                catch
                {

                }
            }
           
        }
        private Bitmap ConvertToBitmap(byte[] image_data,int width,int height)
        {
            try
            {
                int Width = width;
                int Height = height;
                var b = new Bitmap(Width, Height, PixelFormat.Format8bppIndexed);

                ColorPalette ncp = b.Palette;
                for (int i = 0; i < 256; i++)
                    ncp.Entries[i] = Color.FromArgb(255, i, i, i);
                b.Palette = ncp;
                var BoundsRect = new Rectangle(0, 0, Width, Height);
                BitmapData bmpData = b.LockBits(BoundsRect,
                                                ImageLockMode.WriteOnly,
                                                b.PixelFormat);

                IntPtr ptr = bmpData.Scan0;

                int bytes = width * b.Height;
                var rgbValues = new byte[bytes];
                Marshal.Copy(image_data, 0, ptr, bytes);
                b.UnlockBits(bmpData);
                return b;
            }
            catch
            {
                return null;
            }
        }



        private void Form1_Load(object sender, EventArgs e)
        {
            Initialize(textBox1);
        }



       private IntPtr i_p_handle;
        public void Initialize(TextBox result)
        {
            i_p_handle = IntPtr.Zero;
            IntPtr o_pp_procaddress = IntPtr.Zero;
            IntPtr o_p_interfaceTable = IntPtr.Zero;
            IntPtr o_i_interfaceTable_count = IntPtr.Zero;
            IntPtr o_i_dllVersion = IntPtr.Zero;
        
            IntPtr o_p_deviceCount = IntPtr.Zero;
            IntPtr device_handle = IntPtr.Zero;
            IntPtr img2 = IntPtr.Zero;
            IntPtr r = IntPtr.Zero;
            int user_data = 300;
            int re = 0;
            result.AppendText("Loading Library......." + Environment.NewLine);
            re = LoadLib(Directory.GetCurrentDirectory() + "\\SDKServices.dll", out i_p_handle);
            if (re == 0)
            {
                result.AppendText("Library Loaded No ERRORS" + Environment.NewLine);
                result.AppendText("Resolving interface" + Environment.NewLine);
                re = resolveInterface(Directory.GetCurrentDirectory() + "\\SDKServices.dll", o_pp_procaddress, out o_p_interfaceTable, out o_i_interfaceTable_count, out o_i_dllVersion);
                if (re == 0)
                {
                    result.AppendText("Interface resolved" + Environment.NewLine);
                    result.AppendText("Enumerating devices" + Environment.NewLine);
                    re = EnumerateUsableBiometricDevices(i_p_handle, out o_p_deviceCount);
                        OpenBioDevice(i_p_handle,0,out r,user_data);
                        SetupLiveMode(0,i_p_handle);
                    if (re == 0)
                    {
                        result.ForeColor = Color.Black;
                        result.AppendText("device enumerated" + Environment.NewLine);
                    }
                    else
                    {
                        result.AppendText("device could not be enumerated" + Environment.NewLine);
                    }
                }
                else
                {
                    result.AppendText("Interface could not be resolved" + Environment.NewLine);
                }
            }
            else
            {
                result.ForeColor = Color.Black;
                result.AppendText("could not load library" + Environment.NewLine);
            }
        }
        public void OpenDevice(TextBox result, IntPtr i_p_handle, IntPtr o_p_deviceHandle, int i_p_userData)
        {
            int resu = OpenBioDevice(i_p_handle, 0, out o_p_deviceHandle, i_p_userData);
            if (resu == 0)
            {
                result.AppendText("Biometric Device Opened" + Environment.NewLine);
            }
            else
            {
                result.AppendText("Could not open Biometric device" + Environment.NewLine);
            }
        }

        public void CloseDevice(TextBox result, IntPtr i_p_handle, int o_p_deviceHandle)
        {
            int resu = CloseBioDevice(i_p_handle, o_p_deviceHandle);
            if (resu == 0)
            {
                result.ForeColor = Color.Black;
                result.AppendText("Biometric Device Closed" + Environment.NewLine);
            }
            else
            {
                result.ForeColor = Color.Red;
                result.AppendText("Could not close Biometric device" + Environment.NewLine);
            }
        }
        public BDS_Callback callback1;
        public void SetupLiveMode(int SamplingMode, IntPtr i_p_handle)
        {
             callback1 = new BDS_Callback(CallbackPointer);
             int res = BDS_DefineLiveProcess(i_p_handle, SamplingMode, callback1);
        }
        [DllImport("SSB.dll", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Unicode)]
        public extern static int LoadLib(String path, out IntPtr i_p_handle);

        [DllImport("SSB.dll", CallingConvention = CallingConvention.Cdecl)]
        public extern static int GProcAddress(IntPtr i_p_handle, string i_pc_method, out IntPtr o_pp_procaddress);

        [DllImport("SSB.dll", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Unicode)]
        public extern static int resolveInterface(String path, IntPtr i_i_dllType, out IntPtr o_p_interfaceTable, out IntPtr o_i_interfaceTable_count, out IntPtr o_i_dllVersion);


        [DllImport("SSB.dll", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Unicode)]
        public extern static int EnumerateUsableBiometricDevices(IntPtr path, out IntPtr o_p_deviceCount);


        [DllImport("SSB.dll", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Unicode)]
        public extern static int OpenBioDevice(IntPtr path, int i_i_deviceIndex, out IntPtr o_p_deviceHandle, int i_p_userData);


        [DllImport("SSB.dll", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Unicode)]
        public extern static int CloseBioDevice(IntPtr path, int i_i_deviceHandle);

        [DllImport("SSB.dll", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Unicode)]
        public extern static int SetDetectionMode(IntPtr path, IntPtr i_i_deviceHandle, int i_i_detectionMode, int i_i_fingerNumber);
        [DllImport("SSB.dll", CallingConvention = CallingConvention.Cdecl)]
        public extern unsafe static BDS_Image* BDS_GetDirectImage(IntPtr path, int i_i_deviceHandle, ulong i_l_timeout);
        [DllImport("SSB.dll", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Unicode)]
        public extern static int BDS_SetParametersForDirectMode(IntPtr hadle, int sample);
        [DllImport("SSB.dll", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Unicode)]
        public extern static int BDS_SetParametersForDirectMode(IntPtr path, IntPtr i_i_deviceHandle, int i_i_samplingMode);
        [DllImport("SSB.dll", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Unicode)]
        public extern static int BDS_DefineLiveProcess(IntPtr l_p_handle, int a, BDS_Callback c);

        [DllImport("SSB.dll", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Unicode)]
        public extern static int BDS_DefineLiveProcess(int l_p_handle, BDS_Callback bds);

        private void Close_Click(object sender, EventArgs e)
        {
            CloseDevice(textBox1, i_p_handle, 0);
        }
        IEnumerable<Rectangle> FindImageTiles(Bitmap compositeImage)
        {
            var result = new List<Rectangle>();

            // Scan for a non-empty region that hasn't already been "captured"
            for (var x = 0; x < compositeImage.Width; x++)
            {
                for (var y = 0; y < compositeImage.Height; y++)
                {
                    // Only process the pixel if we don't have a rectangle that
                    // already contains this and if it's not empty
                    if (!result.Any(r => r.Contains(x, y))
                        && compositeImage.GetPixel(x, y).A != 0)
                    {
                        // Now that we've found a point, create a rectangle
                        // surrounding that point, then expand outward until
                        // we have a bounding rectangle that doesn't intersect
                        // with the tile
                        var rect = new Rectangle(x - 1, y - 1, 2, 2);
                        bool foundBounds = false;
                        while (!foundBounds)
                        {
                            var xRange = Enumerable.Range(rect.Left, rect.Right)
                                .Where(px => px >= 0 && px < compositeImage.Width);
                            var yRange = Enumerable.Range(rect.Top, rect.Bottom)
                                .Where(py => py >= 0 && py < compositeImage.Height);

                            // Adjust the top
                            if (rect.Top >= 0
                                && xRange
                                    .Select(bx => compositeImage.GetPixel(bx, rect.Top))
                                    .Any(p => p.A != 0))
                            {
                                rect.Y--;
                                rect.Height++;
                            }
                            else if (rect.Bottom < compositeImage.Height
                                && xRange
                                    .Select(bx => compositeImage.GetPixel(bx, rect.Bottom))
                                    .Any(p => p.A != 0))
                            {
                                rect.Height++;
                            }
                            else if (rect.Left >= 0
                                && yRange
                                    .Select(by => compositeImage.GetPixel(rect.Left, by))
                                    .Any(p => p.A != 0))
                            {
                                rect.X--;
                                rect.Width++;
                            }
                            else if (rect.Right < compositeImage.Width
                                && yRange
                                    .Select(by => compositeImage.GetPixel(rect.Right, by))
                                    .Any(p => p.A != 0))
                            {
                                rect.Width++;
                            }
                            else
                            {
                                foundBounds = true;
                            }
                        }
                        result.Add(rect);
                    }
                }
            }

            return result;
        }

        private void button1_Click(object sender, EventArgs e)
        {
            IEnumerable<Rectangle> rec = FindImageTiles((Bitmap)pictureBox2.Image);
            Image img = pictureBox2.Image;
            Graphics newGraphics = Graphics.FromImage(img);
            foreach(Rectangle r in rec){
                newGraphics.DrawRectangle(new Pen(Color.Black, 2), r);
            }
        }
    }
}

that is your choice, and i respect it, but people is not you people are my people not yours just to be clear

thoroughly unclear, tbh.

Start by figuring out which part of it you want to improve, rather than throwing the entire Form class into a block quote.
Why do you think it needs improvement?

because its unsafe code a lot of memory allocation

it looks like that these are the c++ library call out

this function seems to be loading the library from a given path

 [DllImport("SSB.dll", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Unicode)]
        public extern static int LoadLib(String path, out IntPtr i_p_handle);

this one is called procaddress which can only means that hes calling a process address
that takes as a perameter a pointer which is the device handle and “i_pc_method” i dont know what it means and it ouput another pointer

[DllImport("SSB.dll", CallingConvention = CallingConvention.Cdecl)]
public extern static int GProcAddress(IntPtr i_p_handle, string i_pc_method, out IntPtr o_pp_procaddress);

this is the same as the above except it take as a perameter string path and a pointer and output another pointer

[DllImport("SSB.dll", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Unicode)]
public extern static int resolveInterface(String path, IntPtr i_i_dllType, out IntPtr o_p_interfaceTable, out IntPtr o_i_interfaceTable_count, out IntPtr o_i_dllVersion);

this function enumerate the deivce

[DllImport("SSB.dll", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Unicode)]
public extern static int EnumerateUsableBiometricDevices(IntPtr path, out IntPtr o_p_deviceCount);

this function open the device meaning the device will turn green

[DllImport("SSB.dll", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Unicode)]
public extern static int OpenBioDevice(IntPtr path, int i_i_deviceIndex, out IntPtr o_p_deviceHandle, int i_p_userData);

[DllImport("SSB.dll", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Unicode)]
public extern static int CloseBioDevice(IntPtr path, int i_i_deviceHandle);

[DllImport("SSB.dll", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Unicode)]
public extern static int SetDetectionMode(IntPtr path, IntPtr i_i_deviceHandle, int i_i_detectionMode, int i_i_fingerNumber);
[DllImport("SSB.dll", CallingConvention = CallingConvention.Cdecl)]
public extern unsafe static BDS_Image* BDS_GetDirectImage(IntPtr path, int i_i_deviceHandle, ulong i_l_timeout);

this function let you choose between the live more and capture mode meaning live fingerprint capturing or capture the fingerprint once

[DllImport("SSB.dll", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Unicode)]
public extern static int BDS_SetParametersForDirectMode(IntPtr hadle, int sample);

same as above

[DllImport("SSB.dll", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Unicode)]
public extern static int BDS_SetParametersForDirectMode(IntPtr path, IntPtr i_i_deviceHandle, int i_i_samplingMode);

live capture perameter

[DllImport("SSB.dll", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Unicode)]
public extern static int BDS_DefineLiveProcess(IntPtr l_p_handle, int a, BDS_Callback c);

same as above

[DllImport("SSB.dll", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Unicode)]
public extern static int BDS_DefineLiveProcess(int l_p_handle, BDS_Callback bds);

Maybe there is another place where we can clear all our doughts. we search the site to find that place.

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.