Bitmap\alphamap? over layer?
BlitzMax Forums/BlitzMax Beginners Area/Bitmap\alphamap? over layer?
| ||
how would this work in blitzmax? loading two images together. https://drive.google.com/open?id=0B8SxXaDSGTlXRk9OdUozWkdhVjg https://drive.google.com/open?id=0B8SxXaDSGTlXZEFuMmw5UjBCREk |
| ||
Please help?! I looked and nothing came up for blitzmax doing sprites with bitmap and alphamap. |
| ||
I'm assuming you want to combine the two images into one. The image needs to be in a format that supports an Alpha channel. 32bit Png and Tga formats are two that spring to mind. 32 bit (4 bytes) is needed to support, the red, green, blue and alpha channels. You would load the first image into an art package that supports images with alpha channels, say Photoshop. Add an alpha channel. Load the second image and copy and paste it into the alpha channel of the first image. Then save the first image with the alpha channel in a 32bit format of your choosing. Png or Tga. And when drawing the image you would want to use Alphablend mode for the image to render using the alpha channel. setblend(ALPHABLEND) |
| ||
I want to load bitmap and alphamap into a image file one with alpha map and one with a color map how do I do this? |
| ||
Is it sufficient to do this outside of BlitzMax, then use the result later in your app? Or do you need to combine both pictures not until they are in BlitzMax? |
| ||
He is talking abut eg. a jpeg containing the sprite...and eg. a 256 grayscales / 1 channel alpha map.... Like a "mask". With default blitzmax commands you cannot achieve that (at least I think so). Means you will have to preprocess them during loading. Load the image Load the mask Create another image with dims of the mask Clear the pixmap of this image Run over every pixel of the mask. Read the pixel of the source image at the corresponding image. Adjust the alpha of this srcPixel according to srcPixelAlpha multiplied with maskPixelAlpha. Store this in targetPixelAlpha. Last time I have seen such a thing was with the popcap-game-engine (or whatever "Zuma" used). Bye Ron |
| ||
I don't know how do that. with using pix with three maps normal\bum map,bitmap,alphamap. should I use c++ then? |
| ||
You want normal maps learn OpenGL good luck. |
| ||
You can scan both pixmaps with READPIXEL() to get two ARGB values of a corresponding pixel. Then combine the A--- value of the first pixmap with -RGB value of the second pixmap and store it back into another new Pixmap with WRITEPIXEL() ARGB is a 32bit integer with 8bit for each color-part Alpha-Red-Green-Blue. Here is a code snipplet: http://www.blitzbasic.com/codearcs/codearcs.php?code=2236 p.s. does anyone know, why the BlitzBasix.Com search engine is still disabled? |
| ||
@Caton I see from your other post you might still be having trouble coding a solution. So i decided to have a go myself. And here is the code you need if you haven't solved the problem yet. Its takes two 24bit rgb images and copies the second, into the first as an alpha channel and saves the result as a new image. The second image used as the alpha channel needs to be the same size as the first image and only the red channel is used for the alpha level. All three rgb channels should be the same ( ie white or shades of grey ). 'Both Image Images Need To Be The Same Size Strict Global screen_size_x = 1024 Global screen_size_y = 768 Global screen_centre_x = screen_size_x / 2 Global screen_centre_y = screen_size_y / 2 Graphics(screen_size_x , screen_size_y , 0 , 60) ' Window AutoImageFlags(MASKEDIMAGE|FILTEREDIMAGE|MIPMAPPEDIMAGE) AutoMidHandle(True) ' image origin = image centre and not top left SetMaskColor(0 , 0 , 0) ' black not drawn SeedRnd MilliSecs() Global pixmap_1:TPixmap = LoadPixmap("24bit rgb.bmp") 'Image 1 = 24bit RGB Color Image Global pixmap_width = PixmapWidth(pixmap_1) Global pixmap_height = PixmapHeight(pixmap_1) Global pixmap_2:TPixmap = LoadPixmap("24bit alpha.bmp") 'Image 2 = 24bit RGB Color Image ( Used As The Alpha Layer ) 'Arrays To Hold The RGB Values For Each Image Global pixmap_1_red_array[pixmap_width , pixmap_height] Global pixmap_1_green_array[pixmap_width , pixmap_height] Global pixmap_1_blue_array[pixmap_width , pixmap_height] Global pixmap_1_alpha_array[pixmap_width , pixmap_height] Global pixmap_2_red_array[pixmap_width , pixmap_height] Global pixmap_2_green_array[pixmap_width , pixmap_height] Global pixmap_2_blue_array[pixmap_width , pixmap_height] 'Create Final Pixmap In RGBA Format Global final_pixmap:TPixmap = CreatePixmap(pixmap_width , pixmap_height , PF_RGBA8888) ClearPixels(final_pixmap , 0) SetColor(255 , 255 , 255) SetScale(1 , 1) SetRotation(0) SetAlpha(1) Cls DrawText("Processing Image ..." , 0 , 0) Flip set_pixmap_arrays() copy_alpha_into_array() update_and_save_pixmap_1() While KeyDown(KEY_ESCAPE) = False Cls DrawPixmap(final_pixmap , screen_centre_x - (pixmap_width / 2), screen_centre_y - (pixmap_height / 2)) SetColor(0 , 255 , 0) DrawText("Finished" , 0 , 0) SetColor(255 , 255 , 255) DrawText("Press Escape To Exit" , 0 , 30) Flip Wend End 'Get Alpha From ARGB Function argb_alpha(argb) Return (argb Shr 24) & $ff End Function 'Get Red From ARGB Function argb_red(argb) Return (argb Shr 16) & $ff End Function 'Get Green From ARGB Function argb_green(argb) Return (argb Shr 8) & $ff End Function 'Get Blue From ARGB Function argb_blue(argb) Return (argb & $ff) End Function 'Get ARGB From Alpha , Red , Green , Blue Function argb_color(alpha , red , green , blue) Return ( (alpha * $1000000) + (red * $10000) + (green * $100) + (blue) ) End Function Function set_pixmap_arrays() Local x_loop Local y_loop Local argb Local red Local green Local blue 'Pixmap 1 For y_loop = 0 To pixmap_height - 1 For x_loop = 0 To pixmap_width - 1 argb = ReadPixel(pixmap_1 , x_loop , y_loop) red = argb_red(argb) green = argb_green(argb) blue = argb_blue(argb) pixmap_1_red_array[x_loop , y_loop] = red pixmap_1_green_array[x_loop , y_loop] = green pixmap_1_blue_array[x_loop , y_loop] = blue pixmap_1_alpha_array[x_loop , y_loop] = 0 Next Next 'Pixmap 2 For y_loop = 0 To pixmap_height - 1 For x_loop = 0 To pixmap_width - 1 argb = ReadPixel(pixmap_2 , x_loop , y_loop) red = argb_red(argb) green = argb_green(argb) blue = argb_blue(argb) pixmap_2_red_array[x_loop , y_loop] = red pixmap_2_green_array[x_loop , y_loop] = green pixmap_2_blue_array[x_loop , y_loop] = blue Next Next End Function Function copy_alpha_into_array() Local x_loop Local y_loop For y_loop = 0 To pixmap_height - 1 For x_loop = 0 To pixmap_width - 1 'Pixmap 2 RGB Values Should All be The Same ( So Just Reading The Red Channel Here ) pixmap_1_alpha_array[x_loop , y_loop] = pixmap_2_red_array[x_loop , y_loop] Next Next End Function Function update_and_save_pixmap_1() Local x_loop Local y_loop Local red Local green Local blue Local alpha Local argb For y_loop = 0 To pixmap_height - 1 For x_loop = 0 To pixmap_width - 1 red = pixmap_1_red_array[x_loop , y_loop] green = pixmap_1_green_array[x_loop , y_loop] blue = pixmap_1_blue_array[x_loop , y_loop] alpha = pixmap_1_alpha_array[x_loop , y_loop] argb = argb_color(alpha , red , green , blue) WritePixel(final_pixmap , x_loop , y_loop , argb) Next Next SavePixmapPNG(final_pixmap , "final_image.png" , 0) End Function |