Do you own a Debenu Quick PDF Library version 7, 8, 9, 10, 11, 12, 13 or iSEDQuickPDF license? Upgrade to Debenu Quick PDF Library 14 today!

Debenu Quick PDF Library - PDF SDK Community Forum Homepage
Forum Home Forum Home > For Users of the Library > I need help - I can help
  New Posts New Posts RSS Feed - Displaying transparent BMP Files
  FAQ FAQ  Forum Search   Register Register  Login Login

Displaying transparent BMP Files

 Post Reply Post Reply
Author
Message
mcinelly1 View Drop Down
Beginner
Beginner


Joined: 09 Mar 11
Location: USA
Status: Offline
Points: 7
Post Options Post Options   Thanks (0) Thanks(0)   Quote mcinelly1 Quote  Post ReplyReply Direct Link To This Post Topic: Displaying transparent BMP Files
    Posted: 24 May 12 at 10:27PM
Hi,
 
I'm trying to display a monochrome bmp file (a scanned signature) over the top of my pdf file.  I'm trying to get the white area of the bmp to be transparent.  Following previous posts I found reference to the SetImageAsMask() and SetImageMask() functions. Using the following code:
 
int iResult = qp->AddImageFromFile(WideString(sSigPath).c_bstr(), 1);
qp->SelectPage(iImagePageNumber);
qp->SelectImage(iResult);
qp->SetImageMask(0); // or qp->SetImageMask(1)
qp->DrawImage(iImageLeft, iImageTop + (iImageHeight * .5), iImageWidth, iImageHeight * 2);
I get a completely white graphic - the black signature is being filtered out.
 
if I replace qp->SetImageMask(0) with something like qp->SetImageAsMask(0,0,0,.5,.5,.5) (or pretty much any other values) I can get a few pixels of black - but it is mostly filtered out too.
 
Are there any special considerations for the BMP type, other than monochrome?   The sample bmp file can be downloaded from www.agencysoftware.com/test.bmp
 
Thanks in advance for your help.
Mitch McInelly
 
Back to Top
mcinelly1 View Drop Down
Beginner
Beginner


Joined: 09 Mar 11
Location: USA
Status: Offline
Points: 7
Post Options Post Options   Thanks (0) Thanks(0)   Quote mcinelly1 Quote  Post ReplyReply Direct Link To This Post Posted: 25 May 12 at 4:02PM
Sorry.  I should also say that I am using C++ Builder 6 and QuickPDFDLL0812.dll
 
Thanks,
Mitch McInelly
Back to Top
Ingo View Drop Down
Moderator Group
Moderator Group
Avatar

Joined: 29 Oct 05
Status: Offline
Points: 3524
Post Options Post Options   Thanks (0) Thanks(0)   Quote Ingo Quote  Post ReplyReply Direct Link To This Post Posted: 25 May 12 at 4:08PM
Hi Mitch!

You should try the newest dll first.
The kind of work you described was improved with each new version.
Actually we've 8.15 ;-)

Cheers, Ingo

Back to Top
mcinelly1 View Drop Down
Beginner
Beginner


Joined: 09 Mar 11
Location: USA
Status: Offline
Points: 7
Post Options Post Options   Thanks (0) Thanks(0)   Quote mcinelly1 Quote  Post ReplyReply Direct Link To This Post Posted: 25 May 12 at 6:10PM
I installed 8.15 this morning and I have the same results.  SetImageAsMask(0)  does not make white background transparent.  SetImageAsMask(1) makes pretty much entire BMP transparent - not showing black lines.  I triple checked that my file was a black & white bmp.
 
Thanks
Back to Top
barqyDev View Drop Down
Beginner
Beginner


Joined: 10 Feb 12
Status: Offline
Points: 7
Post Options Post Options   Thanks (0) Thanks(0)   Quote barqyDev Quote  Post ReplyReply Direct Link To This Post Posted: 27 May 12 at 8:47PM
I had some problems with BMP, so I converted to PNG (no transparency though).
I was not able to get the SetPNGTransparencyColor() to work, but 
SetImageMask() seems like it can work for you.
I put a range of 90% = 100%, but if the image really is monochrome, you should be able to use all 1's for the starting/ending color.

edited...I used AddImageFromFile(L"test.png", 0)

 int iResult = qp->AddImageFromFile(WideString(sSigPath).c_bstr(), 1);
qp->SelectPage(iImagePageNumber);
qp->SelectImage(iResult);
qp->SetImageMask( 0.9, 0.9, 0.9, 1, 1, 1 ); // THIS SHOULD WORK FOR YOU
qp->DrawImage(iImageLeft, iImageTop + (iImageHeight * .5), iImageWidth, iImageHeight * 2);



Edited by barqyDev - 27 May 12 at 9:03PM
Back to Top
kaiken1987 View Drop Down
Beginner
Beginner
Avatar

Joined: 27 Jan 12
Location: United States
Status: Offline
Points: 5
Post Options Post Options   Thanks (0) Thanks(0)   Quote kaiken1987 Quote  Post ReplyReply Direct Link To This Post Posted: 10 Sep 12 at 7:49PM
barqyDev, thanks I was also having a problem doing this and at it fixed it
Back to Top
mcinelly1 View Drop Down
Beginner
Beginner


Joined: 09 Mar 11
Location: USA
Status: Offline
Points: 7
Post Options Post Options   Thanks (0) Thanks(0)   Quote mcinelly1 Quote  Post ReplyReply Direct Link To This Post Posted: 11 Sep 12 at 9:16PM
I could not get this to work for monochrome bitmap images.  I would up having to convert the monochromes to 256 color images as follows:
 
//SignControl3 is a monochrome bitmap
//SignControl2 is predefined 256 color palette
 
      SignControl3->Picture->LoadFromFile(OpenPictureDialog->FileName);
      SignControl2->Width = SignControl3->Width;                      
      SignControl2->Height = SignControl3->Height;
      TRect src = Rect(0,0, SignControl3->Width, SignControl3->Height);
      TRect dest = Rect(0, 0,SignControl2->Picture->Bitmap->Width, SignControl2->Picture->Bitmap-   >Height);
      SignControl2->Picture->Bitmap->Canvas->CopyRect(dest, SignControl3->Canvas, src);
      SignControl2->Picture->SaveToFile(OpenPictureDialog->FileName);
      SignControl->Picture->LoadFromFile(OpenPictureDialog->FileName);
Back to Top
barqyDev View Drop Down
Beginner
Beginner


Joined: 10 Feb 12
Status: Offline
Points: 7
Post Options Post Options   Thanks (0) Thanks(0)   Quote barqyDev Quote  Post ReplyReply Direct Link To This Post Posted: 11 Sep 12 at 9:23PM
mcinelly1, I understand you've got a solution going.  If you can provide a link to the (or a) mono bitmap, I'm interested in tinkering with it.  Seems like there should be an easier way than to convert the file and reload it.
Back to Top
AndrewC View Drop Down
Moderator Group
Moderator Group
Avatar

Joined: 08 Dec 10
Location: Geelong, Aust
Status: Offline
Points: 841
Post Options Post Options   Thanks (0) Thanks(0)   Quote AndrewC Quote  Post ReplyReply Direct Link To This Post Posted: 12 Sep 12 at 4:32AM
This code is working correctly using the 8.16 release.  It creates a problem with the 8.15 release so it looks like there was a bug fix in the 8.16 release that allows this to work correctly.

8.16 is a free upgrade from 8.xx and can be downloaded from http://www.debenu.com/products/development/debenu-pdf-library/updates/

    QP.SetOrigin(1);
    QP.SetLineWidth(2);
    for (int i = 1; i <= 16; i++)
    {
        QP.SetLineColor(0, (double)i / 16, (double)i / 16);
        QP.DrawLine(i * 16, 0, i * 16, 200);
    }

    int img = QP.AddImageFromFile("test.bmp", -1);
    QP.SelectImage(img);
    QP.SetImageMask(0.9, 0.9, 0.9, 1, 1, 1); // THIS SHOULD WORK FOR YOU
    QP.DrawImage(0,0, 100, 100);

    QP.SaveToFile("out.pdf");

It seems that when using the code above - AcrobatX does some interesting things when rendering this file.  If the zoom is less than 100% then a white box is drawn under the signature. Zooming in then shows the correct background.  I beleive this is an Acrobat rendering problem.

Another option is to call QP.SetBlendMode(3); before calling DrawImage and then calling QP.SetBlendMode(0);   Currenty QuickPDF Library cannot render blend modes but we are working to add this feature.

Andrew.




Edited by AndrewC - 12 Sep 12 at 5:37AM
Back to Top
myler View Drop Down
Beginner
Beginner
Avatar

Joined: 13 Sep 12
Location: ITALY
Status: Offline
Points: 2
Post Options Post Options   Thanks (0) Thanks(0)   Quote myler Quote  Post ReplyReply Direct Link To This Post Posted: 13 Sep 12 at 4:25PM
Hi mcinelly1!
I saw that you are working with C++Builder 6. Can I ask you some suggestions in order to install QPL onto C++ Builder?
I tried to work with the Active X but when I try to unlock the component I get "0" as result instead of 1.
Maybe I made some mistake when I've imported the type library( I do not know).
Now I'm trying to use the DLL but I don't know if it is a good idea...
Thanks in advance,
Erio
Back to Top
Wheeley View Drop Down
Senior Member
Senior Member
Avatar

Joined: 30 Oct 05
Location: United States
Status: Offline
Points: 146
Post Options Post Options   Thanks (0) Thanks(0)   Quote Wheeley Quote  Post ReplyReply Direct Link To This Post Posted: 13 Sep 12 at 7:50PM
As you work out your troubles one difference to keep in mind is that any computer you want to run your application on will need to register the ActiveX. You don't have this issue with the DLL.

Wheeley
Back to Top
myler View Drop Down
Beginner
Beginner
Avatar

Joined: 13 Sep 12
Location: ITALY
Status: Offline
Points: 2
Post Options Post Options   Thanks (0) Thanks(0)   Quote myler Quote  Post ReplyReply Direct Link To This Post Posted: 13 Sep 12 at 9:43PM
Thanks a lot Wheeley. I agree with your reply. I supposed that ActiveX was faster in order to develop the application than DLL. 
Back to Top
AndrewC View Drop Down
Moderator Group
Moderator Group
Avatar

Joined: 08 Dec 10
Location: Geelong, Aust
Status: Offline
Points: 841
Post Options Post Options   Thanks (0) Thanks(0)   Quote AndrewC Quote  Post ReplyReply Direct Link To This Post Posted: 14 Sep 12 at 4:57AM
Here is some BCB6 code that should help you to load the DLL version.  Make sure the QuickPDFDLL0816.DLL file is in the same directory as your compiled EXE or on the Windows path somewhere.  8.xx uses unicode strings hence the L prefix.

#include <vcl.h>
#pragma hdrstop

#include "Unit1.h"
#include "stdio.h"
#include "stdlib.h"
#include "dir.h"
#include "mem.h"
#include "io.h"

#include "strutils.hpp"

#include "QuickPDFdll0816.cpp"
QuickPDFDLL0816  QP(L"quickpdfdll0816.dll");

#include <string>
using namespace std;

//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TForm1 *Form1;
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
    : TForm(Owner)
{
    int InstanceID;
    chdir("f:\\users\\andrew\\downloads");

    wstring s = L"<insert your licence key here>";
    std::wstring lv = QP.LibraryVersion();

    if (QP.UnlockKey(s) != 1)
        MessageBox(Handle, "QPL License Key not valid", "Warning", MB_OK);

    Text = lv.c_str();  // Set the Window Title to the version number.

    int ret = QP.ImportEMFFromFile(L"aaa.emf", 0, 0);
}

Back to Top
 Post Reply Post Reply
  Share Topic   

Forum Jump Forum Permissions View Drop Down

Forum Software by Web Wiz Forums® version 11.01
Copyright ©2001-2014 Web Wiz Ltd.

Copyright © 2017 Debenu. Debenu Quick PDF Library is a PDF SDK. All rights reserved. AboutContactBlogSupportOnline Store