|
New to the CF scene
Join Date: Feb 2012
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
|
I want to make Blue of RGB 0.
I'm a beginner just start to study C language.
I want to make Blue of RGB of an bmp image. Then export the image Blue-0.
You know it doesn't work this way.
I don't know how I debug it.
Help me T_T
######this is my source code######
#include <stdio.h>
#include <malloc.h>
int main()
{
char firstCharacter;
char secondCharacter;
int filesize;
int reserverd;
int data_offset;
int size;
int width;
int planes;
int bit_count;
int compression;
int image_size;
int x_pixels_per_m;
int y_pixels_per_m;
int colors_used;
int colors_important;
FILE * fp = fopen("D:\\flower.bmp","rb");
fread (&firstCharacter,sizeof(char),1,fp);
fread (&secondCharacter,sizeof(char),1,fp);
fread (&filesize,sizeof(int),1,fp);
fread (&reserverd,sizeof(int),1,fp);
fread (&data_offset,sizeof(int),1,fp);
fread (&size,sizeof(int),1,fp);
fread (&width,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 ("filesize is %d \n",filesize);
printf ("reserverd is %d \n",reserverd);
printf ("data_offset is %d \n",data_offset);
printf ("size is %d \n",size);
printf ("width is %d \n",width);
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);
fclose(fp);
char * image_data_size = (char *)malloc ( image_size);
fread (image_data_size, image_size,1,fp);
unsigned int padding;
padding = 8-((width*3)%8);
for (int i = 0; i < width ; i++)
{
for (int j = 0;j <size ; j++)
{
image_data_size [i*(width*3+padding) + j*3] = 0;// B color of first pixel
}
}
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 (&reserverd,sizeof(int),1,wp);
fwrite (&data_offset,sizeof(int),1,wp);
fwrite (&size,sizeof(int),1,wp);
fwrite (&width,sizeof(int),1,wp);
fwrite (&planes,sizeof(int),1,wp);
fwrite (&bit_count,sizeof(int),1,wp);
fwrite (&compression,sizeof(int),1,wp);
fwrite (image_data_size,image_size,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
fclose (wp);
free (image_data_size);
return 0;
}
Last edited by noeloasis; 02-08-2012 at 07:58 AM..
|
|