• BCB实现BMP图片的RGB分解(转)


    源:BCB实现BMP图片的RGB分解

    1、打开BMP图片文件,在Image控件中显示;

      if(dlgOpen1->Execute())
      {
        edt1->Text=dlgOpen1->FileName;
        img1->Picture->LoadFromFile(edt1->Text);
      }

    2、逐行扫描图片,获取图片中每点的像素颜色值;        color=img1->Canvas->Pixels[i][j];

    3、从获取的颜色值中提取R、G、B分量;         rgbbuf[0][i][j]=GetRValue(color);         rgbbuf[1][i][j]=GetGValue(color);         rgbbuf[2][i][j]=GetBValue(color);

    BMP与JPG格式的相互转换

    函数代码如下,在程序头文件中加入:#include <jpeg.hpp>

    void   bmptojpeg(TMemoryStream   *pms)
      {   
            TJPEGImage   *j=new   TJPEGImage;   
            Graphics::TBitmap   *b=new   Graphics::TBitmap;
            b->LoadFromStream(pms);
            j->Assign(b);   
            j->CompressionQuality=60;       //等级太高有可能压缩出错!   
            j->Compress();   
            pms->Clear();   
            j->SaveToStream(pms);   
            pms->Position=0;   
            delete   b;   
            delete   j;   
              
      }   
      void   jpegtobmp(TMemoryStream   *pms)   
      {   
          TJPEGImage   *j=new   TJPEGImage;   
          Graphics::TBitmap   *b=new   Graphics::TBitmap;   
        
          j->LoadFromStream(pms);   
          j->DIBNeeded();   
          b->Assign(j);   
          pms->Clear();   
          b->SaveToStream(pms);   
          pms->Position=0;   
        
          delete   b;   
          delete   j;   
        
      }

    要将转换后的流保存成文件可以使用:SaveToFile方法保存;

  • 相关阅读:
    Java线程
    IO流
    staitc
    权限修饰符
    nexus
    Maven
    Git 常用命令
    获取url参数
    创建存储过程和函数
    三层引号
  • 原文地址:https://www.cnblogs.com/LittleTiger/p/4708532.html
Copyright © 2020-2023  润新知