Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

Lecture bmp of C language

4,461 views

Published on

BMP lecture of C language

  • Be the first to comment

  • Be the first to like this

Lecture bmp of C language

  1. 1. Bitmap Image.<br />Embedded System Engineering<br />
  2. 2. Bitmap Image : Bitmap Structure<br />File Header<br />BITMAPFILEHEADER<br />Info Header<br />BITMAPINFOHEADER<br />Opt. Palette<br />RGBQUAD[n]<br />Image Data<br />RGBTRIPLE[m]<br />
  3. 3. Bitmap Image : File Header<br />File Header<br />14<br />Info Header<br />40<br />Opt. Palette<br />4n<br />Image Data<br />3m<br />BM<br />RESERVED<br />
  4. 4. Bitmap Image : Info Header<br />File Header<br />Info Header<br />40<br />Opt. Palette<br />Height<br />Image Data<br />Width<br />
  5. 5. Bitmap Image : Image Data<br />
  6. 6. Bitmap : Bitmap - Reading<br />#include <windows.h><br />FILE*fp;<br />BITMAPFILEHEADERbh;<br />BITMAPINFOHEADERih;<br />RGBTRIPLE pixel;<br />inti= 0;<br />if(!(fp = fopen("lena.bmp", "rb"))) return 0;<br />fread(&bh, sizeof(BITMAPFILEHEADER), 1, fp);<br />fread(&ih, sizeof(BITMAPINFOHEADER), 1, fp);<br />while(fread(&pixel, sizeof(RGBTRIPLE), 1, fp))<br />{<br />printf("pixel #%5d: %02x %02x %02x ", i++, pixel.rgbtBlue, pixel.rgbtGreen, pixel.rgbtRed);<br />}<br />printf("%d pixels read. ", i);<br />File Header<br />Info Header<br />Image Data<br />Starting point!<br />
  7. 7. Bitmap : Bitmap – Writing<br />FILE *fp;<br />BITMAPFILEHEADERbh;<br />BITMAPINFOHEADERih;<br />char pixel[60*30*3];<br />inti;<br />for( i = 0 ; i < 60 * 30 * 3 ; i+=3 )<br />{<br />// blue<br /> pixel[i] = 0xff;<br /> // green<br />pixel[i+1] = 0x00;<br />// red<br />pixel[i+2] = 0x00;<br />}<br />ih.biSize= sizeof(BITMAPINFOHEADER);<br />ih.biWidth= 60;<br />ih.biHeight = 30;<br />ih.biPlanes= 1;<br />ih.biBitCount= 24;<br />ih.biCompression= 0;<br />ih.biSizeImage= sizeof(pixel);<br />ih.biXPelsPerMeter= ih.biYPelsPerMeter = 0;<br />ih.biClrImportant= ih.biClrUsed = 0;<br />bh.bfType= 0x4d42;<br />bh.bfSize= sizeof(BITMAPFILEHEADER) + sizeof(BITMAPINFOHEADER) + sizeof(pixel);<br />bh.bfOffBits= sizeof(BITMAPFILEHEADER) + sizeof(BITMAPINFOHEADER);<br />if(!(fp = fopen("blue.bmp", "wb"))) return 0;<br />fwrite(&bh, sizeof(BITMAPFILEHEADER), 1, fp);<br />fwrite(&ih, sizeof(BITMAPINFOHEADER), 1, fp);<br />fwrite(&pixel, sizeof(pixel), 1, fp);<br />File Header<br />Info Header<br />Image Data<br />30<br />60<br />
  8. 8. Bitmap : Practice #1<br />Inverting<br />Hint :: Each pixel data(R,G,B) ^ 0xff<br />
  9. 9. Bitmap : Practice #2<br />Sepia effect<br />Hint :: Red * 0.299, Green * 0.587, Blue * 0.114<br />
  10. 10. Bitmap : Practice #3<br />Draw the flag of NETHERLAND<br />Size : 600 x 300<br />
  11. 11. Bitmap : Practice #4<br />Draw the flag of FRANCE<br />Size : 600 x 300<br />
  12. 12. Bitmap : Practice #5<br />In this square, there are some black pixels, how many pixels are there?<br />And, where is location of pixels?<br />
  13. 13. Bitmap : Practice #6<br />Rotation<br />

×