How do I do an animated imageView in appcelerator? - appcelerator

loader_array = [];
for (var i=1; i <= 24; i++) {
loader_array.push('/images/system/block_loaders/' + i + '.png');
};
var loadingSpinner = Ti.UI.createImageView({
images: loader_array,
duration: 100,
repeatCount: 100,
opacity: 0.5
});
self.add(loadingSpinner);
When I do that, I get nothing. But if I do a single image from that set and use image instead of images, it works fine. So what am I doing wrong?

Try This One if Works
answered by brian kurzius

Android or iOS?
If android and set duration, you have called start method to animate.

Related

Xamarin iOS Activity Indicator with Another image

Using Xamarin.iOS is it possible to change the image in an UIActivityIndicatorView the default image looks like this:
and I would like to use an image like this:
You could use the animation properties on a UIImageView like so:
var images = new UIImage[40];
for (int i = 0; i < 40; i++)
{
images[i] = UIImage.FromBundle($"Frame{i}");
}
ImageView.Image = images[0];
ImageView.AnimationImages = images;
ImageView.AnimationDuration = 2;
You can start and stop it with:
ImageView.StartAnimating();
ImageView.StopAnimating();
I made a demo of this here it looks like this:
Also will need to generate the images for the loader you want.

HTML5 video and canvas

I have a video and I need to capture 3 images from it, at different time. Time is not random, I have to take images at specified time (13:10:02, 13:10:03, 13:10:04). The images should be displayed on the page when I access the page, not when I click a button or something like that.
Until now I tried with an example that I found on the internet, but on this example, the image is displayed after a button was clicked, and I don't know how to give a specified time.
<video controls>
<source src="http://www.jplayer.org/video/m4v/Big_Buck_Bunny_Trailer.m4v" type="video/mp4"></source>
<source src="http://www.jplayer.org/video/m4v/Big_Buck_Bunny_Trailer.m4v" type="video/mp4"></source>
</video>
<canvas id="canvas" width="640" height="480"></canvas>
<button id="snap" onclick="snap()">Snap Photo</button>
<script>
var video=document.querySelector('video');
var canvas=document.querySelector('canvas');
var context=canvas.getContext('2d');
var w,h,ratio;
//add loadedmetadata which will helps to identify video attributes......
video.addEventListener('loadedmetadata',function()
{
ratio=video.videoWidth/video.videoHeight;
w=video.videoWidth-100;
h=parseInt(w/ratio,10);
canvas.width=w;
canvas.height=h;
},false);
///define a function
function snap()
{
context.fillRect(0,0,w,h);
context.drawImage(video,0,0,w,h);
}
</script>
You can set the time, for which frame you want to draw to canvas, by setting the currentTime on the video object.
Then you need to wait for video to finish seeking, draw the video onto canvas an move to the next frame.
Of course you need to wait for the video to load before you start drawing its frames.
var images = [ // defined canvases and times for frames
{
canvas: '#canvas1',
time: 10.0 // in seconds
},
{
canvas: '#canvas2',
time: 19.0
},
{
canvas: '#canvas3',
time: 26.0
},
];
function drawFrame(video, time, canvas, callback)
{
var context = canvas.getContext("2d");
video.addEventListener("seeked", function(e) {
e.target.removeEventListener(e.type, arguments.callee); // remove the handler or else it will draw another frame on the same canvas, when the next seek happens
context.fillRect(0, 0, canvas.width, canvas.height);
context.drawImage(video, 0, 0, canvas.width, canvas.height);
callback();
});
video.currentTime = time;
}
function draw(video, images, i)
{
if (i >= images.length)
return;
drawFrame(video, images[i].time, images[i].canvas, function() {
draw(video, images, i+1);
});
}
var video = document.createElement('video');
video.addEventListener('loadedmetadata', function() // when the metadata is loaded set the canvases size and start drawing frames
{
var ratio = video.videoWidth / video.videoHeight;
var w = video.videoWidth - 100; // set the width of the images to 100 px less than the video
var h = w / ratio; // fix the height accordingly
for (var i=0; i<images.length; i++)
{
images[i].canvas = document.querySelector(images[i].canvas);
images[i].canvas.width = w;
images[i].canvas.height = h;
}
draw(video, images, 0);
});
video.src = "http://www.jplayer.org/video/m4v/Big_Buck_Bunny_Trailer.m4v";
JSFiddle

How to remove initial background image when starting a cocos2d-html project?

Initially when a cocos2d-html5 project starts (in the web browser), there is a background image showing cocos2d.
How does one remove or change it ?
This appears just after the loading screen. I cannot find a reference to it anywhere in code.
It's created in frameworks/cocos2d-html5/cocos2d/core/scenes/CCLoaderScene.js
//image move to CCSceneFile.js
var fontSize = 24, lblHeight = -logoHeight / 2 + 100;
if(cc._loaderImage){
//loading logo
cc.loader.loadImg(cc._loaderImage, {isCrossOrigin : false }, function(err, img){
logoWidth = img.width;
logoHeight = img.height;
self._initStage(img, cc.visibleRect.center);
});
fontSize = 14;
lblHeight = -logoHeight / 2 - 10;
}
And the cocos2d logo is a base64 image store in variable cc._loaderImage.
cc._loaderImage is defined in frameworks/cocos2d-html5/Base64Images.js

Kinetic JS - Change image resolution using filter when mouse is down

I am changing left mouse down (drag) to change the image, it works but very slow (refresh). I am using the following to display the image:
function makeKineticImage() {
dImage1 = new Kinetic.Image({
drawFunc: function(canvas) {
var context2 = canvas.getContext("2d");
var x = 0;
var y = 0;
context2.drawImage(dicom1, x, y);
imageData = context2.getImageData(x, y, dicom1.width, dicom1.height).data;
}
});
layer1.add(dImage1);
Then changing the image using Ajax:
...
}).done(function(d) {
dImage1.applyFilter(Kinetic.Filters.Grayscale, null, function() {
image.src = '/Home/changeImage?udm=' + (++udm);
layer1.draw();
});
I tried Grayscale filter, the refresh improved but not good enough. Is there a way to lower the resolution (down sampling). I would appreciate your suggestions, thanks in advance.

Titanium: get png height without creating ImageView

Is there a way to get a .png height without creating ImageView?
The methods I found on google require createImageView first and then doing a .height.
I want to avoid creating ImageView because I'm going to createImageView after I get the height of the png and perform some changes.
Or rather, I will be using the height value during the var imagevariablename = Ti.UI.createImageView itself, so I can't using imagevariablename.height because the declaration of var imagevariablename is not done yet.
I don't know of any way to get the height / width of an image without creating an imageView in Titanium. In my app, I create a temporary image view and read the attributes without ever adding it to a view / window. Then you can create the 'real' image view once you know the size:
var imageTemp = Ti.UI.createImageView({
image : someFile.read(),
height:'auto',
width:'auto'
});
Ti.API.info( "height=" + imageTemp.size.height);
Ti.API.info( "width=" + imageTemp.size.width);
imageTemp = null;
Try this code
var imageTemp = Ti.UI.createImageView({
image : <image>,
height:'auto',
width:'auto'
}),
imageSize = imageTemp.toImage();
Ti.API.info( "height=" + imageSize.height);
Ti.API.info( "width=" + imageSize.width);
imageTemp = imageSize = null;
If you create a Blob from your image you can get width and height from the blob
From Titanium docs:
If this blob represents an image, this is the height of the image in pixels.
In my condition this is run like this.
var imageTemp = Ti.UI.createImageView({
image : someFile.read(),
height:'auto',
width:'auto'
});
alert( "height=" + imageTemp.toBlob().height);
alert( "width=" + imageTemp.toBlob().width);
imageTemp = null;
I was working on this and had trouble with the code above using 3.2.2, testing on Android. Various attempts would just give me 1, 0 or SIZE for the width and height values. This DOES use an imageView, but the following gets me everything I need in this environment. I also am using the load event instead of postLayout. Hopefully this helps someone.
$.map.image = 'http://getyourownimage.com/dev/8fac94c6-872b-4bda-a56a-7dba09188c66.png';
$.map.zIndex = 1;
$.map.width = 'auto';
$.map.height = 'auto';
$.map.addEventListener('load',function(e){
var rect = $.map.getRect();
Ti.API.info(rect.width); //actual width of imageView
Ti.API.info(rect.height); //actual height of imageView
Ti.API.info($.map.getWidth()); //returns auto/SIZE, doesn't work
Ti.API.info($.map.getHeight()); //returns auto/SIZE, doesn't work
Ti.API.info($.map.toImage().width); //some scaled value, not useful
Ti.API.info($.map.toImage().height); //some scaled value, not useful
Ti.API.info($.map.toBlob().width); //image original/full size width
Ti.API.info($.map.toBlob().height); //image original/full size height
alert('rectX:'+rect.width+',rectY:'+rect.height+',mapGW:'+$.map.getWidth()+',mapGH:'+$.map.getHeight()+',tiX:'+$.map.toImage().width+',tiY:'+$.map.toImage().height+',tbX:'+$.map.toBlob().width+',tbY:'+$.map.toBlob().height);
});

Resources