Home > Back-end >  How to modify the TBitmap this class? I'm dizzy!!!!!
How to modify the TBitmap this class? I'm dizzy!!!!!

Time:09-23

Have a project, need the server to get a series of TBitmap SaveToStream way write a continuous flow, and the client then read one by one from a flow inside with loadfromstream independent TBitmap, but found in actual operation, the TBitmap loadfromstream this method, is a sigh to read to the end, that is to say, want to use this method, I need to create a temporary stream, read a piece of data out of it, and then to TBitmap loadfromstream, for example, is as follows:

Server:
BMP: TBitmap;
BMP. Savetostream (stream);
//...
//... Among multiple bitmap into the flow, of course, there will be some segmentation mark

Client:
BMP: TBitmap
TMP: TMemoryStream;//define a temporary flow
TMP. Copyfrom (stream, 10000);//with a temporary flow read a piece of data
BMP. Loadfromstream (TMP);//BMP loaded from the temporary flow

Among the above code, had to borrow a temporary flow, seem to be very tedious, because TBitmap loadfromstream this method, all incredibly don't support the size, check the source code, is a private method TBitmap loadfromstream call Readstream:
Procedure TBitmap. LoadFromStream (Stream: TStream);
The begin
ReadStream (Stream, Stream. Size - Stream. The Position ).
end;
Is too wicked, incredibly ReadStream is to support the size, the results here write the size parameters of the die into a rest all contents of the stream!!

So I'm going to modify TBitmap this class, the idea is simple, add a LoadFromStream2 method, increase a size parameter can be:
Procedure TBitmap. LoadFromStream2 (Stream: TStream ; ASize: integer );
The begin
ReadStream (Stream, ASize ).
end;

But it is not so easy as I think, Tbitmap is a class, so the bottom was the VCL based class, one of the most important social phenomena, all of the system unit involves the bitmap to recompile, other ok, jpeg unit no source code, can't compile, and engineering and need jpeg this unit, I finally had to give up this way,

And he wants from TBitmap inherit a class, realize my LoadFromStream2 method, but after trying to just discover, TBitmap readfrom unexpectedly is a private method, subclasses can't access!!!!!!

So here's the thing: I just want to on the basis of the TBitmap, realize LoadFromStream with size parameters, what should I do? Help you master the ~ ~ ~

CodePudding user response:

This way, say first, what version of what's in the development environment of software, such as Delphi, Win32 or XE5, Win32, Win64 this

CodePudding user response:

Direct use of binary, transfer image data,

CodePudding user response:

Cover the GetSize Stream

CodePudding user response:

reference 1st floor kiboisme response:
this way, first, what version of what's in the development environment of software, such as Delphi, Win32 or XE5, Win32, Win64 such


Delphi 6.0, winxp

CodePudding user response:

refer to the second floor lyhoo163 response:
directly using binary, transfer image data,


This I'd like to have, for example by scanline direct hand in the past, the memory data copy out again after receiving copymemory to the target image memory area, but I haven't tested, this kind of treatment, whether than bitmap savetopstream and loadfromstream low efficiency? Because I am the requirements on speed is higher,

CodePudding user response:

reference s11ss reply: 3/f
covered Stream of GetSize


Specific how to do? Stream is a class, so the bottom will inherit tbitmap old problems again, single point?

CodePudding user response:

TMP. Copyfrom (stream, 10000);//with a temporary flow read a piece of data
The stream here is what kind of change to the class or out of his inheritance

CodePudding user response:

refer to 7th floor s11ss response:
TMP. The copyfrom (stream, 10000);//with a temporary flow read a piece of data
The stream here is what kind of change to this class or from his inheritance


Flow, also at the bottom of the enough, and they were afraid to is extremely important

CodePudding user response:

The D6,
Procedure TBitmap. ReadData (Stream: TStream); The code behind the couch, I there is no D6, D7 only

CodePudding user response:


See with what version, the high version of the patch can use class
To gm, is himself in his own unit head TBitmap to inherit a, such as
TBitmap=class (Graphics. TBitmap)
//way to increase your
//or reload your virtual method
end;
So the Bitmap can only in your quote you the unit

CodePudding user response:

First of all, have to say, not your so-called "immoral, incredibly ReadStream is to support the size of, the results here write the size parameter dead to rest all contents of the stream",
ReadStream parameters that size just to avoid crossing the line into a restriction, specific how to read you are going to see a ReadDIB methods:
//biSizeImage can be zero. If a zero, compute the size.
If biSizeImage=0 then//top - down DIBs have negative height
BiSizeImage:=BytesPerScanLine (biWidth, biBitCount, 32) * Abs (biHeight);

If biSizeImage & lt; ImageSize then ImageSize:=biSizeImage;
Saw it, it is according to read the size of the bitmap image data of the head (if 0 is calculated on the basis of their specific to determine the size of the bitmap, no one read it in the end,

Second, you can write a simple small program verify:
To set up more than a bitmap file:
Copy/b 1. BMP + 2. BMP f.b in
And then:
Var
F: TFileStream;
B1, b2: TBitmap;
//...
F:=TFileStream. Create (' f.b in 'fmOpenRead);
B1:=TBitmap. Create;
B2:=TBitmap. Create;
B1. LoadFromStream (f);
B2. LoadFromStream (f);
B1. SaveToFile (' b1. BMP);
B2. SaveToFile (' b2. BMP);
F.F ree;
B1. Free;
B2. Free;
You look at the picked two bitmap is not correct,

CodePudding user response:

11 references DelphiGuy response:
first of all, have to say, not your so-called "immoral, incredibly ReadStream is to support the size of, the results here write the size parameter dead to rest all contents of the stream",
ReadStream parameters that size just to avoid crossing the line into a restriction, specific how to read you are going to see a ReadDIB methods:
//biSizeImage can be zero. If a zero, compute the size.
If biSizeImage=0 then//top - down DIBs have negative height
BiSizeImage:=BytesPerScanLine (biWidth, biBitCount, 32) * Abs (biHeight);

If biSizeImage & lt; ImageSize then ImageSize:=biSizeImage;
Saw it, it is according to read the size of the bitmap image data of the head (if 0 is calculated on the basis of their specific to determine the size of the bitmap, no one read it in the end,

Second, you can write a simple small program verify:
To set up more than a bitmap file:
Copy/b 1. BMP + 2. BMP f.b in
And then:
Var
F: TFileStream;
nullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnull
  • Related