I'm using import 'package:image/image.dart' as imgs; this package
I can perfectly create a GIF but i cannot set the delay transition for every frame, Here's my code:
List<int>? generateGIF(Iterable<imgs.Image> images) {
final imgs.Animation animation = imgs.Animation();
for (imgs.Image image in images) {
animation.addFrame(image);
}
return imgs.encodeGifAnimation(animation);
}
My question is, how to put a delay for each frame?.
for example, 1000 milliseconds to each frame transition.
try this,
List<int>? generateGIF(Iterable<imgs.Image> images) {
final imgs.Animation animation = imgs.Animation();
for (imgs.Image image in images) {
image.duration = 1;
animation.addFrame(image);
}
return imgs.encodeGifAnimation(animation);
}
Related
We have implemented this functionality of preloading in which when a user is on a photo album the pictures load as per the pages, the first-page load certain picture items once a user has scrolled down all the way through the first page then after the other pictures of another page loads, now we want pictures to load constantly as the user scrolls down the page and not as per the particular pages with fixed picture items. Would really appreciate the suggested approach. Implemented code is down below, please suggest the manipulation of it to achieve the requirement.
scrollController.addListener(() {
if (isloading) {
return;
}
double maxScroll = scrollController.position.maxScrollExtent;
double currentScroll = scrollController.position.pixels;
if (currentScroll == maxScroll && hasMore!) {
fetchPhotos();
// hasMoreAndMaxScroll = true;
update();
// print("call function update");
// print("call function");
} else {
// scrollController.jumpTo(0);
// print("call function");
}
});
callAnalysis(Appstring.resourcestring[Appstring.albumphotolist].toString());
super.onInit();
}
I have implmented image picker, it is working great on both ios and android.
However, after i have captured an image, it is taking quite long for it to appear on my Image.file(image) widget.
I cannot decrease the quality of image, as it matters in the app.
So i need something like CachedNetworkImage but to load from file, not from internet, any ideas?
I just want to show an progress bar or indicator, just to let the user know that there is a process.
File? image;
Future pickImage(ImageSource source, BuildContext context) async {
try {
final image = await ImagePicker().pickImage(source: source);
if (image == null) return;
var imageTemporary = File(image.path);
if (source == ImageSource.camera) {
final img.Image? capturedImage =
img.decodeImage(await File(image.path).readAsBytes());
final img.Image orientedImage = img.bakeOrientation(capturedImage!);
imageTemporary =
await File(image.path).writeAsBytes(img.encodeJpg(orientedImage));
}
setState(() {
this.image = imageTemporary;
});
} on PlatformException catch (e) {print(e.toString());}
}
Thats my function to call image picker.
And passing it to ElevatedButton like:
I build a for loop in Flutter on which I make some stuff with many images:
for (var i = 0; i < resultList.length; i++) {
File imageFile = await _getImageFileFromAssets(resultList[i]);
final appDir = await syspath.getApplicationDocumentsDirectory();
final fileName = path.basename(imageFile.path);
final savedImage =
await File(imageFile.path).copy('${appDir.path}/$fileName');
// Creating thumbnails
final thumb =
image.decodeImage(File(savedImage.path).readAsBytesSync());
final thumbImage = image.copyResize(thumb, width: 500);
new File('${appDir.path}/$fileName-thumb-500.jpg')
.writeAsBytesSync(image.encodeJpg(thumbImage));
final finalThumbImage =
File('${appDir.path}/$fileName-thumb-500.jpg');
picturesData.add(Picture(
album: albumID,
path: savedImage.path,
thumbPath: finalThumbImage.path,
timestamp: Timestamp.now()));
setState(() {
loadingScreen = true;
});
}
While the loop is working, I show a loading screen Widget with an loading animation:
return loadingScreen == true ? LoadingScreen() : Scaffold()
What I expect A clean loading screen while the for loop duration with smooth animation
What I get Extreme flickering and lagging on the animation. After each image was edited, the animation stops. So I get something like a stop motion animation.
What could be the issue here?
I want to render this card and the first time it's loaded, the animation start once. What I want is the default there is no animation happen. Does anyone know how to make this happen?
class Card extends AnimationComponent {
Card(width, height)
: super.sequenced(width, height, 'card.png', 5,
textureWidth: 144.0, textureHeight: 220.0, loop: false);
}
class GameScreen extends BaseGame {
GameScreen({#required this.size}) {
add(Card(0,0));
}
}
According to the source code, you'll able to use Animation to control the frame.
For simple, just don't call update and keep rendering, the frame index will not be updated.
void update(double dt) {
clock += dt;
elapsed += dt;
if (isSingleFrame) {
return;
}
if (!loop && isLastFrame) {
onCompleteAnimation?.call();
return;
}
while (clock > currentFrame.stepTime) {
if (!isLastFrame) {
clock -= currentFrame.stepTime;
currentIndex++;
} else if (loop) {
clock -= currentFrame.stepTime;
currentIndex = 0;
} else {
break;
}
}
}
So you could just override the update method to get the controll of sprite animations.
I imported a custom sprite from Photoshop, and its color was purple. I want it so that when the button is pressed, it changes color. When I used renderer.material.color = Color.cyan;, and once the button is pressed, I have no idea how to make the color of the button return back to normal.
I just noticed that my answer, at its core, is the same as Heisenbug's, but in UnityScript.
private var original : Color;
function Start ()
{
original = renderer.sharedMaterial.color;
}
function changeColor(newColor : Color)
{
renderer.material.color = newColor;
}
function resetColor()
{
changeColor(original);
}
This is how you use it:
changeColor(Color.black);
There is no built-in way to do that. You can, however, store the original color before modifying it and the reassign it back:
Color originalColor;
void Awake()
{
originalColor = renderer.sharedMaterial.color;
}
void ChangeColor(Color newColor)
{
renderer.material.color = newColor;
}
void ResetDefaultColor()
{
renderer.material.color = originalColor;
}