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 파일을 첨부해주세요
번호 | 제 목 | 글쓴이 | 날짜 |
---|---|---|---|
2698994 | 날짜 계산하는 C 코드 짜고 있는데 꽉 막혀서 질문드립니다.. (6) | 별 | 2025-06-22 |
2698967 | 파일삭제 윈도우 폴더까지 접근하게하는 함수가 뭔가요 (2) | 샤인 | 2025-06-21 |
2698938 | c언어 메모리질문 (3) | 나래 | 2025-06-21 |
2698909 | 서비스 요청 고객 관리 프로그램 짜는것좀 도와주세요ㅜㅜ (4) | 궁수자리 | 2025-06-21 |
2698882 | 프로그래밍좀 짜주세요 (3) | 황예 | 2025-06-21 |
2698855 | 카프-라빈 알고리즘 코딩 분석좀 도와주세요.. | 꽃봄 | 2025-06-20 |
2698829 | 학점계산기 (7) | MyWay | 2025-06-20 |
2698782 | 기초적인 함수 질문이요ㅠㅠㅠㅠ | 내담 | 2025-06-20 |
2698749 | 프로그램 짜던 도중 패닉입니다...ㅜ | 파랑 | 2025-06-19 |
2698719 | 조건부컴파일 질문입니다.~ (2) | 큐트 | 2025-06-19 |
2698693 | 재귀 함수 에러 | 바닐라 | 2025-06-19 |
2698673 | 고민이있는데 들어좀주세요!! (1) | 초코맛캔디 | 2025-06-19 |
2698644 | 1부터 n까지의 합을 구하는데 엄청긴숫자의 합을 구할때는 어떻게 해야하나요? (4) | 슬우 | 2025-06-18 |
2698616 | 다른 함수로 안넘어갑니다..;;; | 도1도캣 | 2025-06-18 |
2698587 | 배열하다 막혀서... (3) | WhiteCat | 2025-06-18 |
2698559 | 문자열을 비우는방법 (2) | 하늘 | 2025-06-18 |
2698528 | 착하고 친절한 선생씌구해염~ㅋㅋ (4) | 옆집언니야 | 2025-06-17 |
2698502 | 자료구조 큐 | 캔서 | 2025-06-17 |
2698477 | 실행화면 배경문의요 | 선아 | 2025-06-17 |
2698430 | 변수의 값이 저장이 않되네요;; (4) | 피네 | 2025-06-16 |