Add GrabSprite /SaveSprite Alpha Chanel Support

Got an idea for enhancing PureBasic? New command(s) you'd like to see?
User avatar
thyphoon
Enthusiast
Enthusiast
Posts: 345
Joined: Sat Dec 25, 2004 2:37 pm

Add GrabSprite /SaveSprite Alpha Chanel Support

Post by thyphoon »

Can you add Alpha Chanel support to GrabSprite and SaveSprite.

today If I load a Sprite with Alpha Chanel (with #PB_Sprite_AlphaBlending) and i use GrabSprite or SaveSprite, a lose the Alpha Chanel :(
Best regards
User avatar
Kaeru Gaman
Addict
Addict
Posts: 4826
Joined: Sun Mar 19, 2006 1:57 pm
Location: Germany

Post by Kaeru Gaman »

it is not possible to support an Alpha-Channel with GabSprite, because the Background has none.

does re-saving of an RGBA-Sprite work?
oh... and have a nice day.
User avatar
thyphoon
Enthusiast
Enthusiast
Posts: 345
Joined: Sat Dec 25, 2004 2:37 pm

Post by thyphoon »

Kaeru Gaman wrote:it is not possible to support an Alpha-Channel with GabSprite, because the Background has none.

does re-saving of an RGBA-Sprite work?
No you lose the Alpha Channel !

I want to load a big PNG image with Alpha Channel and split it in many tiles (32x32) and save all tiles. But it's not possible with PB :(
User avatar
Kaeru Gaman
Addict
Addict
Posts: 4826
Joined: Sun Mar 19, 2006 1:57 pm
Location: Germany

Post by Kaeru Gaman »

did you check just resaving it?

... and did you try using Images to split it into Tiles?
oh... and have a nice day.
User avatar
thyphoon
Enthusiast
Enthusiast
Posts: 345
Joined: Sat Dec 25, 2004 2:37 pm

Post by thyphoon »

Kaeru Gaman wrote:did you check just resaving it?

... and did you try using Images to split it into Tiles?
yes !!!
The image
Image

The code to try

Code: Select all

If InitSprite() = 0
    MessageRequester("Erreur", "Impossible d'ouvrir l'écran & l'environnement nécessaire aux sprites !", 0)
    End
  EndIf
  
  If OpenWindow(0, 0, 0, 220, 160, "Un écran dans une fenêtre...", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
    ButtonGadget(0, 170, 135, 45, 20, "Quitter")

    If OpenWindowedScreen(WindowID(0), 0, 0, 160, 160, 0, 0, 0)=0
      MessageRequester("Erreur", "Impossible d'ouvrir un écran dans la fenêtre!", 0)
      End
    EndIf
  EndIf
  
  Global Nbsprite=0
  
  UsePNGImageDecoder()
  UsePNGImageEncoder()
  
  Procedure LoadSpriteAlphaAuto(IdSprite.l,Filename.s,Option.l=0)
  ;Merci a Cpl.Bator,Case et Ollivier sans qui cette fonction n'existerait pas !
  ;http://www.purebasic.fr/french/viewtopic.php?t=9324
  
  ;On verifie si le sprite est un PNG si il y  a une couche alpha
  If LCase(GetExtensionPart(Filename.s))="png" And ReadFile(0,Filename.s)
    FileSeek(0,25)
    If ReadByte(0)=6
      Option.l=Option | #PB_Sprite_AlphaBlending;Si c'est le cas alors on rajoute l'option qui va bien
    EndIf
    CloseFile(0)
  EndIf

  If LoadSprite(IdSprite,Filename,Option)
    ProcedureReturn #True
  Else
    NbSprite-1
    Debug "ERROR:"+Filename
    ProcedureReturn #False
  EndIf
EndProcedure

  Debug LoadSpriteAlphaAuto(10,"house.png")

;Coordonée du sprite (on verra plus tard pour la boucle )
  x=4
  y=4
  Debug GrabSprite(11,32*x,32*y,32,32)
de changer le numero de sprite dans savesprite
SaveSprite(10,"hometest.png",#PB_ImagePlugin_PNG)
  SaveSprite(11,"home_"+Str(x)+"x"+Str(y)+".png",#PB_ImagePlugin_PNG)
User avatar
zxtunes.com
Enthusiast
Enthusiast
Posts: 375
Joined: Wed Apr 23, 2008 7:51 am
Location: Saint-Petersburg, Russia
Contact:

Post by zxtunes.com »

+1
User avatar
zxtunes.com
Enthusiast
Enthusiast
Posts: 375
Joined: Wed Apr 23, 2008 7:51 am
Location: Saint-Petersburg, Russia
Contact:

Post by zxtunes.com »

+1
Post Reply