Print Page | Close Window

Displaying transparent BMP Files

Printed From: Debenu Quick PDF Library - PDF SDK Community Forum
Category: For Users of the Library
Forum Name: I need help - I can help
Forum Description: Problems and solutions while programming with the Debenu Quick PDF Library and Debenu PDF Viewer SDK
URL: http://www.quickpdf.org/forum/forum_posts.asp?TID=2276
Printed Date: 22 Nov 24 at 6:17PM
Software Version: Web Wiz Forums 11.01 - http://www.webwizforums.com


Topic: Displaying transparent BMP Files
Posted By: mcinelly1
Subject: Displaying transparent BMP Files
Date 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 http://www.agencysoftware.com/test.bmp - www.agencysoftware.com/test.bmp
 
Thanks in advance for your help.
Mitch McInelly
 



Replies:
Posted By: mcinelly1
Date 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


Posted By: Ingo
Date 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



Posted By: mcinelly1
Date 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


Posted By: barqyDev
Date 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);



Posted By: kaiken1987
Date Posted: 10 Sep 12 at 7:49PM
barqyDev, thanks I was also having a problem doing this and at it fixed it


Posted By: mcinelly1
Date 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);


Posted By: barqyDev
Date 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.


Posted By: AndrewC
Date 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/ - 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.




Posted By: myler
Date 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


Posted By: Wheeley
Date 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


Posted By: myler
Date 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. 


Posted By: AndrewC
Date 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);
}




Print Page | Close Window

Forum Software by Web Wiz Forums® version 11.01 - http://www.webwizforums.com
Copyright ©2001-2014 Web Wiz Ltd. - http://www.webwiz.co.uk