nititum
asked on
Convert DIB to TImage
Now I have DIB Handle of image (acquire from scanner), how can I assign (convert) it to TImage Object?
Code would be great!!(200 pts)
Thank you
Code would be great!!(200 pts)
Thank you
ASKER
First of all I'm sorry that I forgot to tell you that I'm using C++Builder 3, but I think this question is related to VCL and it should be the same as Delphi, So I post my question here.
I tried it (as you told me), it can be assign the handle but there is no bitmap shown.
Do I have to assign the width, height, or any properties of bitmap?
I tried it (as you told me), it can be assign the handle but there is no bitmap shown.
Do I have to assign the width, height, or any properties of bitmap?
Yes, if you adjust the syntax, C++ Builder should be the same...
I created a little demo application with two TImage objects on it. One without a bitmap. One with a big bitmap (bigger than the image without the bitmap). Then I added a button and in the onClick handler I wrote:
begin
image2.picture.bitmap.hand leType:=bm DIB; // to make sure we have a DIB handle...
image1.picture.bitmap.hand le:=image2 .picture.b itmap.hand le;
// instead of image2.picture.bitmap.hand le you should be able to write yourDIBHandle...
image1.setBounds(image1.le ft,image1. top,image1 .picture.b itmap.widt h,image1.p icture.bit map.height );
// this should stay the same...
end;
And it worked. Hope it will do with C++ Builder and with another DIB handle, too.
Regards, Madshi.
I created a little demo application with two TImage objects on it. One without a bitmap. One with a big bitmap (bigger than the image without the bitmap). Then I added a button and in the onClick handler I wrote:
begin
image2.picture.bitmap.hand
image1.picture.bitmap.hand
// instead of image2.picture.bitmap.hand
image1.setBounds(image1.le
// this should stay the same...
end;
And it worked. Hope it will do with C++ Builder and with another DIB handle, too.
Regards, Madshi.
Nititum,
Madshi's answer is certainly valid for delphi. I have a visual c++ dll that I wrote to manipulate images. You pass it a bitmap handle and it returns one (DIB). I then assign the handle to a TBitmap object in delphi and all of a sudden I have a bitmap...
Good luck
Zac
Madshi's answer is certainly valid for delphi. I have a visual c++ dll that I wrote to manipulate images. You pass it a bitmap handle and it returns one (DIB). I then assign the handle to a TBitmap object in delphi and all of a sudden I have a bitmap...
Good luck
Zac
ASKER
Dear Madshi,
Please wait for me to test the code, I have to wait until Mon.
I will tell you the result ASAP ;-)
nititum
Please wait for me to test the code, I have to wait until Mon.
I will tell you the result ASAP ;-)
nititum
No problem...
BTW, what does ASAP mean? As Soon As Processed?
BTW, what does ASAP mean? As Soon As Processed?
ASKER
Hi, ASAP is As Soon As Posible...
I tried this
Image1->Picture->Bitmap->H andleType = bmDIB;
Image1->Picture->Bitmap->H andle = (*EZ_AcquireNative)(hwnd, CURRENT_UNITS, PIXEL_TYPE, RESOLUTION, 8.27, 11.69);
Image1->SetBounds(Image1-> Left,Image 1->Top,Ima ge1->Pictu re->Width, Image1->Pi cture->Hei ght);
which (*EZ_AcquireNative)(...); is the function that acquire image from scanner and it return type is "HANDLE"
there is a message "Access violation" at Image1->SetBounds..
Can I convert HANDLE to Stream and use Image1->Picture->Bitmap->L oadFromStr eam(TStrea m* Stream).
If yes how to convert HANDLE to Stream...
Thank you.
nititum
I tried this
Image1->Picture->Bitmap->H
Image1->Picture->Bitmap->H
Image1->SetBounds(Image1->
which (*EZ_AcquireNative)(...); is the function that acquire image from scanner and it return type is "HANDLE"
there is a message "Access violation" at Image1->SetBounds..
Can I convert HANDLE to Stream and use Image1->Picture->Bitmap->L
If yes how to convert HANDLE to Stream...
Thank you.
nititum
ASKER
Hi, ASAP is As Soon As Posible...
I tried this
Image1->Picture->Bitmap->H andleType = bmDIB;
Image1->Picture->Bitmap->H andle = (*EZ_AcquireNative)(hwnd, CURRENT_UNITS, PIXEL_TYPE, RESOLUTION, 8.27, 11.69);
Image1->SetBounds(Image1-> Left,Image 1->Top,Ima ge1->Pictu re->Width, Image1->Pi cture->Hei ght);
which (*EZ_AcquireNative)(...); is the function that acquire image from scanner and it return type is "HANDLE"
there is a message "Access violation" at Image1->SetBounds..
Can I convert HANDLE to Stream and use Image1->Picture->Bitmap->L oadFromStr eam(TStrea m* Stream).
If yes how to convert HANDLE to Stream...
Thank you.
nititum
I tried this
Image1->Picture->Bitmap->H
Image1->Picture->Bitmap->H
Image1->SetBounds(Image1->
which (*EZ_AcquireNative)(...); is the function that acquire image from scanner and it return type is "HANDLE"
there is a message "Access violation" at Image1->SetBounds..
Can I convert HANDLE to Stream and use Image1->Picture->Bitmap->L
If yes how to convert HANDLE to Stream...
Thank you.
nititum
I'm not sure where this access violation comes from. Probably the image object wasn't able to handle the handle from EZ_AcquireNative.
Please set a breakpoint on the line Image1->SetBounds... and look if the object Image1.Picture is nil (in C++ 0, I guess).
Then please delete the first line. It won't help. Possibly it will make problems. I think you copied it from my little example. But if you look again at my example, I set the HandleType of Image2, not of Image1.
Then you could try something like
Image1->SetBounds(Image1-> Left,Image 1->Top,500 ,500);
Just to test, if that would work and where the access violation comes from.
You can't easily convert a handle to a stream. You would have to add a full bitmap header and so on. Would be much more difficult than any other kind of transfering the bitmap. Perhaps you could use a BitBlt, but I would prefer using the method I suggested. Of course we have to find out, why it doesn't work yet.
Please report about what's happening if you try my suggestions...
Regards, Madshi.
Please set a breakpoint on the line Image1->SetBounds... and look if the object Image1.Picture is nil (in C++ 0, I guess).
Then please delete the first line. It won't help. Possibly it will make problems. I think you copied it from my little example. But if you look again at my example, I set the HandleType of Image2, not of Image1.
Then you could try something like
Image1->SetBounds(Image1->
Just to test, if that would work and where the access violation comes from.
You can't easily convert a handle to a stream. You would have to add a full bitmap header and so on. Would be much more difficult than any other kind of transfering the bitmap. Perhaps you could use a BitBlt, but I would prefer using the method I suggested. Of course we have to find out, why it doesn't work yet.
Please report about what's happening if you try my suggestions...
Regards, Madshi.
ASKER
Now I found sth. wrong with the EZ_AcquireNative functions, I tried to get the bitmap information from the returned handle but all information are wrong.
I think your code is work, I tried it with others HANDLE.
Please post the answer.
Thank you
Nititum
I think your code is work, I tried it with others HANDLE.
Please post the answer.
Thank you
Nititum
ASKER
Now I found sth. wrong with the EZ_AcquireNative functions, I tried to get the bitmap information from the returned handle but all information are wrong.
I think your code is work, I tried it with others HANDLE. Sorry for taking you into my trouble.
Please post the answer.
Thank you
Nititum
I think your code is work, I tried it with others HANDLE. Sorry for taking you into my trouble.
Please post the answer.
Thank you
Nititum
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Delphi's TBitmap object (that is included in TImage) is able to handle both types of windows bitmaps, DDB and DIB.
Regards, Madshi.