alpha

PyGame: Applying transparency to an image with alpha?

怎甘沉沦 提交于 2019-11-30 10:08:11
I want to display an image with alpha with a specified transparency, but can't figure out how to do it. To elaborate on how I'm struggling with this, the blurb below is a slightly modified hunk of code from this SO answer , but if you run it, you'll see that "image" loses it's native alpha, while the alpha of "image2" never changes! Yuck. #!/usr/bin/env python import pygame, sys pygame.init() window = pygame.display.set_mode((200, 200)) background = pygame.Surface((window.get_size())) background.fill((255, 255, 255)) image = image2 = pygame.image.load('alpha.png') image = image.convert() rect

How to convert 32-bit BMP to contain alpha channel? [closed]

[亡魂溺海] 提交于 2019-11-30 08:43:26
I have an PNG image with alpha, I need to convert it to BMP to be loaded to my OpenGL application. However, BMP has only 1 option for 32-bit, that is XRBG where 'X' is just an extra byte for padding purpose (4-byte alignment). The question is how to ultilise this 'X' byte to contain alpha channel, so that the BMP (32-bit XRGB) can be loaded to GL application with transparent pixels? Maybe I have to make my own tool to do this conversion? What I need is RGBA, and not 'XRGB' or 'ARGB', do I have to read the XRGB BMP file and scan pixel by pixel to convert to RGBA? Which is the best way in VC++

How to read an animated gif with alpha channel

百般思念 提交于 2019-11-30 08:29:05
While doing some tests with .gif animations in MATLAB I realised that somehow I can't read the transparency of the gif. Example: (Original source of the gif) If I do [img,cmap]=imread('Finnandjake.gif'); img is 4D with a redundant 3rd dimension (weird). After squeezing it ( img=squeeze(img); ), if I show it ( imshow(img(:,:,30),cmap) ): The transparency is gone, using another color from the image as background, thus deleting features. However [img,cmap,alpha]=imread('Finnandjake.gif'); returns an empty alpha . Obviously the information of the alpha is in the image somewhere, how can I read it

How to implement alpha gradient on a image?

故事扮演 提交于 2019-11-30 06:25:13
问题 I want to implement alpha gradient on an image. From 0.5 alfa on top of the image to 0.0 on bottom. Any advice, tutorial, link is welcome. 回答1: You can use CGImageCreateWithMask to apply a masking image to it. You could generate an appropriate mask simply enough by drawing to a greyscale or alpha-only CGBitmapContext with CGContextDrawLinearGradient . If it's being displayed as the content of a CALayer, you could apply an appropriate masking layer to the parent layer's mask property. You

Can I have image alpha fade from left to right in java?

試著忘記壹切 提交于 2019-11-30 05:58:20
问题 I am making a game and want to have a single image 'fade' from left to right with the left part of the image having an alpha of 1.0 and the right having an alpha of 0.0. (note: I do not want it to be changing what it looks like over time, like fading in or out, but just fading from left to right and staying constant). An attempt to draw what I want the end result to look like is below: lll lll ll ll l l l l l lll lll ll ll l l l l l lll lll ll ll l l l l l lll lll ll ll l l l l l lll lll ll

How to preserve transparency when resizing PNG using Perl and GD

我的未来我决定 提交于 2019-11-30 05:41:11
问题 This is the code i'm using: !/usr/bin/perl use GD; sub resize { my ($inputfile, $width, $height, $outputfile) = @_; my $gdo = GD::Image->new($inputfile); ## Begin resize my $k_h = $height / $gdo->height; my $k_w = $width / $gdo->width; my $k = ($k_h < $k_w ? $k_h : $k_w); $height = int($gdo->height * $k); $width = int($gdo->width * $k); ## The tricky part my $image = GD::Image->new($width, $height, $gdo->trueColor); $image->transparent( $gdo->transparent() ); $image->copyResampled($gdo, 0, 0,

ggplot alpha levels appear different on fill and border of points (ringing artefact)

元气小坏坏 提交于 2019-11-30 04:59:28
问题 I am plotting many points using ggplot with a constant transparency value for all points. What I find is that the circular points have a more transparent fill than their individual border, so that the borders are noticeably brighter than their fill (I'm plotting light circles on a dark background), i.e. there seems to be a ringing artefact. The effect is that they look like rings rather than semi-transparent circles. library(ggplot2) set.seed(123) data <- data.frame( x = sample(1:100,2000,

View with low alpha - Subview with high alpha

こ雲淡風輕ζ 提交于 2019-11-30 03:12:38
I have a UIView with an alpha of .5 I have added a subview with an alpha of 1. The subview seems to inherit the alpha value of the parent. Is there a way to make the subview more opaque than its parent view? code looks like this: CGRect promptFrame = CGRectMake(55, 80, 180, 50); UIView *inputPrompt = [[UIView alloc] initWithFrame: promptFrame]; [inputPrompt setBackgroundColor: [UIColor darkGrayColor]]; [inputPrompt setAlpha: .5]; inputPrompt.layer.cornerRadius = 8; inputPrompt.layer.masksToBounds = YES; CGRect fileTextFieldFrame = CGRectMake(10, 15, 150, 25); UITextField *filePrompt = [

Resize images with transparency in php

梦想的初衷 提交于 2019-11-30 02:59:23
问题 I have looked all over for how to correctly manage alpha when I'm resizing a png. I've managed to get it to keep transparency, but only for pixels that are completely transparent. Here's my code: $src_image = imagecreatefrompng($file_dir.$this->file_name); $dst_image = imagecreatetruecolor($this->new_image_width, $this->new_image_height); imagealphablending($dst_image, true); imagesavealpha($dst_image, true); $black = imagecolorallocate($dst_image, 0, 0, 0); imagecolortransparent($dst_image,

Alpha masking in c# System.Drawing?

。_饼干妹妹 提交于 2019-11-29 22:25:43
I'm trying to draw an image, with a source Bitmap and an alpha mask Bitmap , using the System.Drawing.Graphics object. At the moment I loop X and Y and use GetPixel and SetPixel to write the source color and mask alpha to a third Bitmap , and then render that. However this is very inefficient and I am wondering if there is an faster way to achieve this? The effect I'm after looks like this: The grid pattern represents transparency; you probably knew that. Yes, the faster way to do this is to use Bitmap.LockBits and use pointer arithmetic to retrieve the values instead of GetPixel and SetPixel