在Android中使用凌空射击时图像旋转

时间:2019-07-04 21:05:14

标签: android android-volley

我有下面的代码使用排球网络映像。

当我从实际设备上拍摄图片时遇到的问题是,它将旋转的图像放置在imageview上。

我想知道在以下实现中我做错了什么。我正在使用最新的排球库1.1.1。

.xml代码

 <com.moapy.xxx.xxx.CustomNetworkImageView
            android:layout_width="100dp"
            android:layout_height="100dp"
            android:id="@+id/imageViewUser"
            android:layout_gravity="start"
            android:adjustViewBounds="true"
            android:scaleType="centerCrop"
            android:background="@color/colorAccent"
            android:contentDescription="@string/description" />

CustomNetworkImageView.java

import com.android.volley.toolbox.ImageLoader;
import com.android.volley.toolbox.NetworkImageView;

public class CustomNetworkImageView extends NetworkImageView {

    private Bitmap mLocalBitmap;

    private boolean mShowLocal;

    public void setLocalImageBitmap(Bitmap bitmap) {
        if (bitmap != null) {
            mShowLocal = true;
        }
        this.mLocalBitmap = bitmap;
        requestLayout();
    }

    @Override
    public void setImageUrl(String url, ImageLoader imageLoader) {
        mShowLocal = false;
        super.setImageUrl(url, imageLoader);
    }

    public CustomNetworkImageView(Context context) {
        this(context, null);
    }

    public CustomNetworkImageView(Context context, AttributeSet attrs) {
        this(context, attrs, 0);
    }

    public CustomNetworkImageView(Context context, AttributeSet attrs, int defStyle) {
        super(context, attrs, defStyle);
    }

    @Override
    protected void onLayout(boolean changed, int left, int top, int right, int bottom) {

        super.onLayout(changed, left, top, right, bottom);
        if (mShowLocal) {
            setImageBitmap(mLocalBitmap);
        }
    }
}

activity.java代码

imageViewUser = (CustomNetworkImageView) findViewById(R.id.imageViewUser);

MultipartRequest multipartRequest = new MultipartRequest(Config.USER_IMAGE_URL,
                null, NetworkUtil.mimeType, multipartBody, new Response.Listener<NetworkResponse>() {
            @Override
            public void onResponse(NetworkResponse response) {
                try {
                    JSONObject jsonObject = new JSONObject(new String(response.data, "UTF-8"));
                    String imagePath = jsonObject.getString("imagePath");
                    ImageLoader imageLoader = CustomVolleyRequest.getInstance(getApplicationContext()).getImageLoader();
                    imageLoader.get(Config.IMAGE_PATH_URL + "/" + imagePath, ImageLoader.getImageListener(imageViewUser, R.drawable.image, R.drawable.blank_profile ));
                    imageViewUser.setImageUrl(Config.IMAGE_PATH_URL + "/" + imagePath, imageLoader);

                    imageLoader.get(Config.IMAGE_PATH_URL + "/" + imagePath, ImageLoader.getImageListener(imageViewUserDrawer, R.drawable.image, R.drawable.blank_profile));
                    imageViewUserDrawer.setImageUrl(Config.IMAGE_PATH_URL + "/" + imagePath, imageLoader);

                    SharedPreferences.Editor editor = getSharedPreferences(Config.SHARED_PREF_NAME, Context.MODE_PRIVATE).edit();
                    editor.putString(Config.USERIMAGEPATH_SHARED_PREF, imagePath);
                    editor.apply();
                } catch (UnsupportedEncodingException | JSONException e) {
                    e.printStackTrace();
                }
            }
        }, new Response.ErrorListener() {
            @Override
            public void onErrorResponse(VolleyError error) {
                Toast.makeText(context, R.string.upload_failed + "" + error.toString(), Toast.LENGTH_SHORT).show();
            }
        });
        multipartRequest.setRetryPolicy(new DefaultRetryPolicy(DefaultRetryPolicy.DEFAULT_TIMEOUT_MS, DefaultRetryPolicy.DEFAULT_MAX_RETRIES, DefaultRetryPolicy.DEFAULT_BACKOFF_MULT));
        CustomVolleyRequest.getInstance(getApplicationContext()).getRequestQueue().add(multipartRequest);

0 个答案:

没有答案