Wrox Programmer Forums
Go Back   Wrox Programmer Forums > C# and C > C++ and Visual C++ > C++ Programming
|
C++ Programming General discussions for the C++ language. For questions specific to Microsoft's Visual C++ variant, see the Visual C++ forum instead.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the C++ Programming section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
  #1 (permalink)  
Old March 13th, 2006, 02:29 PM
Registered User
 
Join Date: Mar 2006
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to chrispbrown2255
Default hex conversion to binary files

Hi all,
  I'm working on a project that requires me to produce .bmp files from data that produced by another program that I'm working on. The other program is working fine.

I have hex values defined as shown

bfType1 = 0x42; // char
bfType2 = 0x4D; // char
bfSize = 0x00000000; //long
bfReserved1 = 0x0000; //short
bfReserved2 = 0x0000; //short
bfOffBits = 0x36; //long
biSize = 0x28; //long
biWidth = 0x0000000A; //long
biHeight = 0x0000000A; //long
biPlanes = 0x0001; //short
biBitCount = 0x0018; //short
biCompression = 0x00000000; //long
biSizeImage = 0x00000000; //long
biXPelsPerMeter = 0x00000000; //long
biYPelsPerMeter = 0x00000000; //long
biClrUsed = 0x00000000; //long
biClrImportant = 0x00000000; //long


I'm trying to write these to a file and the output is wrong. The first two char's are fine. My output code is


ofstream fout("helloworld.bmp",ios::binary);

    fout << bfType1 << bfType2 << bfSize << bfReserved1 << bfReserved2 << bfOffBits << bfSize
        << biWidth << biHeight << biPlanes << biBitCount << biCompression << biSizeImage
        << biXPelsPerMeter << biYPelsPerMeter << biClrUsed << biClrImportant ;


and the actual output I am getting (in ascii) is

BM0005401010124000000

Any auggestions? My source for the header info is from a Delphi mnaual, which doesn't look like (to someone who's never touched delphi and is new to c++) it has to use any modifiers to convert from hex into binary.

Reply With Quote
  #2 (permalink)  
Old March 15th, 2006, 06:06 PM
Registered User
 
Join Date: Mar 2006
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to chrispbrown2255
Default

I've found a way round what I wanted to do.
I've created a valid bmp header in a graphics program, and ow I just copy that header to a new file and append my data to the end.
I'v limited myself to all combinations of 3 intensities, so that gives me 27 colours, which I just write in ascii, ie if I want a nice royal blue, which is hex code 0x21217E I actually write "~!!" (bmps read as BGR) to the file.

Reply With Quote





Similar Threads
Thread Thread Starter Forum Replies Last Post
2's Complement binary to decimal conversion gbilios C++ Programming 7 February 25th, 2013 09:46 AM
string to binary conversion in XSLT navi25584 XSLT 5 September 3rd, 2008 03:14 AM
VB 2005 question, binary to text file conversion pitcher General .NET 0 September 24th, 2007 07:45 PM
PROGRAM FOR DECIMAL TO BINARY CONVERSION bharathidhas C# 1 December 13th, 2006 02:53 AM
convert otb files to hex string ela Classic ASP Professional 1 October 14th, 2004 01:20 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.