Notifications
Clear all

[Closed] Read alpha channel from bitmap

This is actually super fast.
Can you explain these lines?

	pastebitmap img img2 [0,0] [0,0] type:#blend 
	pastebitmap img img2 [0,0] [0,0] type:#blend 
	return not (comparebitmaps img img2 0 0)

Thank you very much.

Actually the function is wrong but it appears to return accurate results.

A better function could be the following:

fn GetBitmapHasAlphaBlackPixel img =
  (
     	if img.hasalpha do
     	(
     		-- Create a new bitmap
     		img2 = bitmap img.width img.height
     		-- Blend the source Bitmap with the new Bitmap
     		pastebitmap img img2 [0,0] [0,0] type:#blend
     		-- Compare the two Bitmaps
     		areequal = comparebitmaps img img2 0 1
    		return not areequal
     	)
     	return false
     )

PolyTools, after some testing I’ve noticed that it always return true. Both with white alpha or black and white alphas. Or maybe I just haven’t understood the function but

img = $.material.diffuseMap.bitmap
fn GetBitmapHasAlphaBlackPixel img = (
				if img.hasalpha do
					(
					img2 = bitmap img.width img.height
					pastebitmap img img2 [0,0] [0,0] type:#blend 
					equal = comparebitmaps img img2 0 0
					return not equal
					)
					return false
			)
GetBitmapHasAlphaBlackPixel img	

returns always true.

1 Reply
(@polytools3d)
Joined: 11 months ago

Posts: 0

But you have changed the function.

equal = comparebitmaps img img2 0 1

Aah sorry. Thanks pal.

Page 2 / 2