Lecture bmp of C language

  • 3,232 views
Uploaded on

BMP lecture of C language

BMP lecture of C language

  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Be the first to comment
    Be the first to like this
No Downloads

Views

Total Views
3,232
On Slideshare
0
From Embeds
0
Number of Embeds
1

Actions

Shares
Downloads
35
Comments
0
Likes
0

Embeds 0

No embeds

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
    No notes for slide

Transcript

  • 1. Bitmap Image.
    Embedded System Engineering
  • 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
  • 5. Bitmap Image : Image Data
  • 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
  • 8. Bitmap : Practice #1
    Inverting
    Hint :: Each pixel data(R,G,B) ^ 0xff
  • 9. Bitmap : Practice #2
    Sepia effect
    Hint :: Red * 0.299, Green * 0.587, Blue * 0.114
  • 10. Bitmap : Practice #3
    Draw the flag of NETHERLAND
    Size : 600 x 300
  • 11. Bitmap : Practice #4
    Draw the flag of FRANCE
    Size : 600 x 300
  • 12. Bitmap : Practice #5
    In this square, there are some black pixels, how many pixels are there?
    And, where is location of pixels?
  • 13. Bitmap : Practice #6
    Rotation