我试图从Android Uri到字节数组.
我有以下代码,但它一直告诉我字节数组长61个字节,即使文件非常大 - 所以我认为它可能将Uri 字符串转换为字节数组,而不是文件:(
Log.d(LOG_TAG, "fileUriString = " + fileUriString);
Uri tempuri = Uri.parse(fileUriString);
InputStream is = cR.openInputStream(tempuri);
String str=is.toString();
byte[] b3=str.getBytes();
Log.d(LOG_TAG, "len of data is " + imageByteArray.length
+ " bytes");
Run Code Online (Sandbox Code Playgroud)
请有人帮我弄清楚该怎么办?
输出为"fileUriString = content:// media/external/video/media/53","len of data为61字节".
谢谢!
我正在使用此库显示gif图像:https : //github.com/felipecsl/GifImageView
但是我不知道如何在这些代码中实现我的gif图像。我在素材资源文件夹中有一些GifImages。
这是我的代码:
PlayActivity.java:
import android.app.Activity;
import android.os.Bundle;
import com.felipecsl.gifimageview.library.GifImageView;
import java.io.IOException;
import java.io.InputStream;
public class PlayActivity extends Activity{
GifImageView gifView;
//byte[] bytes;
@Override
protected void onCreate(final Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.layout_play_activity);
try {
InputStream is = getAssets().open("rain_4.gif");
byte[] bytes = new byte[is.available()];
is.read(bytes);
is.close();
gifView = (GifImageView) findViewById(R.id.gifImageView);
gifView = new GifImageView(this);
gifView.setBytes(bytes);
gifView.startAnimation();
} catch (IOException e) {
e.printStackTrace();
}
}
@Override
protected void onStart() {
super.onStart();
if(gifView != null) gifView.startAnimation();
}
@Override
protected void …Run Code Online (Sandbox Code Playgroud)