Skip to main content
Tweeted twitter.com/StackBlender/status/888260124506071040
deleted 10 characters in body
Source Link
ideasman42
  • 48k
  • 10
  • 144
  • 226

I have tried the following, and the resulting image file, when opened in GIMP, never contains an alpha channel, only R, G and B.

import bpy
image = bpy.data.images.new("Sprite", alpha=True, width=needed_wwidth=16, height=hheight=16)
image.filepath = "//Sprite.png"
image.file_format = 'PNG'
image.save()

Result: no alpha channel in png

import bpy
image = bpy.data.images.new("Sprite", alpha=True, width=needed_wwidth=16, height=hheight=16)
image.colorspace_settings.name = 'sRGB'
image.use_alpha = True
image.alpha_mode = 'STRAIGHT'
image.filepath = "//Sprite.png"
image.file_format = 'PNG'
image.save()

Result: no alpha channel in png file.

I have tried the following, and the resulting image file, when opened in GIMP, never contains an alpha channel, only R, G and B.

image = bpy.data.images.new("Sprite", alpha=True, width=needed_w, height=h)
image.filepath = "//Sprite.png"
image.file_format = 'PNG'
image.save()

Result: no alpha channel in png

image = bpy.data.images.new("Sprite", alpha=True, width=needed_w, height=h)
image.colorspace_settings.name = 'sRGB'
image.use_alpha = True
image.alpha_mode = 'STRAIGHT'
image.filepath = "//Sprite.png"
image.file_format = 'PNG'
image.save()

Result: no alpha channel in png file.

I have tried the following, and the resulting image file, when opened in GIMP, never contains an alpha channel, only R, G and B.

import bpy
image = bpy.data.images.new("Sprite", alpha=True, width=16, height=16)
image.filepath = "//Sprite.png"
image.file_format = 'PNG'
image.save()

Result: no alpha channel in png

import bpy
image = bpy.data.images.new("Sprite", alpha=True, width=16, height=16)
image.colorspace_settings.name = 'sRGB'
image.use_alpha = True
image.alpha_mode = 'STRAIGHT'
image.filepath = "//Sprite.png"
image.file_format = 'PNG'
image.save()

Result: no alpha channel in png file.

Source Link
Hatoru Hansou
  • 886
  • 3
  • 13
  • 21

How to save an image created from python script including the alpha channel?

I have tried the following, and the resulting image file, when opened in GIMP, never contains an alpha channel, only R, G and B.

image = bpy.data.images.new("Sprite", alpha=True, width=needed_w, height=h)
image.filepath = "//Sprite.png"
image.file_format = 'PNG'
image.save()

Result: no alpha channel in png

image = bpy.data.images.new("Sprite", alpha=True, width=needed_w, height=h)
image.colorspace_settings.name = 'sRGB'
image.use_alpha = True
image.alpha_mode = 'STRAIGHT'
image.filepath = "//Sprite.png"
image.file_format = 'PNG'
image.save()

Result: no alpha channel in png file.