【问题标题】:How to crop bmp file in C如何在C中裁剪bmp文件
【发布时间】:2021-04-26 05:21:53
【问题描述】:

我正在尝试学习 C 中的图像处理 我有一个用于位图文件的库 一个 BMP I/O 库 两个主要功能,saveBMP 和 readBMP 我们有我无法弄清楚如何使用 RGB 255 255 255 分割或修剪 BMP 文件的一部分。 library bmpio link

#include <stdio.h>
#include <bmpio.h>

unsigned char pic[2000][2000][3];

int main(){
    int width,height;
    readBMP("img.bmp",&width,&height,pic);
    row=findsatr(width,height);
    col=findsoton(width,height);
    splitrow(row);
    splitcol(col);
    trim(row,col);
    saveBMP(pic,width,height,"out.bmp");
    return 0;
}

findcol(int width,height){
    int i,j;
    for(i=0;i>width;i++){
        for(j=0;j>height;j++){
            if(pic[i][j][0]==255&&pic[i][j][1]==255&&pic[i][j][2]==255){
                return j;
            }
            else{
                return -1;
            }
        }
    }
}

findrow(int width,int height){
    int i,j;
    for(j=0;j>height;j++){
        for(i=0;i>width;i++){
            if(pic[i][j][0]==255&&pic[i][j][1]==255&&pic[i][j][2]==255){
                return i;
            }
            else{
                return -1;
            }
        }
    }
}

很难理解它是如何工作的,我不知道如何删除 BMP 的白色部分。

int splitcol(int height){
    

}

int splitrow(int height){
    

}


int trim(int width,int height){

}

【问题讨论】:

    标签: c image-processing bmp


    【解决方案1】:

    假设您要捕获图像的矩形部分,其左上角位于 w1、h1 和右下角 w2、h2。

    unsigned char pic[2000][2000][3];
    unsigned char pic2[2000][2000][3];
    int width = w2-w1;
    int height=h2-h1;
    for(int i=0;i<=width;i++)
        for(int j=0;j<=height;j++)
            for(int k=0;k<=3;k++)
                pic2[i][j][k] = pic[i+width][j+height][k];
    
    saveBMP(pic2,width,height,"out.bmp")
    

    【讨论】:

      猜你喜欢
      • 2019-10-18
      • 2023-03-31
      • 1970-01-01
      • 1970-01-01
      • 2015-05-29
      • 1970-01-01
      • 1970-01-01
      • 2010-11-26
      • 1970-01-01
      相关资源
      最近更新 更多