Transparent PNG Images

General Help regarding HMG, Compilation, Linking, Samples

Moderator: Rathinagiri

User avatar
srvet_claudio
Posts: 2193
Joined: Thu Feb 25, 2010 8:43 pm
Location: Uruguay
Contact:

Re: Transparent PNG Images

Post by srvet_claudio »

Hi Giovanni,
the problem is that your superimpose a Image Control over another Image Control, the correct way is this:

Code: Select all

#include "hmg.ch"

FUNCTION Main()

PRIVATE hBitmap1 := 0 
PRIVATE hBitmap2 := 0 

   DEFINE WINDOW Form_1 ;
      AT 90,90 ;
      WIDTH 800 ;
      HEIGHT 600 ;
      TITLE "Giovanni" ;
      MAIN;
      ON INIT     Proc_ON_INIT ();
      ON RELEASE  Proc_ON_RELEASE ();
      ON PAINT    Proc_ON_PAINT ()

      @ 500, 350 BUTTON Button_1 CAPTION "Save Image" ACTION SaveImage()

   END WINDOW

   ACTIVATE WINDOW Form_1

RETURN NIL


PROCEDURE Proc_ON_INIT
  hBitmap1 := BT_BitmapLoadFile ("background.png")
  hBitmap2 := BT_BitmapLoadFile ("cocacola.png")
RETURN


PROCEDURE Proc_ON_RELEASE
   BT_BitmapRelease (hBitmap1)
   BT_BitmapRelease (hBitmap2)
RETURN


PROCEDURE Proc_ON_PAINT
LOCAL hDC, BTstruct
   hDC := BT_CreateDC ("Form_1", BT_HDC_INVALIDCLIENTAREA, @BTstruct)
      BT_DrawBitmap   (hDC,   0,   0, 800, 600, BT_STRETCH, hBitmap1)
      BT_DrawBitmapTransparent (hDC, 120, 150, 100, 150, BT_STRETCH, hBitmap2)
   BT_DeleteDC (BTstruct)
RETURN


PROCEDURE SaveImage
LOCAL hBitmap := BT_BitmapClone (hBitmap1)
   BT_BitmapPasteTransparent (hBitmap, 120, 150, 100, 150, BT_STRETCH, hBitmap2, NIL) 
   BT_BitmapSaveFile (hBitmap, "SaveImage.png", BT_FILEFORMAT_PNG) 
RETURN
PS: if you save the images, you can use the resulting composite image into a single Image Control.
Best regards.
Dr. Claudio Soto
(from Uruguay)
http://srvet.blogspot.com
calimero22
Posts: 53
Joined: Sun Nov 04, 2012 11:00 am

Re: Transparent PNG Images

Post by calimero22 »

Thank you very much for your help.
But all images show always the background.
You can see the output in the attachment.
Thank you.
Giovanni
Attachments
h.jpg
h.jpg (254.1 KiB) Viewed 1511 times
calimero22
Posts: 53
Joined: Sun Nov 04, 2012 11:00 am

Re: Transparent PNG Images

Post by calimero22 »

Ok Claudio.
You are GREAT,
It works very fine.
Thank you very much,
Giovanni Di Maria
Attachments
ok.jpg
ok.jpg (65.23 KiB) Viewed 1511 times
Post Reply