 |
BorlandTalk.com Borland discussion newsgroups
|
| View previous topic :: View next topic |
| Author |
Message |
Peter C Guest
|
Posted: Sun Oct 08, 2006 5:48 am Post subject: Bitmap from OLEVariant? |
|
|
I have a function that returns a Device Independant Bitmap in an OLEVariant
variable, but I do not know how to use this.
How can I transfer the DIB from the OLEVariant to a TBitmap object or other
graphics object?
I ultimately want to store the graphic in a BLOB field in a JPG format.
Would appreciate any suggestions.
Peter |
|
| Back to top |
|
 |
Peter Below (TeamB) Guest
|
Posted: Sun Oct 08, 2006 2:21 pm Post subject: Re: Bitmap from OLEVariant? |
|
|
Peter C wrote:
| Quote: | I have a function that returns a Device Independant Bitmap in an
OLEVariant variable, but I do not know how to use this.
How can I transfer the DIB from the OLEVariant to a TBitmap object or
other graphics object?
|
That depends completely on what the variant you get actually contains.
If it if a variant array of bytes ((VarType(theVariant) AND
varTypeMask) = varByte) and VarIsArray(theVariant)) it may just contain
the same data you could find in a BMP file. In this case the following
should work (V is the variant):
Var
ms: TMemoryStream;
len, i: Integer;
p: POinter;
Begin
ms: TMemoryStream.Create;
try
len:= VarArrayHighBound( V, 1 ) - VarArrayLowBound(V, 1) + 1;
p:= varArrayLock( V );
try
ms.Writebuffer( p^, len );
finally
varArrayUnlock( V );
end;
ms.Position := 0;
aBitmap.LoadFromStream(ms);
finally
ms.free
end;
If this does not work start by figuring out the actual type of the
variant data, by examining the result of VarType.
--
Peter Below (TeamB)
Don't be a vampire (http://slash7.com/pages/vampires),
use the newsgroup archives :
http://www.tamaracka.com/search.htm
http://groups.google.com
http://www.prolix.be |
|
| Back to top |
|
 |
Peter C Guest
|
Posted: Mon Oct 09, 2006 8:11 am Post subject: Re: Bitmap from OLEVariant? |
|
|
Thanks Peter,
This helped a lot. I had been doing something similiar, but I did not know
I had to lock the array, which made all the difference.
I also had to generate a 14 byte Bitmap File Header and write it too the
stream before I wrote the DIB content.
Everything now seems to be working fine.
Thanks Again,
Peter Collas
"Peter Below (TeamB)" <none> wrote in message
news:xn0es82tl2obzs001 (AT) newsgroups (DOT) borland.com...
| Quote: | Peter C wrote:
I have a function that returns a Device Independant Bitmap in an
OLEVariant variable, but I do not know how to use this.
How can I transfer the DIB from the OLEVariant to a TBitmap object or
other graphics object?
That depends completely on what the variant you get actually contains.
If it if a variant array of bytes ((VarType(theVariant) AND
varTypeMask) = varByte) and VarIsArray(theVariant)) it may just contain
the same data you could find in a BMP file. In this case the following
should work (V is the variant):
Var
ms: TMemoryStream;
len, i: Integer;
p: POinter;
Begin
ms: TMemoryStream.Create;
try
len:= VarArrayHighBound( V, 1 ) - VarArrayLowBound(V, 1) + 1;
p:= varArrayLock( V );
try
ms.Writebuffer( p^, len );
finally
varArrayUnlock( V );
end;
ms.Position := 0;
aBitmap.LoadFromStream(ms);
finally
ms.free
end;
If this does not work start by figuring out the actual type of the
variant data, by examining the result of VarType.
--
Peter Below (TeamB)
Don't be a vampire (http://slash7.com/pages/vampires),
use the newsgroup archives :
http://www.tamaracka.com/search.htm
http://groups.google.com
http://www.prolix.be |
|
|
| Back to top |
|
 |
Warrick Wilson Guest
|
Posted: Wed Oct 11, 2006 9:06 pm Post subject: Re: Bitmap from OLEVariant? |
|
|
"Peter C" <ozcelt (AT) hotmail (DOT) com> wrote in message
news:4529da11 (AT) newsgroups (DOT) borland.com...
| Quote: | Thanks Peter,
This helped a lot. I had been doing something similiar, but I did not
know I had to lock the array, which made all the difference.
I also had to generate a 14 byte Bitmap File Header and write it too the
stream before I wrote the DIB content.
Everything now seems to be working fine.
Thanks Again,
Peter Collas
|
Peter C,
Any chance you could post your updated routine that solves the problem so
that this thread becomes a complete solution? Having that will help the next
guy who comes along with your question.
Thanks...Warrick |
|
| Back to top |
|
 |
Peter C Guest
|
Posted: Sun Oct 15, 2006 8:11 am Post subject: Re: Bitmap from OLEVariant? |
|
|
Here's the basics of my solution. I'm using an OLEControl which returns a
DIB. For anyone interested, the control is called Facesnap which has come
from the C-VIS company in Germany. It's a brilliant little control which
reads graphics from a file or Twain device, identifies faces, and
automatically crops and color balances the image so it can be used in ID
passes. Apologies for the cryptic variable names!
Cheers,
Peter C
type BMPfileheader = record
BMPType : Smallint;
Size : LongInt;
Reserved1 : SmallInt;
Reserved2 : SmallInt;
OhFileBits : LongInt;
end;
Const BMP_LABEL : Integer = 19778;
var
v : OLEVariant;
o : TOleContainer;
m : TMemoryStream;
i,l : Integer;
p : Pointer;
h : bmpfileheader;
j : TJPEGImage;
b : TBitmap;
begin
h.BMPType := BMP_LABEL;
h.OhFileBits := 54; // Accounts for the size of the BMP
Header and the Device Information already in the Bitmap
//........Call Ole Control which returns a Device Independant Bitmap!!!
m:= TMemoryStream.Create;
try
l:= VarArrayHighBound( v, 1 ) - VarArrayLowBound(v, 1) + 1;
h.Size := l + 55; // Sets the total size of the Bitmap
that will be created by Appending the DIB to the BMP Header
p:= varArrayLock( v );
try
m.WriteBuffer( h , 14 ); // Load Header in First
m.Writebuffer( p^, l ); // Load in DIB
finally
varArrayUnlock( v );
end;
m.Position := 0;
b := TBitmap.Create;
j := TJPEGImage.Create;
b.LoadFromStream(m);
j.Assign(b);
Image1.Picture.Graphic := j;
// Image1.Picture.Bitmap.LoadFromStream(m);
finally
m.free;
b.Free;
j.Free;
o.DestroyObject;
end;
"Warrick Wilson" <warrickw (AT) mercuryonline (DOT) com> wrote in message
news:452d171f$1 (AT) newsgroups (DOT) borland.com...
| Quote: | "Peter C" <ozcelt (AT) hotmail (DOT) com> wrote in message
news:4529da11 (AT) newsgroups (DOT) borland.com...
Thanks Peter,
This helped a lot. I had been doing something similiar, but I did not
know I had to lock the array, which made all the difference.
I also had to generate a 14 byte Bitmap File Header and write it too the
stream before I wrote the DIB content.
Everything now seems to be working fine.
Thanks Again,
Peter Collas
Peter C,
Any chance you could post your updated routine that solves the problem so
that this thread becomes a complete solution? Having that will help the
next guy who comes along with your question.
Thanks...Warrick
|
|
|
| Back to top |
|
 |
|
|
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
|
|