|
-
May 28th, 2017, 01:57 PM
#7
New Member
Re: C/C++ - Loading Bitmap Files (Manually)
i were working with your code, plus win32 system calls plus winbgim win api, this code also works, so:
#include <winbgim.h>
#include <string.h>
#include<iostream>
#include<windows.h>
#include<stdio.h>
#include <stdlib.h>
#include <fstream.h>
const char *Filename;
WORD bibitcount;
BITMAPFILEHEADER FileHeader;
BITMAPINFOHEADER InfoHeader;
int k;
typedef struct{
BYTE colorr;
BYTE colorg;
BYTE colorb;
}cine;
cine color;
HANDLE hArch, hProy;
LPSTR base,puntero;
DWORD tam;
int main()
{
char *p;
char *base;
DWORD buf;
Filename="C:\\path to file\\mybmp.BMP";
int gd = DETECT, gm;
int x = 320, y = 240, radius;
k=0;
initgraph(&gd, &gm, "C:\\path to BGI folder\\BGI");//download TC 3.0 for dos
int i;
int j;
char g[20];
FILE *File=NULL;
if(!Filename)
{
MessageBox(NULL,"Konnte Filename nicht finden!","Error",MB_OK|MB_ICONERROR);
}
else
{
File=fopen("C:\\path to my file\\mybmp.BMP","rb");
}
if(FileHeader.bfType != 0x4D42)
{
MessageBox(NULL,"Ungültiges Bildformat!","Error",MB_OK|MB_ICONERROR);
exit(1);
}
fread(&FileHeader,sizeof(BITMAPFILEHEADER),1,File);
printf("tamaño total del archivo %d\n",FileHeader.bfSize);
printf("comienzo del mapa de bits (imagen en pixels) en bits %d\n",FileHeader.bfOffBits);
buf=FileHeader.bfOffBits/8; //offset from the begining of BMP file (pixel array)
printf("comienzo del mapa de bits en bytes desde el origen del archivo %d\n",buf);
fread(&InfoHeader,sizeof(BITMAPINFOHEADER),1,File);
printf("horizontal resolution in pixels por metro %li\n",InfoHeader.biWidth);
printf("vertical resolution in pixels por metro %li\n",InfoHeader.biHeight);
printf("numero de bits por pixel %d", InfoHeader.biBitCount);
fclose(File);
hArch = CreateFile("bar.bmp", /* file name */
GENERIC_ALL , /* read/write access */
0, /* no sharing of the file */
NULL, /* default security */
OPEN_ALWAYS, /* open new or existing file */
FILE_ATTRIBUTE_NORMAL, /* routine file attributes */
NULL); /* no file template */
if (hArch==INVALID_HANDLE_VALUE){
fprintf(stderr,"no puede abrirse el archivo");
}
hProy = CreateFileMapping(hArch, /* file handle */
NULL, /* default security */
PAGE_READWRITE, /* read/write access to mapped pages */
0, /* map entire file */
0,
TEXT("SharedObject")); /* named shared memory object */
/* write to shared memory */
base=(LPSTR)MapViewOfFile(hProy,FILE_MAP_ALL_ACCESS,0,0,0);
tam=GetFileSize(hArch,NULL);
int cont=0;
puntero=base;
p=base+buf;
k=0;
for (i=0;i<InfoHeader.biHeight;i++)
for(j=0;j<InfoHeader.biWidth;j++)
{
putpixel(j+6,InfoHeader.biHeight-i,COLOR(int(*(p+k)),int(*(p+k+2)),int(*(p+k+1))));
k=k+3;
}
getch();
}
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|