
Python
Как в python сделать прозрачный цвет
Мне нужно задать картинке прозрачный фон


по мнению встроенной документации, нужно поколдовать над img через .transparency_get(...) и transparency_set(...)
я с этим опыта не имел, поэтому конкретный пример дать не могу
идея, что закрасить "пустые" пикселы розовым (#FF00FF) и прогнав два цикла (по x и y) сделать им img.transparency_set(x,y,True)
help> tkinter.PhotoImage
Help on class PhotoImage in tkinter:
tkinter.PhotoImage = class PhotoImage(Image)
| tkinter.PhotoImage(name=None, cnf={}, master=None, **kw)
|
| Widget which can display images in PGM, PPM, GIF, PNG format.
|
| Method resolution order:
| PhotoImage
| Image
| builtins.object
|
| Methods defined here:
|
| __getitem__(self, key)
|
| __init__(self, name=None, cnf={}, master=None, **kw)
| Create an image with NAME.
|
| Valid resource names: data, format, file, gamma, height, palette,
| width.
|
| blank(self)
| Display a transparent image.
|
| cget(self, option)
| Return the value of OPTION.
|
| copy(self)
| Return a new PhotoImage with the same image as this widget.
|
| get(self, x, y)
| Return the color (red, green, blue) of the pixel at X,Y.
|
| put(self, data, to=None)
| Put row formatted colors to image starting from
| position TO, e.g. image.put("{red green} {blue yellow}", to=(4,6))
|
| subsample(self, x, y='')
| Return a new PhotoImage based on the same image as this widget
| but use only every Xth or Yth pixel. If y is not given, the
| default value is the same as x.
|
| transparency_get(self, x, y)
| Return True if the pixel at x,y is transparent.
|
| transparency_set(self, x, y, boolean)
| Set the transparency of the pixel at x,y.
|
| write(self, filename, format=None, from_coords=None)
| Write image to file FILENAME in FORMAT starting from
| position FROM_COORDS.
|
| zoom(self, x, y='')
| Return a new PhotoImage with the same image as this widget
| but zoom it with a factor of x in the X direction and y in the Y
| direction. If y is not given, the default value is the same as x.
|
| ----------------------------------------------------------------------
| Methods inherited from Image:
|
| __del__(self)
|
| __setitem__(self, key, value)
|
| __str__(self)
| Return str(self).
|
| config = configure(self, **kw)
|
| configure(self, **kw)
| Configure the image.
|
| height(self)
| Return the height of the image.
|
| type(self)
| Return the type of the image, e.g. "photo" or "bitmap".
|
| width(self)
| Return the width of the image.
|
| ----------------------------------------------------------------------
| Data descriptors inherited from Image:
|
| __dict__
| dictionary for instance variables (if defined)
|
| __weakref__
| list of weak references to the object (if defined)
help>
я с этим опыта не имел, поэтому конкретный пример дать не могу
идея, что закрасить "пустые" пикселы розовым (#FF00FF) и прогнав два цикла (по x и y) сделать им img.transparency_set(x,y,True)
help> tkinter.PhotoImage
Help on class PhotoImage in tkinter:
tkinter.PhotoImage = class PhotoImage(Image)
| tkinter.PhotoImage(name=None, cnf={}, master=None, **kw)
|
| Widget which can display images in PGM, PPM, GIF, PNG format.
|
| Method resolution order:
| PhotoImage
| Image
| builtins.object
|
| Methods defined here:
|
| __getitem__(self, key)
|
| __init__(self, name=None, cnf={}, master=None, **kw)
| Create an image with NAME.
|
| Valid resource names: data, format, file, gamma, height, palette,
| width.
|
| blank(self)
| Display a transparent image.
|
| cget(self, option)
| Return the value of OPTION.
|
| copy(self)
| Return a new PhotoImage with the same image as this widget.
|
| get(self, x, y)
| Return the color (red, green, blue) of the pixel at X,Y.
|
| put(self, data, to=None)
| Put row formatted colors to image starting from
| position TO, e.g. image.put("{red green} {blue yellow}", to=(4,6))
|
| subsample(self, x, y='')
| Return a new PhotoImage based on the same image as this widget
| but use only every Xth or Yth pixel. If y is not given, the
| default value is the same as x.
|
| transparency_get(self, x, y)
| Return True if the pixel at x,y is transparent.
|
| transparency_set(self, x, y, boolean)
| Set the transparency of the pixel at x,y.
|
| write(self, filename, format=None, from_coords=None)
| Write image to file FILENAME in FORMAT starting from
| position FROM_COORDS.
|
| zoom(self, x, y='')
| Return a new PhotoImage with the same image as this widget
| but zoom it with a factor of x in the X direction and y in the Y
| direction. If y is not given, the default value is the same as x.
|
| ----------------------------------------------------------------------
| Methods inherited from Image:
|
| __del__(self)
|
| __setitem__(self, key, value)
|
| __str__(self)
| Return str(self).
|
| config = configure(self, **kw)
|
| configure(self, **kw)
| Configure the image.
|
| height(self)
| Return the height of the image.
|
| type(self)
| Return the type of the image, e.g. "photo" or "bitmap".
|
| width(self)
| Return the width of the image.
|
| ----------------------------------------------------------------------
| Data descriptors inherited from Image:
|
| __dict__
| dictionary for instance variables (if defined)
|
| __weakref__
| list of weak references to the object (if defined)
help>
Похожие вопросы
- Разве Нейросети сложно. Встретил школьника, он сказал что его попросили сделать распознавание цветов. Сделал за 2 дня
- Помогите, как сделать авторизацию в программе на python?
- Окончил курсы на степике по Python что делать дальше?
- Какие хорошие игры сделаны на Python? Что на нем можно сделать серьезного?
- Python программирование. Помогите написать программу.
- Нейронные сети на Python 3.4
- Помогите пожалуйста, я начинающий программист и я столкнулся с проблемой. Как сделать локализацию Minecraft Python API?
- Python Как сделать так чтобы после сгенерированного числа оно не повторялось?
- Как сделать из python файла exe файл без потери скорости
- Что писать на Python?