BMP 속성값을 바꿔 B만 0으로만드는 C코딩
모람
질문 제목 : bmp 속성값을 바꿔 b만 0으로만드는 c코딩아무 bmp 파일만가지고 b숫자만 0인 c코딩을해서 화면에 출력하고싶습니다.질문 내용 :#includestdio.h
#includemalloc.hint main()
{
char firstcharacter;
char secondcharacter;
unsigned int size;
unsigned int reserved;
unsigned int data_offset;
unsigned int size_x;
unsigned int width;
unsigned int height;
unsigned int planes;
unsigned int bit_count;
unsigned int compression;
unsigned int image_size;
int image_height;
int image_width;
int image_data_size;
unsigned int x_pixels_per_m;
unsigned int y_pixels_per_m;
unsigned int colors_used;
unsigned int colors_important;
int i,j;
file * fp = fopen(d:\dd.bmp, rb);
fread (&firstcharacter, sizeof (char), 1, fp);
fread (&secondcharacter, sizeof (char), 1, fp);
fread (&size, sizeof (int), 1, fp);
fread (&reserved, sizeof (int), 1, fp);
fread (&data_offset, sizeof (int), 1, fp);
fread (&size_x, sizeof (int), 1, fp);
fread (&width, sizeof (int), 1, fp);
fread (&height, sizeof (int), 1, fp);
fread (&planes, sizeof (int), 1, fp);
fread (&bit_count, sizeof (int), 1, fp);
fread (&compression, sizeof (int), 1, fp);
fread (&image_size, sizeof (int), 1, fp);
fread (&x_pixels_per_m, sizeof (int), 1, fp);
fread (&y_pixels_per_m, sizeof (int), 1, fp);
fread (&colors_used, sizeof(int), 1, fp);
fread (&colors_important, sizeof(int), 1, fp);
printf (first character is %c \n, firstcharacter);
printf (second character is %c \n, secondcharacter);
printf (size is %d \n,size);
printf (reserved is %d \n,reserved);
printf (data_offset is %d \n,data_offset);
printf (size_x is %d \n,size_x);
printf (width is %d \n,width);
printf (height is %d \n,height);
printf (planes is %d \n,planes);
printf (bit_count is %d \n,bit_count);
printf (compression is %d \n,compression);
printf (image_size is %d \n,image_size);
printf (x_pixels_per_m is %d \n,x_pixels_per_m);
printf (y_pixels_per_m is %d \n,y_pixels_per_m);
printf (colors_used is %d \n, colors_used);
printf (colors_important is %d \n, colors_important); char * image_data = (char *) malloc(image_data_size);
fread (image_data, image_data_size,1,fp);
unsigned int padding;
padding = 8 - (width*3)%8; for (int i = 0; i image_height; i++)
for (int j = 0; j image_width; j++)
{
image_data[i*(width*3+padding) + j*3] =0; //
} fclose (fp); file * wp;
wp = fopen (newfile.bmp, wb);
fwrite (&firstcharacter, sizeof (char), 1, wp);
///. write header information as same as you read
// now write the image pixel data which is changed one
fwrite (image_data, image_data_size,1,wp);
fwrite (&secondcharacter, sizeof (char), 1, wp); fread(image_data, image_data_size,1,fp); free (image_data); fclose(fp);
fclose (wp); return 0;}
제가 만든 코딩은 여기까진데 일단 성공은되는데 경고가 너무많고, 실행하면 오류가뜨네요.
다른 프로그램을쓰지않고 이프로그램만가지고 b가 0인 bmp파일을 화면에 출력하고싶은데
부족한부분 수정좀 부탁드립니다.
-
큰꽃늘
와 점점 워닝이 없어져갑니다.ㅋㅋㅋㅋㅋ 3개까지 줄였네요. 감사합니다.
근데 실행창띄우면 자꾸 오류가뜹니다ㅠ
조금더 만져보겠습니다. 정말 감사합니다ㅎㅎ -
동은
newfile.bmp에는 헤더가 제대로 쓰이지 않았네요.
dd.bmp에서 헤더를 읽은 순서 그대로 쓰면 됩니다. -
쥬디시어스
C4996경고는 안전성 경고인데 현재는 그리 중요하지 않게 생각해도 됩니다.
경고를 보지 않으려면 소스코드 최상단에 아래를 추가하면 됩니다.
#pragma warning(disable:4996)
\D:\\DD.bmp\가 아니라 역슬래시를 두개 적어야 합니다. \D:\\\\DD.bmp\
image_data_size는 초기화되지 않은 채 사용되었습니다.
image_height, image_width도 마찬가지구요. -
지니
죄송한데 C언어 초보라서요 ㅠ 현재 코딩자체가 잘못된건가요?
아니면 이코딩으론 RGB 중 B색상 0으로만드는게 안되는건가요? -
역곡중
좋은글 감사해요 ㅠ 헌데 저 위 코드로만 해결해야하는문제라서요.
아직 워닝 3개가남았는데 혹시 아직 사이트에계시면 도와주실수있나요? -
채꽃
파일 첨부했는데 확인해주세요.ㅠ 부탁드립니다
-
무슬
DD.bmp 파일을 첨부해주세요
번호 | 제 목 | 글쓴이 | 날짜 |
---|---|---|---|
2694827 | 이제 어떻게 공부해야할지 모르겠네요 | 새얀 | 2025-05-14 |
2694778 | 순열 계산요. | 맛조이 | 2025-05-14 |
2694754 | ShowWindow 함수를 이용하려 하는데 질문있습니다. (2) | 파도 | 2025-05-14 |
2694731 | 리눅스 커널의 시작점 질문 | 미르 | 2025-05-13 |
2694702 | 이거 뭐가문제인가요 코드수정좀 (3) | 맑은 | 2025-05-13 |
2694675 | C언어 후위표기를 중위표기로 | 앨런 | 2025-05-13 |
2694646 | 안녕하세요 파일 합치기 함수! (1) | 연블루 | 2025-05-13 |
2694618 | 잘몰라서 설명부탁드립니다. scanf 관련 (3) | 파라 | 2025-05-12 |
2694590 | 이 코드가 뭐하는 코드일까요? #2 | 빵순 | 2025-05-12 |
2694559 | 동적할당으로 배열(2차원열)을 만드는데 있어 그걸 함수화시키는데... (1) | 늘솔길 | 2025-05-12 |
2694532 | 네트워크에 관하여... (4) | 황소자리 | 2025-05-12 |
2694503 | 프로그램 연산 후 바로 종료되는 현상 (6) | Judicious | 2025-05-11 |
2694450 | while문질문입니다. (1) | 허리품 | 2025-05-11 |
2694420 | C언어 질문할게요(유니코드,자료형,버퍼,캐스트연산자) | 은새 | 2025-05-11 |
2694370 | 내일까진데 함수호출 제발 도와주세요!!!!!!!!!11 | 들찬 | 2025-05-10 |
2694339 | putchar()의 괄호 안에 int c=10;로 전에 선언된 c를 넣으면 안되는 이유에서 제가 생각한 것이 그 이유가 되는지 확인하고 싶습니다. (3) | 미르 | 2025-05-10 |
2694316 | 이 코드 어디가 잘못되었는지 고수분들 ㅠㅠ (2) | 나빛 | 2025-05-10 |
2694285 | 언어 공부하는 과정 좀 추천해주세요! (1) | 아빠몬 | 2025-05-09 |
2694258 | 카운터.. 질문입니다. (4) | 하늘빛눈망울 | 2025-05-09 |
2694229 | 단순한 질문이요 (8) | 여름 | 2025-05-09 |