精华内容
下载资源
问答
  • private void ColorBMPToOne(String filename,String toFilename) { FileInfo file = new FileInfo(filename); if (file.Exists) { FileStream fs = file.OpenRead(); 

       private void  ColorBMPToOne(String filename,String toFilename) {
             FileInfo file = new FileInfo(filename);

             if (file.Exists)
             {
                 FileStream fs = file.OpenRead();
                 byte[] bmphead = new byte[54];
                 fs.Read(bmphead, 0, 54);
                 if (bmphead[0].ToString().Equals("66") && bmphead[1].ToString().Equals("77"))
                 {

                     int bmpwidth = int.Parse(bmphead[18].ToString()) + int.Parse(bmphead[19].ToString()) * 256 + int.Parse(bmphead[20].ToString()) * 256 * 256 + int.Parse(bmphead[21].ToString()) * 256 * 256 * 256;
                     int bmpheight = int.Parse(bmphead[22].ToString()) + int.Parse(bmphead[23].ToString()) * 256 + int.Parse(bmphead[24].ToString()) * 256 * 256 + int.Parse(bmphead[25].ToString()) * 256 * 256 * 256; ;
                     int bit = int.Parse(bmphead[28].ToString());

                     if ((bit == 24) || (bit == 32))
                     {
                     }
                     else {
                         MessageBox.Show("请确定图位数为24或者32位图");
                         return;
                    
                     }

                     int bblength = bmpwidth * 3;
                     int bbend = 0;
                     if ((bmpwidth*3 % 4) > 0)
                     {

                         bbend=4 - ((bmpwidth * 3) % 4);
                         bblength = bmpwidth * 3 + bbend;
                        
                     }


                     int newbmpwidth = 0;

                     if((bmpwidth%32)>0){

                         newbmpwidth = ((32 - bmpwidth % 32) + bmpwidth) / 8;
                    
                     }else{

                         newbmpwidth = bmpwidth / 8;
                     }


                    
                     int bmpsize = newbmpwidth * bmpheight;

     

                     //图片所占的大小(算上数据头62位的)
                     int bmprelsize = bmpsize + 54 + 8; //54是bmp表头数据.8位是颜色表,分别为00,00,00,00,ff,ff,ff,00
                     byte[] bmpbit = new byte[bmprelsize + newbmpwidth];
                     Array.Copy(bmphead, bmpbit, 54);

                     #region 写表头的数据
                     bmpbit[10] = 0x3e;
                     bmpbit[28] = 0x01;
                     bmpbit[54] = 0x00;
                     bmpbit[55] = 0x00;
                     bmpbit[56] = 0x00;
                     bmpbit[57] = 0x00;
                     bmpbit[58] = 0xff;
                     bmpbit[59] = 0xff;
                     bmpbit[60] = 0xff;
                     bmpbit[61] = 0x00;

                     //图所占的空间大小,这个不包括图头的
                     String bmpsizeString = String.Format("{0:x2}", bmpsize);
                     String bmpresizeString = String.Format("{0:x2}", bmprelsize);
                     bmpsizeString = bmpsizeString.PadLeft(8, '0');
                     bmpresizeString = bmpresizeString.PadLeft(8, '0');

                     Char[] chsize = bmpsizeString.ToCharArray();
                     Char[] chresize = bmpresizeString.ToCharArray();

     

                     for (int i = 0; i < 8; i = i + 2)
                     {
                         bmpbit[37 - (i / 2)] = (byte)(Uri.FromHex(chsize[i]) * 16 + Uri.FromHex(chsize[i + 1]));
                         bmpbit[5 - (i / 2)] = (byte)(Uri.FromHex(chresize[i]) * 16 + Uri.FromHex(chresize[i + 1]));
                     }
                     #endregion

     

                     MessageBox.Show(bmpwidth.ToString() + "@@@" + bmpheight.ToString() + "@@@" + newbmpwidth.ToString() + "@@@" + bmprelsize.ToString() + "@@@" + fs.Length+"@@"+bblength.ToString());


                     #region


                     byte[] bbrec = new byte[bblength];
                     byte[] bb = new byte[bmpwidth*3];
                     int[] ch = new int[8];
                     int[] chend = new int[8];
                     int count = 0;
                     int count2 = 0;
                     int count3 = 0;
               
                     char[] cc = new char[2];
                     int bmpheightcount = 0;
                     int bmpendcount = 0;

                     while (fs.Read(bbrec, 0, bblength) > 0)
                     {
                         Array.Copy(bbrec, 0, bb, 0, bmpwidth * 3);
                        

                     
                      
                         for (int k = 0; k < bb.Length-23 ; k = k + 24)
                         {
                             bmpendcount = k/24;
                             for (int j = 0; j < 8; j++)
                             {
                                 count = k + j * 3;
                                 if ((bb[count].ToString().Equals("255")) && (bb[count + 1].ToString().Equals("255")) && (bb[count + 2].ToString().Equals("255")))
                                 {
                                     ch[j] = 1;
                                 }
                                 else
                                 {
                                     ch[j] = 0;
                                 }
                             }
                             count2 = ch[0] * 8 + ch[1] * 4 + ch[2] * 2 + ch[3];
                             count3 = ch[4] * 8 + ch[5] * 4 + ch[6] * 2 + ch[7];
                             cc[1] = Convert.ToChar(count3.ToString("x"));
                             cc[0] = Convert.ToChar(count2.ToString("x"));
                             int rewrite = k / 24 + newbmpwidth * bmpheightcount + 62;
                             bmpbit[rewrite] = (byte)(Uri.FromHex(cc[0]) * 16 + Uri.FromHex(cc[1]));
                         }
                        
                  
                       
                         #region
                         int m = bb.Length% 24;
                         ch = new int[8];
                         for (int i = 0; i < ch.Length; i++)
                         {
                             ch[i] = 1;
                         }
                             if (m > 0)
                             {
                                 bmpendcount = bmpendcount + 1;
                                 for (int i = 0; i < m; i = i + 3)
                                 {
                                     int j = bb.Length - m + i;

                                     if ((bb[j].ToString().Equals("255")) && (bb[j + 1].ToString().Equals("255")) && (bb[j + 2].ToString().Equals("255")))
                                     {
                                         ch[i / 3] = 1;
                                     }
                                     else
                                     {

                                         ch[i / 3] = 0;
                                     }
                                 }
                                 count2 = ch[0] * 8 + ch[1] * 4 + ch[2] * 2 + ch[3];
                                 count3 = ch[4] * 8 + ch[5] * 4 + ch[6] * 2 + ch[7];
                                 cc[1] = Convert.ToChar(count3.ToString("x"));
                                 cc[0] = Convert.ToChar(count2.ToString("x"));
                                 bmpbit[bmpendcount + newbmpwidth * bmpheightcount + 62] = (byte)(Uri.FromHex(cc[0]) * 16 + Uri.FromHex(cc[1]));
                             }
                         #endregion
                        
                         for (int i = bmpendcount+1; i < newbmpwidth;i++ ) {
                             bmpbit[i + newbmpwidth * bmpheightcount + 62] = (byte)Convert.ToInt16(255);
                        
                         }

                         for (int i = bmpbit.Length; i > (bmpbit.Length - newbmpwidth);i--)
                         {
                             bmpbit[i-1] = (byte)Convert.ToInt16(255);
                         }
                         bmpheightcount = bmpheightcount + 1;
                         bb = new byte[bmpwidth * 3];

                     }
                     MessageBox.Show(bmpheightcount.ToString());
                     FileStream fwrite = new FileStream(toFilename, FileMode.Create);
                     fwrite.Write(bmpbit, 0, bmpbit.Length);
                     fwrite.Close();
                     fs.Close();
                     #endregion
                 }
                 else {
                     MessageBox.Show("非BMP格式的数据");
                 }
             }
             else {
                 MessageBox.Show("文件路径不对,请确定文件路径");
             }
            }

     

    因为打印机的显示与微软的显示不一样,所以要转的时候要填充后面的补的字节,不然在打印的时候会有一条黑线

    展开全文
  • python 转换彩图黑白图 ,去噪

    万次阅读 2014-08-08 13:29:40
    原图:

    原图:

    转换成:


    python代码

    # -*- coding: utf-8 -*-
    
    import os
    from PIL import *
    
    curdir="E:\\py\\WinPython-32bit-2.7.6.4\\study"
    
    os.chdir(curdir)
    
    
    def RGB2BlackWhite(filename):
        im=Image.open(filename)
        print "image info,",im.format,im.mode,im.size
        (w,h)=im.size
        R=0
        G=0
        B=0
    
        for x in xrange(w):
            for y in xrange(h):
                pos=(x,y)
                rgb=im.getpixel( pos )
                (r,g,b)=rgb
                R=R+r
                G=G+g
                B=B+b
    
        rate1=R*1000/(R+G+B)
        rate2=G*1000/(R+G+B)
        rate3=B*1000/(R+G+B)
        
        print "rate:",rate1,rate2,rate3
    
        
        for x in xrange(w):
            for y in xrange(h):
                pos=(x,y)
                rgb=im.getpixel( pos )
                (r,g,b)=rgb
                n= r*rate1/1000 + g*rate2/1000 + b*rate3/1000
                #print "n:",n
                if n>=60:
                    im.putpixel( pos,(255,255,255))
                else:
                    im.putpixel( pos,(0,0,0))
                    
        im.save("blackwhite.bmp")                
          
    def saveAsBmp(fname):    
        pos1=fname.rfind('.')
        fname1=fname[0:pos1]
        fname1=fname1+'_2.bmp'
        im = Image.open(fname)
        new_im = Image.new("RGB", im.size)
        new_im.paste(im)
        new_im.save(fname1)          
        return fname1          
                    
    if __name__=="__main__":
        filename=saveAsBmp("2ujb.bmp")
        RGB2BlackWhite(filename)
        
                


    展开全文
  • 作者:曼哈顿印象微博:曼哈顿印象PHOTO 视频教程视频教程​www.bilibili.com哈喽,大家好,我是小曼(曼哈顿印象),今天给大家带来一期照片转黑白的教程,利用PS快速修出高质量的黑白照片。我们来看看对比图:第1...

    作者:曼哈顿印象

    微博:曼哈顿印象PHOTO

    视频教程

    视频教程​www.bilibili.com

    哈喽,大家好,我是小曼(曼哈顿印象),今天给大家带来一期照片转黑白的教程,利用PS快速修出高质量的黑白照片。

    我们来看看对比图:

    6ca34c80ebe5fef0b85ba73c113be45f.png

    3a8df812e5e0eaedb43ba343ec183265.png

    第1步:转为黑白

    首先第一步我们需要做的就是将照片转为黑白,这里我选择调整图层里的黑白工具,其实PS里面有很多转黑白的方式,之所以选择这个黑白工具因为这个工具可以调整照片原本颜色的黑白亮度。

    046150232b1dce26239b0a260f053ef4.png

    这里参数选择不固定,尽量调整让照片整体看起来黑白对比强烈点。

    b9d6c5cd5be43ff07de7bc9782818510.png

    调整后:

    e258a3ddf499638bff83b644503dcd37.png

    第2步:压暗人物周围

    为了让主体更突出点,我们需要将主体周围给压暗,这里选择带有蒙版的曲线工具进行压暗:

    0eab534764028e98a7e2b9092d6108ac.png

    里面蒙版用黑色把人物擦出来,人物不需要压暗。

    10fec73c7705131cf82539ca57c208ca.png

    调整后:

    e30ca23922db21b78aebcba7d4b73013.png

    第3步:高低频

    皮肤的处理,我们选择高低频方法进行磨皮:按住快捷键shift+alt+ctrl+e合并图层:为图层2,再次复制一个图层2:为图层3

    dce01b451550e23b5e47522968be421f.png

    对图层2进行以下操作:滤镜—高斯模糊—半径2.8左右。

    6f0a2bec697fd15c261419e83ab21ccb.png

    format,png

    对图层3进行以下操作:图像——应用图像

    e63741c42fc3eae731a54bbd19951b8a.png

    图层选择进行过高斯模糊的图层2,混合选择:减去,缩放:2,补偿值:128.

    a003e838f1c2365dcdfccbcd7eb410ca.png

    点击确定后,改变图层3的图层模式:改为线性光。

    第4步:磨皮

    这里我们选择进行过高斯模糊的图层2进行操作,选择混合器画笔工具

    2877db298cce3b7eb4fc2bcb401c64a5.png

    参数选择如图:选项-每次描边后清理画笔-点按下去,参数分别设置为:49%,30%,28%,82%。

    6a777e5023121d53994c931505672c39.png

    然后就可以开始涂抹皮肤了。

    涂抹后:

    cc08d91b59703f0cb388bf713c389648.png

    第 5步:锐化皮肤

    由于经过磨皮后,皮肤纹理几乎没有了,所以这一步需要对皮肤进行锐化的处理。

    按住快捷键shift+alt+ctrl+e合并图层,选择滤镜—cameraraw滤镜。

    这一步的处理,主要是调整照片的黑白灰关系,让整体看起来更有质感。

    df2ad5b0edf954a6c5f7a7c5d3c6b840.png

    再次复制一个图层,选择滤镜—其他—高反差保留—半径4.1左右

    8e013a7fb302572bb6988837228a1fc2.png

    26a88aecbbae9f47b30a2c0d9880c06b.png

    然后将图层模式改为:线性光。

    最终效果:

    69afc11bf17f8cd07950188de95b539b.png

    喜欢的点个赞奥!

    98ab4d70fd7712bd4bab1c20714d327a.png
    展开全文
  • gif动态彩图转化黑白动画(简单图形识别)这个项目是去年的时候写的东西了,今天整理代码的时候发现,运行了一下发现挺有趣的——将动态的gif图片识别颜色深度转化为黑白动画
  • 不要在意性别。! Google并且自己尝试了一晚上都不知道怎么搞 求助。!!
  • 内容索引:脚本资源,jQuery,图片交换 jQuery一个图片处理效果,将真彩色的图片逐渐变为黑白图像,在不知不觉中变换,大家不要想是jquery把彩色去掉了,实际上没有这么神奇,它是在平滑的交换图片,当你鼠标移到图片上的...
  • MFC类库彩图黑白

    2010-05-27 22:04:43
    A3纸打印,边学边画有助于快速MFC入门。
  • coreldraw把彩图快速变黑白图 huangshengqing 来自地理爱好者 我们常常会遇到这样的问题想把某幅彩图变为黑白图例如我想把下图世界所平均气温的分布图来自七年级上册天气与气候转变成黑白图以便于做学案或者出一些...
  • I've got a bitmap displayed in an ImageView, and I want to be able to make a certain percentage of the image black and white, and have the other part retain it's color. For example, if 60% is the targ...

    I've got a bitmap displayed in an ImageView, and I want to be able to make a certain percentage of the image black and white, and have the other part retain it's color. For example, if 60% is the target percentage, the image would look like this:

    9lQu9.png. Thanks.

    解决方案I've got a bitmap displayed in an ImageView, and I want to be able to

    make a certain percentage of the image black and white, and have the

    other part retain it's color. For example, if 60% is the target

    percentage.

    It seems (from your image) you mean monochrome (i.e. greyscale), not black and white.

    Something like this should do it (tested o.k.):

    void doIt(ImageView image)

    {

    //get bitmap from your ImageView (image)

    Bitmap originalBitmap = ((BitmapDrawable)image.getDrawable()).getBitmap();

    int height = originalBitmap.getHeight();

    int fortyPercentHeight = (int) Math.floor(height * 40.0 / 100.0);

    //create a bitmap of the top 40% of image height that we will make black and white

    Bitmap croppedBitmap = Bitmap.createBitmap(originalBitmap, 0, 0, originalBitmap.getWidth() , fortyPercentHeight );

    //make it monochrome

    Bitmap blackAndWhiteBitmap = monoChrome(croppedBitmap);

    //copy the monochrome bmp (blackAndWhiteBitmap) to the original bmp (originalBitmap)

    originalBitmap = overlay(originalBitmap, blackAndWhiteBitmap);

    //set imageview to new bitmap

    image.setImageBitmap(originalBitmap );

    }

    Bitmap monoChrome(Bitmap bitmap)

    {

    Bitmap bmpMonochrome = Bitmap.createBitmap(bitmap.getWidth(), bitmap.getHeight(), Bitmap.Config.ARGB_8888);

    Canvas canvas = new Canvas(bmpMonochrome);

    ColorMatrix ma = new ColorMatrix();

    ma.setSaturation(0);

    Paint paint = new Paint();

    paint.setColorFilter(new ColorMatrixColorFilter(ma));

    canvas.drawBitmap(bitmap, 0, 0, paint);

    return bmpMonochrome;

    }

    Bitmap overlay(Bitmap bmp1, Bitmap bmp2)

    {

    Bitmap bmp3 = bmp1.copy(Bitmap.Config.ARGB_8888,true);//mutable copy

    Canvas canvas = new Canvas(bmp3 );

    canvas.drawBitmap(bmp2, new Matrix(), null);

    return bmp3 ;

    }

    展开全文
  • C语言实现的bmp彩图转二值图;使用2*2模板灰度图二值图
  • 此外, 文中几乎所有黑白图片都被我覆盖上了官网上提供的彩色插图 (注意是覆盖,移开彩图下面还有原来的黑白插图). 个别没有覆盖的是因为新图也是黑白的, 而且清晰度也差不多, 覆盖意义不大, 所以就不再麻烦了. 此...
  • 求各位大牛帮忙,小弟在程序中需要对彩图黑白图做不同处理,但是黑白图处理效果比较好。现在遇到一个问题,在彩色图片中会有很多彩色的黑白图(看起来是黑白图,实际上是彩色图),我想把这种图片作为黑白图处理,...
  • 24位真彩图转8位灰度图

    千次阅读 2014-02-27 23:39:46
    实现了24位真彩图转8位灰度图的基本功能,不过只是为了实现功能,并没有进行错误处理等,仅供大家一点参考 #include #include #include /* typedef struct tagBITMAPFILEHEADER {  WORD bfType; // 位图...
  • word彩色图片转黑白

    千次阅读 2019-03-06 17:28:23
    专利申请书要求图片只能是黑白的,所以在此记录操作过程。 1. 若图片是visio格式且插入的是visio自带的框图,可通过修改框图的“填充”和“线条”来将彩色变成黑白; 2. 若图片是visio格式且插入的是图片,可将该...
  • [img=https://img-bbs.csdn.net/upload/201401/11/1389419211_206318.jpg][/img] [img=https://img-bbs.csdn.net/upload/201401/11/1389419271_423911.jpg][/img]
  • 下面十几行代码,能帮助你理解彩色图转化为黑白图的原理
  • 一些简单的计算机实现工具,此物主要用来实现彩图像灰度的转换。
  • save_name=None, # 保存文件名 (如果是 动图用 gif 结尾哦) save_dir=os.getcwd() # 保存路径 ) Demo: from MyQR import myqr print("start 黑白:") version, level, qr_name = myqr.run(words='...
  • import image,lcd lcd.init() img = image.Image("xianyu2.jpg") img = img.find_edges(image.EDGE_SIMPLE,threshold = (10, 255)) lcd.display(img)
  • 本帖最后由 西双版纳 于 2009-7-16 14:06 编辑 (原创)如何制作反差和明度值都与原彩图一样的黑白片 (2009-7-16) 将彩色图转为黑白片,方法有很多。但是,在转变的过程中,如果要将原来的彩色图片的反差、明度值...
  • Halcon RGB彩色灰度图: read_image(Image, './imgs/1.png') rgb1_to_gray(Image, ...Halcon灰度图RGB彩图: compose3(GrayImage, GrayImage, GrayImage, ColorImage) 比较简单,仅用于个人学习记录。。
  • 图像 -> 调整 -> 去色
  • 摘要:VC/C++源码,图形处理,彩色转换  VC++将彩色图像转换成黑白图像源代码,图像灰度转换的一个示例程序,基于VC++源码实现,供VC初学者参考。
  • ①实现将彩色图像转换为灰度图像、黑白图像的功能; ②实现将图像整体呈现效果为偏绿色风格; ③并将原始图像、灰度图像、黑白图像、绿色滤镜图像展示在同一个图像 窗口内。 每个子图要有相应的图名,最终呈现...
  • 如何将彩色图片转为黑白图片 第一种方法-灰度公式法: 看了网上很多人说有个灰度公式,可以直接遍历每个像素,并把每个像素中的rgb换成如下值即可: P=0.299×Red+0.587×Green+0.114×BlueP=0.299\times Red +0.587...
  • 本例子将800*600的double类型的数据先进行归一化成0-255的quint8类型的数据,然后将归一化后的数据生成一个QImage,这个QImage的格式一定要是 QImage::Format_Indexed8 这是为了方便使用自定义的颜色表,然后将...
  • 本篇文章参考了博客http://blog.csdn.net/matrix_space/article/details/22992833和博客http://blog.csdn.net/maozefa/article/details/6584877 黑白调整 Photoshop CS的图像黑白调整功能...能更精细地将彩色图片

空空如也

空空如也

1 2 3 4 5 ... 20
收藏数 1,001
精华内容 400
关键字:

彩图转黑白