我正在将GIF保存到外部存储器中,在我的代码中我从Drawable获取GIF并且我能够将其保存到外部存储器Fine.But任何人都可以帮我从GifImageView的Bitmap保存GIF。 / p>
protected void onCreate(Bundle savedInstanceState) {
if (savedInstanceState != null)
fileName = savedInstanceState.getString("fileName");
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
gif = (GifImageView) findViewById(R.id.ggg);
save.setOnClickListener(new saveclick());
}
class saveclick implements Button.OnClickListener {
@Override
public void onClick(View v) {
saveGIF();
}
}
private void saveGIF()
{
try
{
File file = new
File(Environment.getExternalStoragePublicDirectory
(Environment.DIRECTORY_DOWNLOADS), "shared_gif_shai" +
System.currentTimeMillis() + ".gif");
long startTime = System.currentTimeMillis();
// InputStream is = new BufferedInputStream(new
FileInputStream("source.bitmap"));
InputStream is =getResources().openRawResource(+R.drawable.aa);
BufferedInputStream bis = new BufferedInputStream(is);
//bitmap = BitmapFactory.decodeStream(bis);
ByteArrayOutputStream baos = new ByteArrayOutputStream();
//Log.d(TAG, "on do in background, create buffered array output
stream");
byte[] img = new byte[1024];
int current = 0;
while ((current = bis.read()) != -1) {
baos.write(current);
}
FileOutputStream fos = new FileOutputStream(file);
fos.write(baos.toByteArray());
fos.flush();
fos.close();
is.close();
}
catch (Exception e) {
e.printStackTrace();
}
}
此代码中的InputStream是从drawable获取GIF,有没有办法将位图转换为inputStream?非常感谢。