와우 왜 안되는걸까요...
한추렴
질문 제목 : 비트맵 픽셀에서 파란색 없애기왜 성공은 뜨고 안돼는걸까요 질문 내용 :
//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비트 이미지일 것이라고 가정하지 마세요.
그리고 안 되면, 이런 오류메시지가 뜨더라, 어떠한 결과를 예상하는데 이러한 결과가 나오더라 같이 상태를 자세하게 설명하세요.
번호 | 제 목 | 글쓴이 | 날짜 |
---|---|---|---|
2700400 | 원넓이를 계산이요 ㅜㅜ | 천칭자리 | 2025-07-04 |
2700368 | if에 관해서 질문이요... | Orange | 2025-07-04 |
2700339 | 이거 결과값이 왜이런건지.. (4) | 그댸와나 | 2025-07-04 |
2700313 | 파일 읽어서 저장하는데 빈파일일 경우 문재가 발생하네요.. (2) | 크나 | 2025-07-03 |
2700287 | 구조체 동적할당 연습을 하는데 오류가 뜹니다...(해결) (3) | 아련나래 | 2025-07-03 |
2700264 | 문자와 숫자 동시에 입력??? | 글고운 | 2025-07-03 |
2700236 | txt파일로만 쓰고 읽게 하려면 어떻게 해야 하나요..?? (8) | 미국녀 | 2025-07-03 |
2700211 | 전위 연산자 (2) | 어른처럼 | 2025-07-02 |
2700183 | C에서 파일이름을 받고, 그 파일의 사이즈를 출력해줘야하는데 내용이 출력이 안되네요 ;ㅅ; | 피스케스 | 2025-07-02 |
2700150 | 꼭좀 도와주세요ㅠㅠㅠ | 호습다 | 2025-07-02 |
2700095 | 연산문제...질문... | 오빤테앵겨 | 2025-07-01 |
2700070 | while문 , 3의배수 출력하는 프로그램좀 짜주세욤. | 횃불 | 2025-07-01 |
2700041 | 초보인데요 ㅎ 배열안에 배열을 집어넣을수 있나요?? | 헛장사 | 2025-07-01 |
2700012 | 배열// (1) | 전갈자리 | 2025-07-01 |
2699895 | 무한루프에 빠집니다.!! 해결좀부탁드려요 (10) | 선아 | 2025-06-30 |
2699842 | 질문을 너무 많이 하네여.....죄송.... (2) | 해님꽃 | 2025-06-29 |
2699816 | 오류 질문입니다.. (1) | 해비치 | 2025-06-29 |
2699763 | 질문입니다 ! 꼭 좀 도와주세요ㅠㅠ (2) | 미라 | 2025-06-28 |
2699555 | c언어 다항식을 입력을 했는데 왜 출력이 안될까요? | 피스케스 | 2025-06-27 |
2699528 | C언어 포인터연산 질문입니다. (3) | 안녕나야 | 2025-06-26 |