我正在使用带有 5 个片段的导航底部。
每个片段都会进行 HTTP 调用并下载内容,但是在替换片段时,视图会被破坏并再次下载。
在我的搜索中,我发现我应该使用 setOffscreenPageLimit 这个方法,但我不使用 viewpager。
我怎么能实现这样的东西?
navigation android android-fragments android-volley bottomnavigationview
我正在尝试从设备相机拍摄照片或从图库中选取它并通过齐射将其上传到服务器,一切正常,但图像质量太差
private void dispatchTakePictureIntent()
{
Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
startActivityForResult(intent , CAMERA_REQUEST_CODE);
}
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data {
switch (requestCode) {
case CAMERA_REQUEST_CODE:
if ( resultCode == RESULT_OK){
Bundle bundle = data.getExtras();
bitmap = (Bitmap) bundle.get("data");
ByteArrayOutputStream stream = new ByteArrayOutputStream();
bitmap.compress(Bitmap.CompressFormat.PNG, 100, stream);
}
break;
Run Code Online (Sandbox Code Playgroud)
和 getParams 方法:
byte[] a = convertBitmapToByteArrayUncompressed(bitmap);
params.put("img" , Base64.encodeToString(a , Base64.DEFAULT));
public static byte[] convertBitmapToByteArrayUncompressed(Bitmap bitmap){
ByteBuffer byteBuffer = ByteBuffer.allocate(bitmap.getByteCount());
bitmap.copyPixelsToBuffer(byteBuffer);
byteBuffer.rewind();
return byteBuffer.array();
}
Run Code Online (Sandbox Code Playgroud)