Applying tint() on a BufferedImage in processing - processing

I'm grabbing visual screen contents with the Robot Class which I'm then trying to set to half transparency. I'm following the reference for the tint command like so:
screenshot = robot.createScreenCapture(new Rectangle(0,42,scrdim.width,36));
shot = new PImage(screenshot);
shot.resize(32,1);
tint(255,127);
image(shot,5,5,64-5,4);
But as soon as I use the tint command the image disappears completely, regardless of the actual aplha parameter value. Is it, because it because I'm dealing with a BufferedImage? I've been trying to figure out how to set the alpha of that directly, but with no luck.

Your transparenvcy currently is 100%.
The syntax for tint is:
tint(color, transparency);
Simply invert your tint color for 50% transparency:
tint(255, 127);

Related

Can I change the background of a smallbasic graphics window to an image?

I know that to change the background colour of a graphics window in SmallBasic you can use this:
GraphicsWindow.BackgroundColor = "Green"
But is it possible to make the background an image from my computer?
Thanks.
Sure! The simplest way of doing that would be to just draw an image on the graphics window at position 0, 0 (top left):
GraphicsWindow.DrawImage("Path/To/Image.png", 0, 0)
You may also want to resize either the image, or the graphics window to make their sizes match:
GraphicsWindow.Width = imageWidth
GraphicsWindow.Height = imageHeight
Zock77 has a good way to do this without any extensions, but if you want the image to resize depending on the size of the window, to make it feel more like the background really is the image, you can use the LitDev extension and the LDGraphicsWindow.BackgroundImage(imageListImage) command. Here is the code you could use:
image = ImageList.LoadImage("filepath")
LDGraphicsWindow.BackgroundImage(image)
The first line gets an image from a file and saves it to the image variable.
The second sets the background image to the image.
If you don't want to download litdev then use Zock77's method as it is the best alternative to Litdev.
Hope this helped!
CodeAlong

Windows button ignores alpha channel for fully transparent image

I have a radio button that should display an image (style BS_AUTORADIOBUTTON|BS_PUSHLIKE|BS_BITMAP).
I create a bitmap via CreateDIBSection (using a BITMAPINFO with BI_RGB) and obtain a pointer to the raw pixels via the ppvBits, so that I can manipulate them freely.
I use BM_SETIMAGE to set the button's image to the bitmap I created.
So far, I can set the RGB and alpha by manipulating the pixels by hand. I tested that even semi-transparent (non-premultiplied) alpha values look good.
As far as I can tell, everything works, except if all pixels in the image are transparent. In that case, the button apparently ignores the alpha value, simply displaying a rectangle with each pixel having the respective color with full opacity.
I found a hint that Windows - at least in some cases - actually seems to interpret images whose pixels' alpha values are all 0 as completely opaque images:
When the window manager sees a 32bpp bitmap, it looks at the alpha
channel. If it's all zeroes, then it assumes that the image is in 0RGB
format; otherwise it assumes it is in ARGB format
Is this behavior documented somewhere?
Is this behaviour documented somewhere?
Yes! In Raymond's post! :) That's often the way of it, no?
If you look at the foot of the page here you will find a comments box. If you raise your concerns there then MS will most likely fix their documentation. See here for an example of the process they usually follow if they consider the problem serious enough to fix.

Access Default Window Color Cocoa

I have an SKView with a picture of a keyboard in a window as shown below. I would like the background color of the SKScene it's presenting to be the same color as the window behind it, so that it would appear as if the keyboard was just in the window, and not in something else that was in the window. After consulting the NSColor documentation, I tried setting the background color of the SKScene as NSColor.windowBackgroundColor(). The color below is what I got. I'm assuming there was some kind of error and so it defaulted to black. That being said, how do I access the default color of a window?
Set the SKView's allowsTransparency to true and then set the SKScene's backgroundColor to NSColor.clearColor().
I think that using windowBackgroundColor() gives black if the view doesn't allow transparency and works if it does because it's effectively being translated to clearColor() by "accident". windowBackgroundColor() is a bit strange. It's not in either an RGB nor a gray-scale color space and it can't be converted to either of those. I'm guessing that SKScene tries to convert the background color to the RGB color space and, when that fails, it uses clearColor() as a fallback.

Delphi PNGImage - Image transparency is not pure

I am using PNG images as main image resource in my application. Since im using Delphi 7, i downloaded PNGImage lib and included it in project. I load images like this:
Form.image.Picture.LoadFromFile(PAnsiChar('\background.png'));
Image has transparent and semi transparent pixels on its border. The problem i get is that transparent pixels are filled with random zoomed part of my desktop with currently opened windows, while i expected to see what is actually located beneath form.
Additionally, form has this properties:
BorderStyle: bsNone;
TransparentColor: true;
Visible: false;
Here is a picture of current state (above black line) and desired:
Can this be fixed somehow or it is how delphi deals with transparency?
To have the form "shade" what's beneath it, use the forms AlphaBlend and AlphaBlendValue properties. The .png image doesn't have to be partially (alpha blended) transparent, but it can be.
If you want the form to be semi-transparent you use Alphablending, that's a limitation of Windows. In addition you can have a certain color fully transparent. In the following sample the forms color is clGray, which is also defined as the Transparent color property in addition to the Transparent property set to True. The image, aligned alClient, is 50% transparent, placed on a TImage which is set as transparent, but even so, it doesn't show up as semi-transparent unless you have AlphaBlending on. Again, this is a limitation of Windows. The best you can do is try with a fairly high value for AlphaBlendingValue (240..250) and a rather light image to find the right compromise.

Why does graphics.clearRect change its behaviour?

I was on the way of making a picasa like photo viewer and later an image editor.i used JFrame and alpha channel to set background transparent.but while moving or zooming in/out ,as i had to draw it on different location and clear the previous image i used clearRect and faced the problem.
the oracle documentation says it clears the rect and restores the background color.
on some trials the clearRect clears the area to background color.But while continuous events like mouse-dragging its turning the color of cleared area to black and causing this:
`
thnx
.i used JFrame and alpha channel to set background transparent.
Don't use alpha for complete transparency. Instead just use:
panel.setOpaque( false );
If you are using semi transparency then check out Backgrounds With Transparency. It will explain the problems with transparent background and provide a couple of solutions.
The basic problem is that transparency breaks the painting contract with Swing components because the background is not cleared entirely before child components are painted.

Resources