BorlandTalk.com Forum Index BorlandTalk.com
Borland discussion newsgroups
 
Archives   FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Save a .bmp into .pcx file

 
Post new topic   Reply to topic    BorlandTalk.com Forum Index -> C++ Builder (Graphics)
View previous topic :: View next topic  
Author Message
Julian
Guest





PostPosted: Tue Jan 11, 2005 8:52 pm    Post subject: Save a .bmp into .pcx file Reply with quote



Hi,
Does anybody know how to save an image into a .pcx file instead of .bmp?
Back to top
Clayton Arends
Guest





PostPosted: Wed Jan 12, 2005 6:46 pm    Post subject: Re: Save a .bmp into .pcx file Reply with quote



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:

http://howtodothings.com/showarticle.asp?article=236

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


Back to top
Clayton Arends
Guest





PostPosted: Wed Jan 12, 2005 6:52 pm    Post subject: Re: Save a .bmp into .pcx file Reply with quote



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


Back to top
Julian
Guest





PostPosted: Wed Jan 12, 2005 9:26 pm    Post subject: Re: Save a .bmp into .pcx file Reply with quote

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.
Back to top
Clayton Arends
Guest





PostPosted: Thu Jan 13, 2005 5:48 am    Post subject: Re: Save a .bmp into .pcx file Reply with quote

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.


Back to top
Clayton Arends
Guest





PostPosted: Thu Jan 13, 2005 5:53 am    Post subject: Re: Save a .bmp into .pcx file Reply with 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


Back to top
Julian
Guest





PostPosted: Fri Jan 14, 2005 11:34 pm    Post subject: Re: Save a .bmp into .pcx file Reply with quote

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



Back to top
Display posts from previous:   
Post new topic   Reply to topic    BorlandTalk.com Forum Index -> C++ Builder (Graphics) All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2006 phpBB Group
SEO toolkit © 2004-2006 webmedic.