I am putting together an image gallery that displays a preview of the image. For most of the images this is no problem, only when the image is an animated gif the image is animated as well, which in this case is not necessary.
What I would like to do for an animated gif is to just display one frame of the animation.
While searching for a solution I have come across this.
GifDecoder d = new GifDecoder();
d.read( filename);
WritableImage wimg = null;
Image img = SwingFXUtils.toFXImage(d.getFrame(0), wimg);
But first of all this seems to be too much overhead and a quick test so far ended in a NullPointerException due to the fact that d.getFrame(0) returns null.
I was thinking that there must be an easier way, like some property on the Image to avoid animating the image, or as an alternative approach not displaying the image in an ImageView.
There were two reasons the GifDecoder did not work.
The first one was really my mistake, as the String passed to the read method should be an URI:
File f = new File(filename);
d.read(f.toURI().toString());
The second issue lies with the GifDecoder: To check the input URI it is converted to lower case and that converted String is then used to create in InputStream. This works on an OS that is not case sensitive (like Windows) but not on NIX based systems. I therefore had to fix that and now it is working.
Related
I have a template in which I'm attempting to change the source of a picture from Image 1, to Image 2 - yet I want Image 2 to keep the original size it was uploaded to the server in. (I want it in the position of Image 1, but its own dimensions.)
To do this, I figured I needed to use the adjust parameter - which I have attempted. The description for adjust=100% is "The picture is adjusted to be proportional to the original size." - which sounded like what I needed to do.
However, in my docx output, this seems to set the image size to be 100% of page width, rather than related to image size. (In the word image properties, it shows my image to be 208%, so I don't think it's related to my file!)
Is this a bug in opentbs, or have I misunderstood the docs? If so, how should I be doing it, or otherwise, can anyone thing of a work around? I attempted not using adjust at all, however that seems to have the same behaviour as adjust=inside - which I presume is the default.
With the normal thanks for a great tool!
Edit: The Error causing tag is below. I've found the problem reproducible when starting from nothing, and with just an image in the word doc. Word 2010, OpenTBS 1.8.
[onshow.logo;ope=changepic;tagpos=after;adjust=100%]
The problems was caused by the TbsPicAdjust() function expecting the image's dimensions to be provided in points, rather than pixels, as php's getimagesize() function was returning.
It was solved by replacing the two fixed coefficients in the TbsPicGetDim_OpenXML_dml() function with 9,525, rather 12,700 as they were originally coded. (Which would be an appropriate value, if the dimensions were in points, rather than pixels.)
After some research, from what I can see, getimagesize() always returns a size in pixels rather than points, so it looks to me like this could be a potential bug?
Additional Source for coefficient, combined with personal calculations: http://openxmldeveloper.org/discussions/formats/f/15/p/396/933.aspx
Workaround:
It depends if you are using the new (.docx) or old (.doc) style of document. If you have the newer style, I don't know for sure that you can change the image size without putting the tag directly into the XML. The older (VML, I believe) style uses <v:shape> to describe a picture rather than <pic:pic>. With v:shape, you can just put together a CSS-style string that describes the size, etc. of your image. Something like:
$imgStyle = "position:absolute;left:0;top:0;width:800;height:600"
Then you just have a tag next to your changepic tag; something like:
[imgStyle;att=v:shape#style]
The newer style does not use a style string like this to size and position images, the pic:pic element is full of nested tags describing the image so it is harder to get to the details (though you could certainly try). I ended up creating a subtemplate for my image switching because my template is in the new format with compatibility for the old format (so I have to maintain two image blocks). This allows me to maintain the XML directly for the image dimensions, but still be able to edit my main template in Word. I just use a tag in my main template that includes the subtemplate like:
[LineItem.template;block=w:r;file='img.xml']
Separating the manually controlled XML out allows me to edit the main template in Word without damaging the really custom parts. Using this technique though, you may have some trouble with onload/onshow tags in the subtemplate - everything I change in the subtemplate is controlled by a block.
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 have a flex application and am trying to show some animated vector shapes on a google map. To do this I load an external SWF (the content is dynamic, so I have to load at runtime and SWF was the only loadable format supporting animation AFAIK) and place it on the map using an overlay.
I then need to control the alpha of the SWF. Setting it is straightforward, but for some reason the alpha appears to be applied to the sub-shapes inside the SWF, and only after that is the image composited onto the map. This makes the yellow blob that is on top of the green blob appear yellow-green rather than just yellow.
I need to somehow tell flex/flash to "render/flatten the SWF, then apply the alpha", rather than "apply the alpha to the individual sub-shapes, then flatten to the map". Ideally without going via e.g. a BitmapData object or similar.
The containment hierarchy is Map -> BlobManager -> Loader -> Loader.content (the SWF) and I've tried applying the alpha to the BlobManager, Loader, and Loader.content separately, but no difference. I've tried cacheAsBitmap on the lower layers and then applying alpha higher up to no avail.
Any suggestions for what to try next? Thanks!
Try BlendMode.LAYER, it saved many lives.
I don't think you can do that without drawing the loaded content on a Bitmap and using that to display with alpha.
It is quite easy though, although you might run into security violations if the loaded content is from another domain and won't let you create bitmapData from it.
// content is the loaded external swf, or the Loader itself?
var bitmapData:BitmapData = new BitmapData(content.width, content.height);
bitmapData.draw(content);
var bitmap:Bitmap = new Bitmap(bitmapData);
bitmap.alpha = .5;
addChild(bitmap);
It may not even be necessary to display the loaded content (although I haven't tried that) and you can also take only part of it to use as bitmapData using a Matrix.
EDIT: for animation, another option is to load an animated gif as described here: http://www.bytearray.org/?p=95 (I have no experience with it so I can't say if it'd really work for you), or use video.
I have created a image cropping tool in flex using core copyPixel method.
croppedBitmapData.copyPixels(croppedBitmapData, clipCan, new Point(0, 0));
I have to crope area of dementions 20*20 and show this cropped area in an image of demention 250*350.
Every thing going well.
My problem is image distortion.
Even i am using this method for smoothing image contents on complete.
private function smoothImage(event:Event):void
{
var bitmap: Bitmap = ((event.target as Image).content as Bitmap);
if (bitmap != null)
{
bitmap.smoothing = true;
}
}
I want to get the result of this site. http://www.yourplayingcards.com/builder/
Please help me to get ride of image distortion.
Can we show bitmapdata of 20*20 into image of 250*350 without distotion?
What you call 'distortion' is probably what I think you mean by pixelation. The reason why that website can zoom in without pixelation is because it's using vector shapes, not bitmaps, to show the graphics. Vector shapes can be scale infinitely without loss of quality because it doesn't store pixel information, but spline information.
In essence, if you want to imitate the zooming of the the website you have shown, you will have to create your own vector shape. You can use Flex 4's built in FXG format or use something like Degrafa if you're still in Flex 3. You can also leverage Flash Catalyst to import vector graphics made in Illustration into Flex.
I am not sure about that but it is done in VectorMagic may be they are using server side too any ways, you may also interested in Actionscript SVG renderer
Hopes that helps
I have an image that I use many times. In several cases I want to shrink its size, but obviously it loses sharpness when I do this in HTML.
Is there a way to fix this? The image is located elsewhere and I can’t save it locally.
Thanks
As dheerosaur states, SVG graphics can be used when you need to have the same image in multiple sizes but don't want to compromise quality.
Another thing to do is use an online service, such as Resize.co. You pass them the URL for your image file, the attributes and they take care of everything else.
You cannot control the way the browser renders images when they are resized. Images will look better when being passed through Photoshop's filters (or those in another tool) upon resize.
There is three way that I know to reduce an image file size in bytes :
Convert the file into a format using lossy compression algorithm such as JPG. Obviously the image will lose sharpness
Convert the file into a format using lossless compression algorithm, like PNG. Only works if the image contains lots of region with flat colors
Resize/resample the image using Photoshop or GIMP. If the new image dimension (width x height) is exactly the same as the displayed image's dimension in HTML, then web users will still see a sharp image
Firefox and Internet Explorer actually do have CSS properties that adjust the way images are rendered when resized via HTML attributes or CSS properties:
Firefox: image-rendering
Internet Explorer: -ms-interpolation-mode
These won’t work in other browsers, and may not work great in all (or any) versions of IE and Firefox.
But it might be worth experimenting with them as a fallback in case resizer.co causes any issues.