Board index » cppbuilder » Save a .bmp into .pcx file

Save a .bmp into .pcx file


2005-01-12 04:52:28 AM
cppbuilder60
Hi,
Does anybody know how to save an image into a .pcx file instead of .bmp?
 
 

Re:Save a .bmp into .pcx file

The VCL way to do it is to derive a class from TGraphic that handles the PCX
file format. I found this code on the Internet:
howtodothings.com/showarticle.asp
It appears that this class stores the image internally in a bitmap,
hopefully that won't be an issue for you. However, there were a few
problems with it that I had to fix in order for it to compile. Assuming you
all the code and place it into a unit named "pcximage.pas" here are the
changes I made by line number:
Line 142:
TPCXData = class // rather than Object
Line 959:
fPCXData := TPCXData.Create;
Line 966:
fPCXData.Free;
Some fixes to be able to make it work with TImage correctly:
Line 344:
Result := fBitmap.Height;
Line 350:
Result := fBitmap.Width;
Line 508 (I replaced the entire Assign procedure with the following):
Procedure TPCXImage.Assign(Source : TPersistent);
Var
iX,iY : Integer;
Begin
If (Source is TBitmap) then
Begin
fBitmap.Assign(Source as TBitmap);
End
else
if (Source is TPCXImage) then
Begin
fBitmap.Assign((Source as TPCXImage).fBitmap);
End
else
If (Source is TPicture) then
Begin
iX := (Source as TPicture).Width;
iY := (Source as TPicture).Height;
fBitmap.Width := iX;
fBitmap.Height := iY;
fBitmap.Canvas.Draw(0,0,(Source as TPicture).Graphic);
End
//else
// You can write other assignments here...
else
Raise Exception.Create(ASSIGN_ERROR);
End;
Now, once you've compiled the PAS file (and included the HPP that gets
generated) you can work with PCX files. A simple example to convert a BMP
to PCX is:
Graphics::TBitmap* bmp; // created and populated somewhere else
TPCXImage* pcx = new TPCXImage;
pcx->Assign(bmp);
pcx->SaveToFile(fileName); // PCX file now created
- Clayton
 

Re:Save a .bmp into .pcx file

Sorry, I messed up my line numbering that I posted. And, since I am using
the line numbers after all changes have been made you need to make those
changes in order of smallest line number to largest line number. Here are
the changes in that order:
Line 142:
TPCXData = class // rather than Object
Line 344:
Result := fBitmap.Height;
Line 350:
Result := fBitmap.Width;
Line 508 (I replaced the entire Assign procedure with the following):
Procedure TPCXImage.Assign(Source : TPersistent);
Var
iX,iY : Integer;
Begin
If (Source is TBitmap) then
Begin
fBitmap.Assign(Source as TBitmap);
End
else
if (Source is TPCXImage) then
Begin
fBitmap.Assign((Source as TPCXImage).fBitmap);
End
else
If (Source is TPicture) then
Begin
iX := (Source as TPicture).Width;
iY := (Source as TPicture).Height;
fBitmap.Width := iX;
fBitmap.Height := iY;
fBitmap.Canvas.Draw(0,0,(Source as TPicture).Graphic);
End
//else
// You can write other assignments here...
else
Raise Exception.Create(ASSIGN_ERROR);
End;
Line 956:
fPCXData := TPCXData.Create;
Line 963:
fPCXData.Free;
If after you've made the changes the code won't compile or execute correctly
let me know and I will email you the PAS that I created.
- Clayton
 

{smallsort}

Re:Save a .bmp into .pcx file

Thanks Clayton,
By any chance do you have that code in C++, or do you know where to find
it? I looked at the link you sent me but I couldn't find a C++ version.
 

Re:Save a .bmp into .pcx file

In my haste to post I forgot that I added three lines of test code which
affected all of my line numbers above and including 344. All line numbers,
except 142, should be three less, so 344 should be 341, etc.
Again, sorry for the confusion.
 

Re:Save a .bmp into .pcx file

I didn't see this particular code in C++ but it is rather trivial to convert
(just time consuming). Since my other post was errored I have emailed you
the PAS file as edited by me. I may eventually convert this code to C++ if
I have a spare couple of hours (though that time seems hard to come by).
- Clayton
 

Re:Save a .bmp into .pcx file

Thanks Clayton
Clayton Arends wrote:
Quote
I didn't see this particular code in C++ but it is rather trivial to convert
(just time consuming). Since my other post was errored I have emailed you
the PAS file as edited by me. I may eventually convert this code to C++ if
I have a spare couple of hours (though that time seems hard to come by).

- Clayton