久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

位圖中的顏色百分比

Colour percentage in Bitmap(位圖中的顏色百分比)
本文介紹了位圖中的顏色百分比的處理方法,對(duì)大家解決問(wèn)題具有一定的參考價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)吧!

問(wèn)題描述

在不了解位圖的情況下開(kāi)始**

To get total pixels in bitmap  height*Width 
To get total white pixels Where R==255 & B==255 & G==255
To get total black pixels Where R==0 & B==0 & G==0
To get total grey pixels where R=G=B

其余的將是應(yīng)該給我的混合顏色.顯然程序會(huì)運(yùn)行數(shù)千次,所以我需要使用Lockbits.

Rest of them will be a mixed colours which should give me. Obviously the program will run for thousands of times,so I need to use Lockbits.

當(dāng)前問(wèn)題是結(jié)果不準(zhǔn)確.請(qǐng)建議.嘗試使用 aforge.net 或 imagemagick.net 庫(kù)來(lái)檢查它是否可以給出準(zhǔn)確的結(jié)果

current problem is inaccurate result. pls suggest. Trying to use aforge.net or imagemagick.net libraries to check whether it can give accurate results

如何找到位圖中的顏色像素百分比,最初位圖對(duì)象來(lái)自PDF頁(yè)面.我嘗試使用 bitmap.getpixel() 它需要很長(zhǎng)時(shí)間,LockBits 的性能更好,想知道使用 Lockbits 找到不包括黑色、白色和灰色的彩色像素的百分比.這是為了識(shí)別PDF文件中的彩色頁(yè)面和打印特定頁(yè)面的顏色使用.

How do I find the color pixels percentage in bitmap, originally the bitmap object is from PDF page. I tried with bitmap.getpixel() it is taking ages, LockBits is better in performance, Would like to know using Lockbits finding the percentage of color pixels excluding black, white and grey. This is to identify the colour pages in PDF file and colour usage for printing specific page.

我剛剛有一個(gè)代碼來(lái)檢測(cè)黑白像素的數(shù)量,我只是想利用這個(gè)代碼來(lái)檢測(cè)百分比,只需找到總像素,然后差異應(yīng)該給我彩色像素,不確定方法是否正確!!

I have just got a code to detect the count of black and white pixels, I am just trying to make use of this code to detect percentage just by finding the total pixels and then the difference should give me colour pixels,not sure it is correct approach or not!!

 public void ColourPercentage(Bitmap page, ref int nBlackCount, ref int nWhiteCount)
    {
        System.Drawing.Image image = null;
        Bitmap bmpCrop = null;

        BitmapData bmpData = null;
        byte[] imgData = null;
        int n = 0;
        try
        {
            image = page;
            bmpCrop = new Bitmap(image);
            for (int h = 0; h < bmpCrop.Height; h++)
            {

                bmpData = bmpCrop.LockBits(new System.Drawing.Rectangle(0, h, bmpCrop.Width, 1),
                System.Drawing.Imaging.ImageLockMode.ReadOnly, image.PixelFormat);
                imgData = new byte[bmpData.Stride];
                System.Runtime.InteropServices.Marshal.Copy(bmpData.Scan0, imgData, 0
                , imgData.Length);
                bmpCrop.UnlockBits(bmpData);

                for (n = 0; n <= imgData.Length - 3; n += 3)
                {
                    if ((int)imgData[n] == 000 && (int)imgData[n + 1] == 0 && (int)imgData[n + 2] == 000)// R=0 G=0 B=0 represents Black
                    {
                        nBlackCount++;
                    }
                    else if ((int)imgData[n] == 255 && (int)imgData[n + 1] == 255 && (int)imgData[n + 2] == 255) //R=255 G=255 B=255 represents White
                    {
                        nWhiteCount++;
                    }
                    else if ((int)imgData[n] == (int)imgData[n + 1] && (int)imgData[n + 1] == (int)imgData[n + 2])
                        nBlackCount++;
                }

            }

        }
        catch (Exception ex)
        {
            System.Windows.MessageBox.Show(ex.Message);
        }     
    }

<小時(shí)>

  public void blackwhiteCount(Bitmap page, ref int nBlackCount, ref int nWhiteCount)
    {
        System.Drawing.Color pixel;
        try
        {
            for (int i = 0; i < page.Height; i++)
            {
                for (int j = 0; j < page.Width; j++)
                {
                    pixel = page.GetPixel(i, j);
                    if (pixel.R == 0 && pixel.G == 0 && pixel.B == 0)
                        nBlackCount++;
                    else if (pixel.R == 255 && pixel.G == 255 && pixel.B == 255)
                        nWhiteCount++;
                }
            }
        }
        catch (Exception ex)
        {
            System.Windows.MessageBox.Show("Unable to parse image " + ex);
        }
    }

<小時(shí)>

ColourPercentage(page, ref nblack, ref nwhite);
                             double nTotal = page.Width * page.Height;
                            string blackper, whiteper, colourper;
                            double black =(double) nblack*100 / nTotal;
                            double white =(double) nwhite *100 / nTotal;
                            double colour = 100 - (black + white);

推薦答案

我找到了自己,為了方便瀏覽者重新使用,添加更正(問(wèn)題已經(jīng)更新了答案).

I have found myself, for viewers convenience for re usage, adding the correction(Question is updated with the answer already).

要獲得總像素,請(qǐng)使用圖像尺寸,而不是計(jì)算 bitlockdata 中的循環(huán)像素.

To get total pixels use image dimensions, instead of counting the looping pixels in bitlockdata.

Image page= new Image(filePath);
double nTotal = page.Width * page.Height;

這篇關(guān)于位圖中的顏色百分比的文章就介紹到這了,希望我們推薦的答案對(duì)大家有所幫助,也希望大家多多支持html5模板網(wǎng)!

【網(wǎng)站聲明】本站部分內(nèi)容來(lái)源于互聯(lián)網(wǎng),旨在幫助大家更快的解決問(wèn)題,如果有圖片或者內(nèi)容侵犯了您的權(quán)益,請(qǐng)聯(lián)系我們刪除處理,感謝您的支持!

相關(guān)文檔推薦

Right-click on a Listbox in a Silverlight 4 app(右鍵單擊 Silverlight 4 應(yīng)用程序中的列表框)
WPF c# webbrowser scrolls over top menu(WPF c# webbrowser 在頂部菜單上滾動(dòng))
C# Console app - How do I make an interactive menu?(C# 控制臺(tái)應(yīng)用程序 - 如何制作交互式菜單?)
How to avoid duplicate form creation in .NET Windows Forms?(如何避免在 .NET Windows Forms 中創(chuàng)建重復(fù)的表單?)
UI Automation Control Desktop Application and Click on Menu Strip(UI自動(dòng)化控制桌面應(yīng)用程序并單擊菜單條)
Removing thin border around the menuitems(刪除菜單項(xiàng)周圍的細(xì)邊框)
主站蜘蛛池模板: 91新视频 | 国产一区二区三区四区五区加勒比 | 成人欧美一区二区三区黑人孕妇 | 日韩一区二区福利 | 日韩午夜电影在线观看 | 国产免费一区二区 | 日本三级做a全过程在线观看 | 国产成人免费视频网站高清观看视频 | 一区二区视频在线 | 国产色| 亚洲电影中文字幕 | 亚洲国产成人精品久久久国产成人一区 | 国产精品久久久久一区二区三区 | 综合精品久久久 | 爱爱小视频 | 在线观看国产视频 | 亚洲精品视频一区二区三区 | 人人做人人澡人人爽欧美 | 国产精品久久久亚洲 | 一区二区三区不卡视频 | 97伦理电影网| 99国产精品久久久久久久 | 国外成人在线视频网站 | av在线播放网站 | 二区高清 | 涩涩视频网站在线观看 | 2019精品手机国产品在线 | 欧美精三区欧美精三区 | 亚洲九色 | 色婷婷狠狠| 日韩免费福利视频 | 成人毛片网站 | h视频在线观看免费 | 欧美日韩久久精品 | 亚洲国产一区二区三区在线观看 | 国产精品国产三级国产aⅴ入口 | 国产欧美一区二区三区国产幕精品 | 日韩成人在线观看 | 伊人无码高清 | 国产精品一区二区三区在线 | 亚洲免费一区 |