Handling inverted pixels in bitmapData and bitmap class in as3 - apache-flex

I am using bitmapData and bitmap classes to render a mouse cursor on the display screen. The bitmapData consists of an area whose colors should be inverted according to the background color. This is a very basic thing which could be observed with text cursor(the vertical line with two small horizontals on top and bottom), when moved over the text area.
I want to be able to do the same with the pixels in my bitmapData, is there a way to find out the background color effectively and invert the color values?
In this process i will be redrawing the whole pixels, is there any other efficient way to do that ?

You can draw your cursor using BlendMode.INVERT
http://livedocs.adobe.com/flex/3/langref/flash/display/BitmapData.html#draw()
or simply put your cursor display object over your bitmap and set it's blendMode to INVERT.

Related

How to blit two transparent frame buffer objects using QOpenGLFramebufferObject?

I have two FBOs created using QOpenGLFrameBufferObject, which are images with a transparent background and some lines and text on top of them. I am blitting the first fbo onto the second using QOpenGLFramebufferObject::blitFramebuffer, this results in the content of the first fbo on top of the second. However, I would like to preserve the transparency of the the first fbo and blend the content of the first fbo on top of the second fbo (instead of erasing the portion of the second fbo and redrawing the first fbo on top of it). Looking around, I think this might be possible with glBlendFunc, but the following didn't really achieve the result I wanted.
glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
// then blit fbo1 on top of fbo2
QOpenGLFramebufferObject::blitFramebuffer(fbo2, fbo1);
How can I preserve the transparency (by blending them together) of my framebuffers when I blit them?
You can't glBlitFramebuffer is a copy operation, and does not blend the source and target fragments.
A possibility is to render to a texture (see Framebuffer Object - Attaching Images). Finally you can render a screen space rectangle and Blend the texture with the target framebuffer.

How to make a round WKInterfaceButton in watchkit?

iOS can use layer.cornerRadius to make a round UIButton.
Does WKInterfaceButton have this property?
If not, how can I make a round WKInterfaceButton in WatchKit.
If you put an image inside a group, you can then set the radius of the group. This crops the image into a circle. In the picture below, I have:
Group (radius 56)
Group (radius 52)
Image (a square image)
While this example is with an image, you can use the same technique for a button. Previously the dog was clickable as a button so this is doable.
WKInterfaceButton does not have a corner radius property. You can make a circular button by setting a circular image as the button's background image. You can generate the image in code doing something like this: Draw a simple circle uiimage
You don't need an image to make WKInterfaceButton rounded. Instead:
Go to Attributes inspector for the button, and select content type: Group
Inside the button find the group and set its corner radius to whatever you need.
Scroll down the inspector and set both fixed Width and Height to the value equal to the radius doubled. Here you go
You can put whatever you want inside the button, for example a text label. This way you also can make oval buttons.

BitmapData with Scale9Grid

I have a Skin for SkinnableContainer.
Skin contains only the original contentGroup and s:BitmapImage as background.
Background image stretchers out according to width and height content.
The used image is .png with transparent regions.
To create hitarea, I used this algorithm:
http://www.webverwirklichung.com/en/blog/programming/flex/creating-hitarea-png-image-transparent-alpha-regions-flex
Everything's working fine until I start to stretch the SkinnableContainer (along with the image in the skin).
I have a scale9Grid for the image.
The problem is, that when stretching the image, the bitmapData of the image is still the same (same width and height). Therefore I need to somehow obtain the bitmapData of the image for the scale9Grid application.
The background of the component is an image, which has some transparent areas. It is only possible to click on the visible part of the image. The image will stretch according to the content in contentGroup.
Need an advice, please.
How about using the BitmapData.draw() method?
After the container is resized and the 9 slice scaling has been applied (or whatever the appropriate trigger is) do:
var b:BitmapData = new BitmapData(container.width, container.height);
b.draw(container);
Then use this new bitmap with the algorithm that creates the hit area.

QGraphicsView background

Hi i'm trying to get a photoshop-like behaviour for my QGraphicsScene
The grid in the background should not resize with the call of scale. And I must be able to save the picture with QPixmap::grabWidget(view) but without the background grid. I can probably do it with removing the background layer just before saving the picture, but i'm not sure if its cleanest way to do it.
Any ideas ?
thx.
Question 1
The grid in the background should not resize with the call of scale.
Use the QGraphicsItem::ItemIgnoresTransformations flag.
The item ignores inherited transformations (i.e., its position is
still anchored to its parent, but the parent or view rotation, zoom or
shear transformations are ignored). This flag is useful for keeping
text label items horizontal and unscaled, so they will still be
readable if the view is transformed. When set, the item's view
geometry and scene geometry will be maintained separately.
In order to set this flag use the setFlag function when creating the grid item.
Question 2
I must be able to save the picture with QPixmap::grabWidget(view) but without the
background grid.
Call the hide function on the grid item before calling the grabWidget. After you have grabbed it you show it again by calling the show function.

How can I manipulate shapes in Adobe Flex?

I'm working on an application where I'm drawing some rectangles on the screen, and then will need to manipulate the shapes (change their size, location). I tried to do something with .drawRect and clearing the shape each time I was manipulating it, but the RAM usage was spiking and then falling (presumeably because i keep reinitializing a new component and then removing it, and garbage collection was cleaning it out). This seems like its probably not the most efficient way to do it.
Is there a way for me to just create a shape once, and then move it around on a canvas (and change its width and height without all this RAM usage?
If all you're doing is changing it's offsets, and adjusting it's width and height without needing to fundamentally change the structure of the shape (such as rounding the corners of a rectangle of some such) you should be able to just maintain a reference to the Shape and adjust it's x, y, scaleX, scaleY properties to effect the changes.
You can try Degrafa to draw the rectangle.
To move the rectangle:
Changing the x and y or height and width property of the shape
Using the Flex Move Effect

Resources