| |

VerySource

 Forgot password?
 Register
Search
View: 755|Reply: 3

How to display a bitmap by reading a bitmap file? (Not login)

[Copy link]

1

Threads

2

Posts

3.00

Credits

Newbie

Rank: 1

Credits
3.00

 China

Post time: 2020-1-29 13:20:01
| Show all posts |Read mode
let him
Reply

Use magic Report

0

Threads

20

Posts

21.00

Credits

Newbie

Rank: 1

Credits
21.00

 China

Post time: 2020-3-2 04:00:01
| Show all posts
CString StrFilter = "Bitmap files (* .bmp) | * .bmp | All files (*. *) | *. * ||";
CFileDialog Dlg (TRUE, NULL, NULL, NULL, StrFilter, this);
if (! Dlg.DoModal () == IDOK)
return;
CString StrFileName;
StrFileName = Dlg.GetPathName ();
// BITMAPINFO structure pointer
BITMAPINFO * pBmpInfo;
// DIB image data pointer
BYTE * pBmpData;
CFile MyFile;
if (! MyFile.Open (StrFileName, CFile :: modeRead | CFile :: typeBinary))
return;
BITMAPFILEHEADER BmpHeader;
if (MyFile.Read (&BmpHeader, sizeof (BmpHeader))! = sizeof (BmpHeader))
{
AfxMessageBox ("Error reading bitmap file header!");
return;
}
if (BmpHeader.bfType! = 0x4d42)
{
AfxMessageBox ("Not a bitmap file!");
return;
}
BITMAPINFOHEADER BmpInfo;
if (MyFile.Read (&BmpInfo, sizeof (BmpInfo))! = sizeof (BmpInfo))
{
AfxMessageBox ("Error reading bitmap information!");
return;
}
if (BmpInfo.biBitCount! = 24)
{
AfxMessageBox ("Not a true 24-color bitmap, the program does not support it for now!");
return;
}
pBmpInfo = (BITMAPINFO *) new char [sizeof (BITMAPINFOHEADER)];
if (! pBmpInfo)
{
AfxMessageBox ("Memory allocation error!");
return;
}
memcpy (pBmpInfo,&BmpInfo, sizeof (BITMAPINFOHEADER));
DWORD dataBytes = BmpHeader.bfSize-BmpHeader.bfOffBits;
pBmpData = (BYTE *) new char [dataBytes];
if (! pBmpData)
{
AfxMessageBox ("Memory allocation error!");
delete pBmpInfo;
return;
}
if (MyFile.Read (pBmpData, dataBytes)! = dataBytes)
{
AfxMessageBox ("Error reading bitmap data!");
delete pBmpInfo;
delete pBmpData;
return;
}
MyFile.Close ();
CClientDC * pDC = new CClientDC (this);
pDC-> SetStretchBltMode (COLORONCOLOR);
StretchDIBits (pDC-> GetSafeHdc (), 0,0, BmpInfo.biWidth, BmpInfo.biHeight, 0,0,
BmpInfo.biWidth, BmpInfo.biHeight,
        pBmpData, pBmpInfo, DIB_RGB_COLORS, SRCCOPY);
Reply

Use magic Report

0

Threads

12

Posts

10.00

Credits

Newbie

Rank: 1

Credits
10.00

 United States

Post time: 2020-3-2 10:15:01
| Show all posts
Load-> bitblt to the specified location
Reply

Use magic Report

1

Threads

2

Posts

3.00

Credits

Newbie

Rank: 1

Credits
3.00

 China

 Author| Post time: 2020-3-2 13:00:02
| Show all posts
Thank you
Reply

Use magic Report

You have to log in before you can reply Login | Register

Points Rules

Contact us|Archive|Mobile|CopyRight © 2008-2023|verysource.com ( 京ICP备17048824号-1 )

Quick Reply To Top Return to the list