I would like to capture the entire contents of a window, not just the visible portion, as a bitmap. What I've been able to do only captures what is currently visible:
var v:UIComponent = ...
var bd:BitmapData = new BitmapData ( v.width, v.height );
bd.draw(v);
var pixels:ByteArray = bd.getPixels(bd.rect);
I realize using the v.width and v.height will only get the visible part. But I need the entire graphic extent (that which is scrollable).
Any help would be appreciated?
You can maybe try not to copy the window pixels but its content pixels : if that content is scrollable, there's chances that the window uses a mask or any similar method to hide everything that's outside of its dimensions.
But by trying to draw its content directly (if you have a v.content method or anything likewise) you should be able to have its real sizes and thus draw it in its entire.
Keep us updated if that works ?
Related
I am using opencv to show an image. The problem is that the image is large so it is bigger than my huge display.
Is there a way to show this image AUTOMATICALLY resized to fit in my screen?
Please note that many of the answers to similar questions here fall under two categories:
They suggest the use of an option in the namedWindow function, but this does not solve the question (I tried and also read carefully the documentation, it never claim it does solve this question)
Use resize to manually resize the image. Not automatically. But then how can I know the values to resize?
EDIT: I have been asked to report my claim that WINDOW_NORMAL does not solve the problem. I have right in front of me a script in which first I just do
cv.imshow("window",image)
cv.waitKey()
and then the same script with
cv.namedWindow("window", cv.WINDOW_NORMAL)
#image = cv.resize(image, (960, 540))
#image = cv.resize(image, (1280, 800))
cv.imshow("window",image)
cv.waitKey()
The results are the same. The window is as Huge as always.
Now let's see the docs
Parameters:
name – Name of the window in the window caption that may be used as a window identifier.
flags –
Flags of the window. The supported flags are:
WINDOW_NORMAL If this is set, the user can resize the window (no constraint).
WINDOW_AUTOSIZE If this is set, the window size is automatically adjusted to fit the displayed image (see imshow() ), and you cannot change the window size manually.
WINDOW_OPENGL If this is set, the window will be created with OpenGL support.
As you can see it clearly says the user can resize the window (no constraint) and in no part it says AUTOMATICALLY
so it does not address the problem of this question
You can try and use the following library to obtain the X and Y values of your display:
import pyautogui #pip install pyautogui
x = pyautogui.size()[0] # getting the width of the screen
y = pyautogui.size()[1] # getting the length of the screen
print(x,y)
Similar to what Dimitar Veljanovski posted (Thanks!) I did this like this. It is not automatic and it does not occupy the whole screen but I have not received an answer to this
h, w, c = image.shape
cv.namedWindow("window",cv.WINDOW_NORMAL)
image=cv.resize(image, (w//3,h//3))
cv.imshow("window",image)
I'm using the dreded AS2 (not by choice) and working with images externally loaded.
I know that
targetClip.forceSmoothing = true;
...exists, but it still doesn't seem to be doing much at all.
The images externally loaded are really big in dimensions and when made smaller in the flash, they pixelate.
Perhaps forceSmoothing is the best method but...
I'm thinking there may be a way to resave the external bitmap resized and use that, instead of resizing a bitmap as a vector.
Any ideas?
Also, I've got an AS3 version of this, so if you know how I can do it in that too, then great. But it seems they do not want to use that yet.
in as2:
add this class to your project BitmapLoader
and use like that:
var loader : BitmapLoader = new BitmapLoader(true);
loader.addListener(this);
loader.loadBitmap("http://foo.tr/example.jpg", this, "doneLoading" );
in as3 :
var loader:Loader = new Loader()
loader.load(new URLRequest("1.jpg"))
loader.contentLoaderInfo.addEventListener(Event.COMPLETE,doneLoad);
function doneLoad(e:Event){
var bitmap:Bitmap = e.target.content as Bitmap
bitmap.smoothing = true
}
How are you loading the image data? If you're doing it with the BitmapData class, you can use a matrix together with the scale() command to shrink it.
http://docs.brajeshwar.com/as2/flash/geom/Matrix.html
http://docs.brajeshwar.com/as2/flash/display/BitmapData.html
First of all, I would like to say that I'm fairly new to AS3, so feel free to correct me when needed.
So I'm trying to create a moving background, made out of different types of isometric tiles, like a floor or a wall, disposen in a grid like fashion.
At first, I tried creating a symbol containing the floor and the wall on different frames, and alternate between the frames as needed. Then I would add multiple instances of this symbol to a container and move the container around. Quickly I realized that this probably wouldn't be an ifficient method, as confirmed by the unsmooth movement of the container. (I gave up on this method).
So I did a little digging around, and then I converted the tile symbol to a png file, created a bitmap container to where I would copyPixels from the png as many times as the map required it.
The problem now is that when I do this:
var pngBitmapData:BitmapData=new tilePng
the bitmapData height and width don't match the height and width of the actual tile. There seem to be some transparent pixels around the tile and I have no idea how to remove them. This causes the tiles to be misaligned on the background's grid, with some small empty spaces around them.
So I have a couple of questions:
Is this an effective way to build the background?
Is there a way to avoid that transparent pixels "problem" ?
Hmm, it's hard to tell without seeing your png.
Are you doing this?
var pngBitmapData:BitmapData = new tilePng();
var bmp:Bitmap = new Bitmap(pngBitmapData);
To initialize your bitmap?
Also, check the anti-aliasing on your bitmap, that could be it. I'd set it to none.
I am making an interactive storybook project given these specifications:
My book has 13 pages, where 1 page = 1 swf loaded externally into the book swf. As you can see, the page swf must be centered in between the 2 buttons that are both 100x450 each. Whenever I try to load the swf, usually it's cut off at some point.
In short, how do I center my externally swf when loaded?
Make the completeHandler Function like given bellow
function completeHandler(event:Event):void{
this.container.addChild(event.target.content);
this.container.x = this.stage.stageWidth/2 - event.target.width /2;
this.container.y = this.stage.stageHeight/2 - event.target.height /2;
}
U can change this.stage.stageWidth with the center container width and apply same for width also
The advice gyandas gives is good. However, from the way you've worded your question I'm guessing you're already doing something along the lines of what he suggests. If so, you could try adding a filled shape of 520x450 as the background of each of your pages. You can set the alpha to 0 or match the background color of the book itself, but the important thing is to have some actual content of the required dimensions rather than relying on the supposed width of the SWF when centering it in another movie.
I'm not in a position to test this right now, but I seem to recall that the dimensions of a loaded SWF are calculated according to the bounding box created around actual content, and that I have resorted to doing this as a result.
I'm using a canvas to load a background image, and then, using jQuery UI, I call the droppable() function on the canvas and draggable() on a bunch of PNG images on the screen (that are not in the canvas). After the user drags one or more images on the canvas, I allow him to save the contents to a file using the following function:
function saveCanvas() {
var data = canvas.toDataURL("image/png");
if (!window.open(data)) {
document.location.href = data;
}
}
This successfully open another window with an image, that sadly contains only the original background image, not the dragged images. I'd like to save an image presenting the final stage of the canvas. What am I missing here?
Thanks for your time.
You've got to draw the images to the canvas.
Here is a live example:
http://jsfiddle.net/6YV88/244/
To try it out, drag the kitten and drop it somewhere over the canvas (which is the square above the kitten). Then move the kitten again to see that it's been drawn into the canvas.
The example is just to show how an image would be drawn into the canvas. In your app, you wouldn't use the draggable stop method. Rather, at save time you would iterate through the pngs, drawing them on to your canvas. Note that the jQuery offset() method is used to determine the positions of the canvas and images relative to the document.
You are saving the final state of the canvas. You have images atop the canvas and the canvas has zero knowledge of them.
The only way you can save the resulting thing you see is to, before you call toDataUrl, you must call ctx.drawImage with each of the images and actually draw them to the canvas.
Getting the right coordinates for the call to drawImage might get tricky but its not impossible. You'll have to use the pageX and pageY coordinates of the image, probably, and then draw them onto the canvas relative to the canvas' own pageX and pageY.