Fastest way to make color transparent?

I’ve got a Mac exclusive app in the workings where I retrieve PNG data from a server. Sadly, the graphics are on white background but I need them to be on a transparent layer.
What would be the fastest way to change white into clear? MBS would be fully fine.

Dim burf,surf As RGBSurface
dim bmap,neu as picture
dim b,h,rw,gw,bw,x,y,w,wx,z as integer
dim c,cc as color
rem Weisslöschen
try
If image <> Nil Then

b=image.Width
h=image.height 
neu = New picture(b,h)
neu.Graphics.drawpicture image,0,0
bmap =neu.copymask
bmap.graphics.ClearRectangle(0,0,b,h)
w= 230
burf=bmap.RGBSurface
surf=px(bnr).image.RGBSurface

cc=Color.black
For x = 0 To b
  For y = 0 To h
    c = surf.Pixel(x,y)
    If  c.red < w Or c.green <w Or c.blue < w  Then
      burf.pixel(x,y) = cc
    End If
  Next
Next
neu.ApplyMask(bmap)
pic As New pixmapshape(neu)

End If
Catch err As OutOfMemoryException
messagebox("kein Memory to draw the picture ! ")

Catch e As OutOfBoundsException

messagebox( “Exceeded size of array”)

Catch err As NilObjectException
messagebox("kein Alphakanal ! ")
End Try

Thank you, but that is obviously a time-consuming way. I need to do this in a zip and hope that someone can point me to an optimized (plugin?) method that does the same in a fraction of time.

Are you sure the background is pure white? If there is any antialiasing going on you would not get a very good result by just changing the white pixels to transparent…

BTW Xojo supports (or did support) doing it directly using the Picture.transparent property

When set to 1 white becomes transparent… Before the color alpha channel was supported, I used it often.

-Karen

Unfortunately it’s impossible. How do you know if a color should be 100% black at 50% opacity vs 50% black at 100% opacity? You don’t. Once blended to the white background, that data is permanently lost.

Worse still, with Xojo at least, is the only way to solve this is going through pixel by pixel with the RGBSurface. There may be a way to replace every instance of a color with another color, but you’d still need to go through to find each color that needs to be replaced and guess at its replacement.

Plugins might be your only option. MBS has ImageMagick options, though I’m not sure which function you’d use.

So you do want the white to be transparent?

Create new picture of the same size with no ‘depth’ new picture (x,y)
Drawpicture the original image to it, but with .transparent set to 1 on the downloaded pic.

Swapping one color for another can be done using TRANSFORM
But it doesnt seem to have been updated to handle alpha… just RGB

RGBSurface.Transform

Thanks all, especially Karen for reminding me on the old picture type transparency trick. Which I had given as an answer myself … Transparent for Pictures with alpha channel
That’s fast and convenient enough for my purpose. Sorry for using you as external memory!