Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Convert PNG to BMP and MSK files
Message
 
À
05/07/2005 10:10:49
Information générale
Forum:
Visual FoxPro
Catégorie:
Photos et traitement d'images
Divers
Thread ID:
01028982
Message ID:
01029148
Vues:
12
Malcolm,

This code will convert all the white pixels RGB(255,255,255) to RGB(254,254,254) as mentioned by Chad.

While this avoids having the extra MSK file it requires that you set the BackStyle property to transparent. This can cause problems with some images to not render correctly.

Hope this helps,
Bo Durban
www.moxiedata.com
#define PixelFormat24bppRGB        0x00021808
#define UnitPixel   2
#define ARGB_WHITE   0xffffffff

cImagePng = "image.png"
cImageBmp = FORCEEXT(cImagePng,"bmp")

SET CLASSLIB TO (HOME()+"ffc\_gdiplus") ADDITIVE
DeclGdip()

** Load our PNG and save it as a BMP
oImg = CREATEOBJECT("GpImage")
oImg.CreateFromFile(cImagePng)

nWidth = oImg.ImageWidth
nHeight = oImg.ImageHeight

** Create a bitmap the same size
oBmp = CREATEOBJECT("GpBitmap")
oBmp.Create(nWidth, nHeight, PixelFormat24bppRGB)
** Load it into a graphics object
oGfx = CREATEOBJECT("GpGraphics")
oGfx.CreateFromImage(oBmp)
oGfx.Clear(ARGB_WHITE)

** Create an GpImageAttribute to translate the colors
hImgAttrib = 0
GdipCreateImageAttributes(@hImgAttrib)

** Convert all knock all RGB values down by 1
cMatrix = ;
   BINTOC(1,"F")+BINTOC(0,"F")+BINTOC(0,"F")+BINTOC(0,"F")+BINTOC(0,"F")+;
   BINTOC(0,"F")+BINTOC(1,"F")+BINTOC(0,"F")+BINTOC(0,"F")+BINTOC(0,"F")+;
   BINTOC(0,"F")+BINTOC(0,"F")+BINTOC(1,"F")+BINTOC(0,"F")+BINTOC(0,"F")+;
   BINTOC(0,"F")+BINTOC(0,"F")+BINTOC(0,"F")+BINTOC(1,"F")+BINTOC(0,"F")+;
   BINTOC(-.004,"F")+BINTOC(-.004,"F")+BINTOC(-.004,"F")+BINTOC(0,"F")+BINTOC(1,"F")
GdipSetImageAttributesColorMatrix(hImgAttrib,1,1,cMatrix,0,0)

** Draw the PNG to our mask, converting all RGB values to black
GdipDrawImageRectRect(oGfx.GetHandle(),oImg.GetHandle(),;
   0, 0, nWidth, nHeight, ;
   0, 0, nWidth, nHeight, ;
   UnitPixel, hImgAttrib, 0, 0)

** Save the MSK file
oBmp.SaveToFile(cImageBmp,"image/bmp")

GdipDisposeImageAttributes(hImgAttrib)
oGfx = NULL
oBmp = NULL
oImg = NULL



***********************************************
FUNCTION DeclGDIP()

   DECLARE Long GdipDrawImageRectRect IN GDIPLUS ;
      Long graphics, Long image, ;
      Single dstx, Single dsty, ;
      Single dstwidth, Single dstheight, ;
      Single srcx, Single srcy, ;
      Single srcwidth, Single srcheight, ;
      Long srcUnit, Long imageAttributes, ;
      Long callback, Long callbackData

   DECLARE Long GdipCreateImageAttributes IN GDIPLUS ;
      Long @imageattr

   DECLARE Long GdipDisposeImageAttributes IN GDIPLUS ;
      Long imageattr

   DECLARE Long GdipSetImageAttributesColorMatrix IN GDIPLUS ;
      Long imageattr, Long type, ;
      Long enableFlag, String colorMatrix, ;
      Long grayMatrix, ;
      Long flags

ENDFUNC
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform