I'm trying to display an animated GIF in a Firemonkey HD form using TImage but I do not see any methods for animation.
Using Vcl.Imaging.gifImg is not an option because types differ.
Can someone suggest a way to solve this problem or probably component to animate GIF images under Firemonkey?
The only way I find for now is:
create TGIFImage instance and load the GIF image
loop through gif.images:
a. save current image to stream
b. Image1.bitmap.loadFromStream [Image1 is FMX:TImage]
Is there any smarter solution?
You can use TBitmapListAnimation with a single image which has each frame of the animation inside a long strip. eg, if your animation has 4 frames and is 32px by 32px then you need to create an image 128px wide by 32px high and add each frame side by side...
Then add a TImage to the form (you don't have to load a bitmap into this)
Add a TBitmapListAnimation with the TImage as it's parent
Double click AnimationBitmap and load your animation image strip
Drop down PropertyName and pick Bitmap
Set AnimationCount to 4 and AnimationRowCount 1 for this example
Set enabled to true
TBitmapListAnimation has good control over animation frame rates, reversing, looping and interpolation. I couldn't find a way to get a .gif to animate in FireMonkey2 but if you have the means to convert an animated .gif into a 'cartoon strip' then this is a good way to do animations.
PS This is Delphi XE3...so can't say if these components existed in previous version.
Related
I need to create button like this
and the change the background programmatically like this
and like this
I can not use images for different states of a button because each time I have different text on it.
What to start from ? I tried to understand CoreGraphics and CoreAnimation but there is too small amount of examples and tutorials so my attempts didn't give me any success.
You can, and should, use an image for this. UIKit has a method resizableImageWithCapInsets that creates resizable images. You feed it a minimum sized image and the system stretches it to fit the desired size. It looks like your image is fixed in height, which is good since you can't do smooth gradients with this technique.
UIButtons are composed of a background image and title text, so you can use an image for the background shapes (setBackgroundImage(_:forState:)), and then change the text using setTitle(_:forState:).
However, you can still use Core Graphics for this, and there are benefits to doing so, such as the fact that it reduces the number of rendered assets in your app bundle. For this, probably the best approach is to create a CAShapeLayer with a path constructed from a UIBezierPath, and then render it into a graphics context. From this context, you can pull out a UIImage instance, and treat it just the same as an image loaded from a JPEG or PNG asset (that is, set it as the buttons background image using setBackgroundImage(_:forState:)).
I want to get directions for following two issues related to UISlider control customization.
Issues#1:
I just updated the UISlideThumbImage as seen in following screenshot. As thumb image is in retina display, so its large image; My question is how we can resize the thumb image? I don't want to resize thumb image PNG. If i will do that then on retina display screens, it will seems blur.
Issue#2:
Default clickable area of thumb image of slider is 23x23. How we can increase that area? So that we can adjust it according to the size of thumb image. Currently, if i will move finger in 23x23 bounds, it will start sliding but if out side of that bound, it will not move but i also want to move the thumb if i will slide on any place of the thumb image.
Your important suggestions will be move helpful in this regards. Is there any third party library present which will do it more efficiently regardless of doing it ourself and spend more time over it?
From my experience with customising UISlider, It's better just not using the default one.
There is a open source Range Slider:
https://github.com/muZZkat/NMRangeSlider
And notice there is a option to remove the lower thumb so you acutely have a regular customising UISlider
"(New) Disable lower handle so it behaves like a regular UISlider but still use other features."
I want to know how is it possible to animate gif image that is put in TImageList.
I know that if we could access the graphic of each images in TImageList it may be possible cast the graphic of the picture to TGIFImage and set Animate property to true. but the problem is how can we access the image that is loaded in TImageList and cast it to TGIFImage and set that animate property?
EDIT:
How we can have animated gif in TTreeView?
As David Heffernan answered TImageList is not appropriate for saving gif images. but the purpose of this question was to have an animated gif in a treeview. By the suggestion of Remy-lebeau I wrote a unit for that. In this unit I defined two classes. first TGifImageRefrence that uses a TImagelist as its property and must be assigned and has a procedure that add gif image to this imagelist. each frame will be saved as single image in Imagelist and frames' indexes and animationspeed will be saved.
The Second class is TGifNode that its purpose is to be a node in TreeView. It contains a timer an accept a TGifImageRefrence as it's property. you can inherit a class for your own node for your treeview from this class. I write an example using this unit and put them together and you can download it from http://loghman.ir/MySource/GifInTreeView.zip
A TImageList stores a list of equally sized static images. It's not appropriate for hosting an animated GIF. You could unpack all the images from the animated GIF and put them in the images list. And then reconstruct them later for animation. That would seem pointless. You should use TGIFImage for animating a GIF.
In my FMX Application I have to fill the entire background area of my form using a Bitmap pattern.
The reason why I'm thinking to use this pattern is because the form is freely resizable by the user and whether I set a fixed image the stretch causes the loss of quality of the background.
Is there a way to use a small Bitmap pattern I can repeat (X and Y) to fill the whole form area according to the resizing?
The effect you are looking for is a Tile.
See TTilerEffect and FireMonkey_Image_Effects for documentation.
The properties HorizontalTileCount and VerticalTileCount controls how many times a bitmap will be replicated. Since these values are floats, you need to adapt their values when the form is rescaled.
Add a TImage to the form
Make all the other controls children of it (so they appear on top).
Set the image's Align to alClient.
Load the Bitmap.
Set the WrapMode to imTile.
I have a Image list assigned to a listview to display transparent images.
There is a slight issue with this regarding some transparent images that are added, and that is they are sometimes hard to see/find in the listview.
See this example image:
You will notice that the images (noticeably the mouse) is barely viewable, infact if a empty image was added you would not even see it, the number captions come to the rescue here to show there is something actually there.
But I would like to make the images visually easier to see. I thought maybe having another image underneath the transparent images would work - of course though it could not affect the actual image.
So with that in mind, I made a bitmap of a chessboard grid:
I feel this would be the most suitable way of representing transparent areas of the images just like Paint.NET etc does.
To further illustrate this example I have modified the original image to show how it would look, if we had the chessboard bitmap as the underlay image:
Having the chessboard there would indicate there is a list item there in the first place, and the bitmap of the chessboard grid could be darker or an altogether different kind of image. As I said earlier if there was no image you would see nothing at all, so better to show an empty chess grid or other bitmap than nothing.
So, how can I display a second image underneath the original images using a imagelist to give a result similar to the example above? The underneath image could be anything - just another loaded bitmap for example.
If you store the chessboard as the first image (with index 0) and make the overlay image from the current image in the OnGetImageIndex event handler, it will do what you want to. However I'm not sure how efficient is to make the overlay image every time the event is fired.
procedure TForm1.ListView1GetImageIndex(Sender: TObject; Item: TListItem);
begin
// make the overlay (with overlay index 1) from the
// image with index Item.Index + 1
ImageList1.Overlay(Item.Index + 1, 1);
// use the first image from the list as a background
Item.ImageIndex := 0;
// and assign just created overlay index for overlay
Item.OverlayIndex := 1;
end;
I seems that what you need is a TImageList with extra capabilities.
As a starting point, I suggests you to consider TImageListEx described in the book Inside Delphi 2006
Excerpt:
The TImageListEx component is a TImageList descendant that can use the
images from another image list to generate disabled images, which can
be used on toolbars and other user interface elements.
The TImageListEx component is a TImageList descendant that can use the
images from another image list to generate disabled images, which can
be used on toolbars and other user interface elements.
There are several benefits of the TImageListEx component:
It eliminates the need for creating disabled glyphs.
It eliminates the need for adding the disabled glyphs to an additional TImageList component at design time.
It can drastically reduce the size of the .dfm file and of the entire application, especially in large applications that use a lot of
glyphs.
It's extremely fast, taking only milliseconds to disable all images in an image list, even when there are number of images.
It's extremely lightweight. (If you add it to an application that already uses the standard TImageList component, it won't increase the
size of the executable at all, and if you add it to an application
that doesn't use the standard TImageList component, the overhead is
only 2 KB.)
It's far from your requirements but yet detailed enough to show how to extend TImageList.