Clox answered my question of how to display huge graphics (e.g. greater than 8191 pixels).
I have the code to copy parts of a huge loaded BitmapData to a target BitmapData that is just the size that I can display.
I think I have set the scroll bars of an enclosing Canvas to show the size of the larger image and allow the user to scroll.
Now I need to put the selected pixels on the screen. When I try to add a Bitmap component as a child of the Canvas, it get an error because Bitmap is not a UIComponent.
What's the best way to put the target BitmapData into an Image component?
How else can I get the subset of pixels on the screen?
To display a BitmapData object use the Bitmap class. Then you can set the bitmap as the source of an image.
var imageBmp:Bitmap = new Bitmap(myBitmapData);
var displayImage:Image = new Image();
displayImage.source = imageBmp;
myCanvas.addChild(displayImage);
You could also draw the pixels of your bitmap data directly onto the Graphics object of the Canvas using beginBitmapFill.
var g:Graphics = myCanvas.graphics;
g.beginBitmapFill(myBitmapData);
g.drawRect(0, 0, myBitmapData.width, myBitmapData.height);
Related
I'm using paper.js to place an image on a paper.js canvas. I then copy that canvas's dataURL to create a new canvas. When I do so unless I hard code the position of the raster, it ends up in the wrong position, but drawn paths are in the correct position. Working codpene here
If I use paper's raster object syntax:
var image = new paper.Raster({
position: paper.view.center
})
It has no effect.
If I use paper's raster object syntax with a hard coded position it corrects the positionioning:
var image = new paper.Raster({
position: new paper.Point(400,600)
})
The image is corrected. Thanks in advance
Earlier last week I created a window in Python that resized the main window to the dimensions of the background image. I wanted to do the same in QT. I've managed to figure out the syntax to resize the main window through its constructor.
this->setFixedSize(QSize(600, 600));
I'm curious how I might now set the width and height parameters to the same parameters of an image in the resource file. I was thinking something like this:
QGraphicsPixmapItem image(QPixmap("url(:/images/background.png);"));
int x = image.width
int y = image.length
this->setFixedSize(QSize(x, y));
edit:
In summary, I want to resize the main window to the same dimensions of an image file which so the window wraps around the background image. According to this post I have to parse the image header to read the dimensions... sounds too complicated. Is there a third party library?
Instead of using QGraphicsPixmapItem use QImage to get the size of your image.
QImage image(":/images/background.png");
if(!image.isNull())
setFixedSize(image.size());
else
//loading the image failed, show some error message or something
Have you tried to adjustSize , after setting to new ?
this->setFixedSize(QSize(x, y));
this->adjustSize();
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.
I have a flex video capturing mobile application that attaches its camera to a UIComponent as follows:
var camera:Camera = Camera.getCamera();
camera.setQuality(0,100);
video = new Video(width, height);
video.attachCamera(camera);
var uiVideo:UIComponent = new UIComponent();
uiVideo.width = video.width;
uiVideo.height = video.height;
uiVideo.addChild(video);
videoGroup.addElement(uiVideo);
*width and height are the mobile's screen size.
The problem with the above code is the video/camera the user sees when recording is zoomed-in when compared with the recorded video. That happens probably because, a camera with dimensions 20x30 is streched to a screen size of 60x90, thus resulting in a zoom of 3x.
How can I avoid that?
Is there a way to strech a camera to fill the mobile screen without zooming-in (distortion is okay, when the screen's ratio is different from the camera's ratio)?
Have you tried Camera.setMode()? You can pass in width, height, frames per second, and a 4th parameter. If the camera does not support that resolution you specify, it will try to use a supported resolution that is similar.
Here's my problem, I need to scale and clip images into square sized tiles to put into a tile list. Here's how I want it to work:
I want all my tiles to be, say, 300px x 300px.
For each image, I want to scale the shorter side (either width or height) to fit in the tile using the "letterbox" scaleMode (so that it maintains aspect ratio).
Then I want to position the image in the center and clip away anything left over from either both sides or the top and bottom.
Here's an example to help clarify:
I have an image with width=600px and height=1200px. First I want to scale the image to width=300px and height=600px (notice that aspect ratio is maintained), then center the image vertically and clip the image to 300 x 300.
Is this possible? This is actually a pretty standard way of displaying square thumbnails in many photo-based web sites, but I can't find a way to make it work in flex.
Any help would be appreciated, thanks!
UPDATE JUNE 2012:
Just in case anyone finds this thread now, this issue has been resolved in the latest version of the Flex SDK. On the spark image object there is a new scaleMode of "zoom" which does exactly what I've asked for here.
Take your big image and draw it on BitmapData with scale and reposition:
const zoom:Number = Math.max(THUMB_WIDTH/image.width, THUMB_HEIGHT/image.height);
const x:int = (THUMB_WIDTH - image.width*zoom)/2;
const y:int = (THUMB_HEIGHT - image.height*zoom)/2;
var matrix:Matrix = new Matrix;
matrix.scale(zoom, zoom);
matrix.translate(x, y);
var _thumbBitmap:BitmapData = new BitmapData(THUMB_WIDTH, THUMB_HEIGHT, false, 0xFFFFFF);
_thumbBitmap.draw(image, matrix, null, null, null, true);
Then assign resulting BitmapData to the source of the BitmapImage.
More: http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/display/BitmapData.html#draw%28%29
http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/spark/primitives/BitmapImage.html#source