用偽語(yǔ)句可以表示如下
public bitmap GrayScal(bitmap orgbmp)
{
    建立一個(gè)與原圖片等大的8位的圖片
    取出原圖像中的每一個(gè)點(diǎn)
    新圖像的點(diǎn)=原圖像點(diǎn)的紅色量*系數(shù)1+綠色量*系數(shù)2+黃色量*系統(tǒng)3
    返回新圖像
}
        /// <summary>
        /// 做點(diǎn)運(yùn)算,要給每一個(gè)偏量,做一下設(shè)置,比如做圖像的灰度圖就需要現(xiàn)設(shè)置
        /// </summary>
        /// <param name="cr"></param>
        /// <param name="cg"></param>
        /// <param name="cb"></param>
        public PointTrans(double cr, double cg, double cb)
        {
            this.cr = cr;
            this.cg = cg;
            this.cb = cb;
        }
        public  Bitmap GrayScaleBmp(Bitmap orgData)
        {
            int bmpWidth = orgData.Width, bmpHeight = orgData.Height;
            Bitmap destData = ImageTools.CreateGrayscaleImage(bmpWidth, bmpHeight);
            Rectangle bmpRect=new Rectangle(0,0,bmpWidth,bmpHeight);
BitmapData orgBmpData = orgData.LockBits(bmpRect, ImageLockMode.ReadOnly, PixelFormat.Format24bppRgb);
            BitmapData destBmpData = destData.LockBits(bmpRect, ImageLockMode.WriteOnly, PixelFormat.Format8bppIndexed);
            ProcessFilter(orgBmpData,destBmpData);
            orgData.UnlockBits(orgBmpData);
            destData.UnlockBits(destBmpData);
            return destData;
}
        protected unsafe void ProcessFilter(BitmapData sourceData, BitmapData destinationData)
        {
            // get width and height
            int width = sourceData.Width;
            int height = sourceData.Height;
            int srcOffset = sourceData.Stride - width*3;
            int dstOffset = destinationData.Stride - width;
            // do the job
            byte* src = (byte*) sourceData.Scan0.ToPointer();
            byte* dst = (byte*) destinationData.Scan0.ToPointer();
            // for each line
            for (int y = 0; y < height; y++)
            {
                // for each pixel
                for (int x = 0; x < width; x++, src += 3, dst++)
                {
                    *dst = (byte) (cr*src[RGB.R] + cg*src[RGB.G] + cb*src[RGB.B]);
                }
                src += srcOffset;
                dst += dstOffset;
            }
        }
    }
| 
 
 | 
新聞熱點(diǎn)
疑難解答
圖片精選