zoukankan      html  css  js  c++  java
  • 高效取图片像素的方法

     public static short搜索[][] GetPixs(Bitmap bitmap)
            {
                int height = bitmap.Height;
                int width = bitmap.Width;
                byte tempB, tempG, tempR;
                short[][] spOriginData = new short[height][];
                for (int i = 0; i < height; i++)
                {
                    spOriginData[i] = new short[width];
                }

                BitmapData dataOut = bitmap.LockBits(new Rectangle(0, 0, width, height), ImageLockMode.ReadWrite, PixelFormat.Format24bppRgb);
                int offset = dataOut.Stride - dataOut.Width * 3;
                try
                {
                    unsafe
                    {
                        byte* pOut = (byte*)(dataOut.Scan0.ToPointer());

                        for (int y = 0; y < height; y++)
                        {
                            for (int x = 0; x < width; x++)
                            {
                                tempB = pOut[0];
                                tempG = pOut[1];
                                tempR = pOut[2];
                                double data=0.31 * tempR + 0.59 * tempG + 0.11 * tempB;
                                if (data > 255)
                                    spOriginData[y][x] = 255;
                                else
                                    if (data < 0)
                                        spOriginData[y][x] = 0;
                                    else
                                        spOriginData[y][x] = (short)data;
                                pOut += 3;
                            }
                            pOut += offset;
                        }
                        bitmap.UnlockBits(dataOut);
                    }
                }
                catch
                {
                }
                return spOriginData;
            }

  • 相关阅读:
    关于WPF中Popup控件的小记
    javascript调用外部wpf的方法
    html+ashx 缓存问题
    『Linux学习笔记』8. 权限
    LeetCode 2.两数相加
    C# 标签打印示例 1
    检索COM 类工厂中CLSID 为 {0002450000000000C000000000000046}的组件时失败
    C# 文件操作(一)
    Nginx 事件基本处理流程分析
    Spring学习笔记1:概论
  • 原文地址:https://www.cnblogs.com/harry0914/p/3435936.html
Copyright © 2011-2022 走看看