I have a QML based app which shall provide basic image editing. I have implemented cropping, and now I would like to add the effects provided by QtGraphicalEffects. I have added the effects to the QML, and added corresponding sliders, so I can add the effects to my image, which works well.
However, my question is, how I would be able to save those effects back to the image file? The problem is, that I am scaling down the image to fit the screen dimensions, therefore, saving directly from the QML / javascript would result in a shrinked image.
For the cropping part I have solved this by doing the cropping in C++, and re-opening the original image unscaled, and applying the cropping to the original image.
Could I do something similar in QML? E.g. when a save button is pressed, render the original image again in original size (off-screen, so its not visible), apply the effect, then save it? Is this possible?
You should be able to use an unscaled Image that has Item::visible: false, render all of the effects, and then use Item::grabToImage on the resulting rendering to save the result.
You can use Image::implicitWidth and Image::implicitHeight to get the native height and width of the original Image (before scaling).
Related
I have created a react app Which is very similar to office whiteboard. I would like to generate a thumbnail or card preview of each whiteboard and wondering how to go about it.
My initial thought was to just create a card component and render the shapes to that the same way I do for the real whiteboard. However, the points for each shape will be outside the stage and I can't think of how I can scale it down.
Any ideas?
Take a look at the official canvas thumbnail demo from Konva.
You can use a similar approach with react-konva.
Create a special component for the preview.
I think this approach will work better and probably more performant (depending on your app). You just need to create another Stage and draw all objects into it. It will be better if you can draw simplified versions of the shape, because the drawing is much smaller, so not all details are visible.
You will have to calculate your own scale ratio.
Use image preview
Instead of making a full components tree for the whiteboard, you can just export the main stage into an image and show it. You have to do reexport from time to time.
I'm working on a report with some coworkers in Google Docs (which will eventually be printed). We want to include some plots generated with ggplot. As we edit the document, the space for the images keeps changing slightly--often, we need to resize and/or change the aspect ratio of a plot slightly so that it fits on the page with the accompanying text.
Is there a way to export a ggplot object to an image that is resizable in the same way that plots can be resized in the Export dialog in RStudio?
Google Docs does not support SVG images--dropping an svg on the page simply opens the SVG itself (rather than adding it to the doc), so that's not an option.
I would like to be able to take screenshots of my program and save them as png (or if it is possible as pdf). I have taken the screenshot-example from Qt. This takes a screenshot from the whole display. But I would like to take a screenshot from only a part of my window, even if it is in another postion of the display. How can I do that. Is there a function?
The static function grabWidget of QPixmap is your friend. You can easily take a pixmap of the provided widget and then save it in any format you desire:
QPixmap p = QPixmap::grabWidget(widget);
p.save("p.png");
What about QWidget::render (http://doc.qt.nokia.com/4.7-snapshot/qwidget.html#render)?
Examine the window to get it's position and size. If you have any specific element you want to see in the screenshot, you can get it's position and size instead. Otherwise, you'll have to use offsets from the window position which can cause trouble (for example, when the window is resized).
Get the screenshot and then crep the pixmap using the position/size from before.
There is one drawback: Taking a snapshot of the whole desktop is somewhat slow.
So a better solution might be to change your application: Render the parts you want to save in an off-screen buffer. You can then use this buffer to render the UI and save the screenshot at the same time.
I'm scaling my application to fit the browser window. I'm also defining my own cursor using a bitmap and CursorManager.setCursor.
The problem: when my app scales, the cursor bitmap is jagged. Is there a way to smooth the bitmap that is use?
I believe your problem is that you're scaling your root display object(e.g., stage), which means the cursor also gets scaled. You probably want to scale a child container instead, which means the cursor won't scale. I'm guessing you don't want the cursor to change sizes anyway.
Otherwise, you can look at using an svg file (or a swf image) since they're based on vectors and scale properly. You can also look at trying to smooth the bitmap using the bitmapData draw function. (http://livedocs.adobe.com/flex/3/langref/flash/display/BitmapData.html#draw())
I have a Flex component with a background image. The image is sharp in the beginning, but is jagged whenever I scale the component using scaleX and scaleY. How would I make the image anti-alias so that, it it's scaled to 0.75, the lines are smooth, not jaggedy?
Here is the image
Here is the scaled version
And the unscaled (good) one
If you load the image with an Image component, you can cast the content property of the component to a Bitmap and then set smoothing to true. Unfortunately, the image component doesn't provide this functionality out of the box. However, it's rather easy to hack in.
Here is a tutorial to show you how to create such a component:
http://www.adobe.com/cfusion/communityengine/index.cfm?event=showdetails&productId=2&postId=4001
However, if this is set using the backgroundImage style of a component, you just might be out of luck unless you override updateDisplayList and perform the drawing of the bitmap yourself by using Graphics.beginBitmapFill (which does provide smoothing support).
Why smoothing of images doesn't have better support (such as different interpolation methods) in Flex (and subsequently, Flash) boggles my mind. At least pixel bender filters will help a bit by letting us implement such filters ourselves.
If the dimensions of your Bitmap are both either n^2 or n^8, then the Flash player will automatically use a technique called mip-mapping that will dramatically improve the look (and performance) of scaled bitmap images.