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