Android的JPG动画 [英] Android jpg animation
本文介绍了Android的JPG动画的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想从一个网站下载10 JPG图片。
I would like to download 10 JPG pictures from a site.
在这里每隔一段时间拍摄的照片>>这是没有问题的。
The pictures where taken at intervals >> that is no problem
- 如何保存图片在图片的数组。
- 我将如何显示它们作为动画(动画等)。
- 要在Android(ImageView的,动画师)用什么成分?
- 我将如何动画组成部分?
任何具体的例子是大大AP preciated。
Any specific examples would be greatly appreciated.
推荐答案
我有这样一个例子,我在这里下载三张图片形式的网站,然后在其存储路径到/ mnt / SD卡/ ..。如果你想在动画显示这个话,我觉得你可以用鳍,然后动态添加此图像,并使用一个异步任务,你可以下一个翻转图像。
I have an example of this, here I am downloading three images form site and then store in it path "/mnt/sdcard/..". If you want to show this in animation then I think that you can use flipper and then add this image dynamically and using an async task you can flip image next.
import java.io.BufferedInputStream;
import java.io.FileOutputStream;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.URL;
import java.net.URLConnection;
import android.app.Activity;
import android.app.ProgressDialog;
import android.os.AsyncTask;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.Toast;
public class TestActivity extends Activity {
/** Called when the activity is first created. */
Button btn;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
btn=(Button)findViewById(R.id.startBtn);
final String url1 = "http://farm1.static.flickr.com/114/298125983_0e4bf66782_b.jpg";
final String url2 = "http://farm1.static.flickr.com/114/298125983_0e4bf66782_b.jpg";
final String url3 = "http://farm1.static.flickr.com/114/298125983_0e4bf66782_b.jpg";
btn.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
new AsyncDownload().execute(url1,url2,url3);
}
});
}
//------------------------------Class AsyncDownload----------------------------------
public class AsyncDownload extends AsyncTask<String, String, String>
{
ProgressDialog dialog;
@Override
protected void onPostExecute(String result) {
// TODO Auto-generated method stub
super.onPostExecute(result);
dialog.dismiss();
Toast.makeText(TestActivity.this,"Downloading complate successfully",2).show();
}
@Override
protected void onPreExecute() {
// TODO Auto-generated method stub
super.onPreExecute();
dialog=new ProgressDialog(TestActivity.this);
dialog.setMessage("Downloading file..");
dialog.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);
dialog.setMax(100);
dialog.show();
}
@Override
protected void onProgressUpdate(String... values) {
// TODO Auto-generated method stub
super.onProgressUpdate(values);
dialog.setProgress(Integer.parseInt(values[0]));
}
@Override
protected String doInBackground(String... aurl) {
int count;
int lenghtOfFile=0;
long total = 0;
try {
for(int i=0;i<aurl.length;i++)
{
URL url = new URL(aurl[i]);
URLConnection conexion = url.openConnection();
conexion.connect();
lenghtOfFile =lenghtOfFile+conexion.getContentLength();
}
for(int i=0;i<aurl.length;i++)
{
URL url = new URL(aurl[i]);
URLConnection conexion = url.openConnection();
conexion.connect();
InputStream input = new BufferedInputStream(url.openStream());
OutputStream output = new FileOutputStream("/mnt/sdcard/img"+i+".jpg");
byte data[] = new byte[1024];
while ((count = input.read(data)) != -1) {
total += count;
publishProgress(""+(int)((total*100)/lenghtOfFile));
output.write(data, 0, count);
}
output.flush();
output.close();
input.close();
}
} catch (Exception e) {
e.getMessage();
}
return null;
}
}
}
这篇关于Android的JPG动画的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文