zoukankan      html  css  js  c++  java
  • c/c++ 图像RGB位存储,位操作

    直接上代码:

     1 #include <string.h>
     2 #include <stdio.h>
     3 #include <math.h>
     4 
     5 
     6 typedef unsigned short    UINT16;    //store pixel rgb data
     7 typedef unsigned char    BYTE;    //store r\g\b data
     8 
     9 
    10 
    11 void main(){
    12     UINT16    pattern[640][480];    //16bit 640*480 rgb image.
    13     BYTE rgb[3];
    14     BYTE r;                        //rgb variable
    15     BYTE g;
    16     BYTE b;
    17 
    18     FILE *fp_read;
    19     fp_read = fopen("pattern_mem.bmp","r");    //open the source bitmap
    20 
    21     if(fp_read == NULL)
    22     {
    23         printf("can't open files!");
    24         return ;
    25     }
    26 
    27     char bmp_head[54];
    28     //读出BMP头,抛弃不要
    29     fread(bmp_head,sizeof(char)*54,1,fp_read);
    30 
    31     for(int i = 0 ; i < 480; i++)
    32         for(int j=0 ; j < 640; j++)
    33         {
    34             fread(rgb, 3, 1, fp_read);        //read rgb data of a pixel
    35             
    36             r = rgb[0];
    37             g = rgb[1];
    38             b = rgb[2];
    39 
    40             pattern[j][i] = ((r&0xf8)<<8)|((g&0xfc)<<3)|((b&0xf8)>>3);
    41         }
    42     fclose(fp_read);
    43     return ;
    44 } 
  • 相关阅读:
    颜色透明度16进制对照表
    爬取代理IP
    Python中匹配IP的正则表达式
    IP地址正则表达式的写法
    每日一练 11.23
    每日一练 11.22
    每日一练
    pycharm使用教程
    周总结博客16
    周总结博客15
  • 原文地址:https://www.cnblogs.com/bubbler/p/2580330.html
Copyright © 2011-2022 走看看