Ejemplo n.º 1
0
        private void HistMenuItem_Click(object sender, EventArgs e)
        {
            if (m_bitmap == null)
            {
                return;
            }
            TiHistogram histogram = null;

            try
            {
                BitmapData bitmapData = m_bitmap.LockBits(new Rectangle(0, 0, m_bitmap.Width, m_bitmap.Height),
                                                          ImageLockMode.ReadWrite, PixelFormat.Format32bppArgb);
                IntPtr ptr = NativeMethods.GetImageHistogram(bitmapData.Scan0, bitmapData.Width, bitmapData.Height, bitmapData.Stride, m_bpp);
                if (ptr != null)
                {
                    histogram = (TiHistogram)Marshal.PtrToStructure(ptr, typeof(TiHistogram));
                    Marshal.DestroyStructure(ptr, typeof(TiHistogram)); //销毁非托管的内存
                }
                m_bitmap.UnlockBits(bitmapData);
            }
            catch (System.Exception ex)
            {
                Console.WriteLine(ex.ToString());
            }
            if (histogram != null)
            {
                HistogramForm form = new HistogramForm(histogram);
                form.ShowDialog();
            }
        }
Ejemplo n.º 2
0
 public HistogramForm(TiHistogram histogram)
 {
     InitializeComponent();
     m_histogram     = histogram;
     m_currentValues = m_histogram.rgbValues;
     m_color         = Color.Gray;
 }