와우 왜 안되는걸까요...
한추렴
질문 제목 : 비트맵 픽셀에서 파란색 없애기왜 성공은 뜨고 안돼는걸까요 질문 내용 :
//this program will read a bmp image file
//and change the blue component of each pixel in that
//file to zeor value
//and produce the changed bitmap into a new file
//input:a bmp image file
//output: a new bmp file with blue componenet set to zero
#include stdio.h
#include malloc.h
int main()
{
char firstcharacter,secondcharacter;
int filesize;
int reserved;
int data_offset;
int size;
int width;
int height;
short planes;
short bit_count;
int compression;
int image_size;
int x_pixels_per_m;
int y_pixels_per_m;
int colors_used;
int colors_important;
//first read a bitmap file
file*fp = fopen(d:\\펭귄.bmp,rb); //file open
fread(&firstcharacter,sizeof(char),1,fp);
fread(&secondcharacter,sizeof(char),1,fp);
fread(&filesize,sizeof(int),1,fp);
fread(&reserved,sizeof(int),1,fp);
fread(&data_offset,sizeof(int),1,fp);
fread(&size,sizeof(int),1,fp);
fread(&width,sizeof(int),1,fp);
fread(&height,sizeof(int),1,fp);
fread(&planes,sizeof(short),1,fp);
fread(&bit_count,sizeof(short),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(file size is %d byte \n, filesize);
printf(reserved is %d \n, reserved);
printf(data_offset is %d \n, data_offset);
printf(size is %d \n, size);
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);
*/
//bmp header information completely read
//now read the pixel information
//first prepare memory for the pixel data
//with image_size
char * image_data = (char*)malloc(image_size);
fread(image_data,image_size,1,fp);
fclose(fp);
int i,j;
unsigned int padding;
padding = 4 - (3*width) % 4;
//change tje blue part of each pixel to zero
for(i=0 ; iheight ; i++)
for(j=0 ; jwidth ; j++)
{
image_data[i*(width*3+padding) + j*3] = 0;
}
file * wp;
wp = fopen(d:\\newfile.bmp,wb);
fwrite(&firstcharacter,sizeof(char),1,wp);
fwrite(&secondcharacter,sizeof(char),1,wp);
fwrite(&filesize,sizeof(int),1,wp);
fwrite(&reserved,sizeof(int),1,wp);
fwrite(&data_offset,sizeof(int),1,wp);
fwrite(&size,sizeof(int),1,fp);
fwrite(&width,sizeof(int),1,wp);
fwrite(&height,sizeof(int),1,wp);
fwrite(&planes,sizeof(short),1,wp);
fwrite(&bit_count,sizeof(short),1,wp);
fwrite(&compression,sizeof(int),1,wp);
fwrite(&image_size,sizeof(int),1,wp);
fwrite(&x_pixels_per_m,sizeof(int),1,wp);
fwrite(&y_pixels_per_m,sizeof(int),1,wp);
fwrite(&colors_used,sizeof(int),1,wp);
fwrite(&colors_important,sizeof(int),1,wp);
// write header information as same as you read
// now write the image pixel data which is changed one
fwrite(image_data,imageta,image_size,1,wp);
free(image_data);
fclose(wp);
}
-
볼1매그녀 2025-01-25
여전히 * 3을 하는군요.
24비트 이미지일 것이라고 가정하지 마세요.
그리고 안 되면, 이런 오류메시지가 뜨더라, 어떠한 결과를 예상하는데 이러한 결과가 나오더라 같이 상태를 자세하게 설명하세요.
번호 | 제 목 | 글쓴이 | 날짜 |
---|---|---|---|
2693956 | PlaySound재생이 안됩니다!(C에 음악넣기) | 지존 | 2025-05-06 |
2693928 | &와 *의 사용에 관한 명확한 이해 | 제나 | 2025-05-06 |
2693903 | 반복문 설명좀요 ㅠㅠ (2) | 란새 | 2025-05-06 |
2693869 | stdio.h 는 왜 쓰는건가요? (1) | 큰꽃들 | 2025-05-06 |
2693842 | 포인터 변수의 주소값끼리 더하는 것에 대해서 질문드립니다. (1) | 진솔 | 2025-05-05 |
2693811 | 소수 출력;;;; | 화이트캣 | 2025-05-05 |
2693788 | 이런 함수는 없나요? (3) | 앤드류 | 2025-05-05 |
2693758 | txt파일 불러와서 행렬로 저장 | 큰애 | 2025-05-05 |
2693727 | scanf 오류 문제!! (2) | 큰나래 | 2025-05-04 |
2693704 | 구조체 주소록 문제인데 도와주세요 (2) | 도1도캣 | 2025-05-04 |
2693676 | 열혈강의 c언어 질문입니다 | 하양이 | 2025-05-04 |
2693647 | 12.620000 을요 12.620 으로 어떻게 표현해요? (2) | 파도 | 2025-05-04 |
2693619 | 타이틀 코드.. | 단순드립 | 2025-05-03 |
2693591 | 컴파일 에러에서 질문드립니다 (3) | 게자리 | 2025-05-03 |
2693463 | 동적할당 이용시 fwrite사용을 어떻게 해야하나요..? (10) | 일본어못해요 | 2025-05-02 |
2693387 | 배열문제입니다 수정오류캡쳐했습니다 (6) | 연하얀 | 2025-05-01 |
2693356 | text 입출력 내림차순 질문입니다 ㅠ | 빛글 | 2025-05-01 |
2693328 | C언어를이용해서 .txt파일 외에 다른 확장자 파일 삭제가 가능한지.. (2) | 대나무 | 2025-05-01 |
2693299 | 파일입출력 바이너리파일 | 독특한 | 2025-04-30 |
2693273 | 오류 (1) | 귀1여운렩 | 2025-04-30 |