2017-10-16 2 views
0

이미지를 검색 할 장소를 선택한 후 검은 색 원 대신이 사진을 선택하면 내 조각에 이미지가로드되는 데 문제가 있습니다. 내 코드는사진 대신 검은 색 화면이 나타납니다

입니다.
civ = view.findViewById(R.id.circle_profile); 

civ.setOnClickListener(new View.OnClickListener() { 
    @Override 
    public void onClick(View view) { 
     Intent GaleryIntent = new Intent(Intent.ACTION_PICK, android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI); 
     startActivityForResult(GaleryIntent, RESULT_LOAD_IMAGE); 
    } 
}); 

@Override 
public void onActivityResult(int requestCode, int resultCode, Intent data) { 
    super.onActivityResult(requestCode, resultCode, data); 
    if (requestCode == RESULT_LOAD_IMAGE && resultCode == getActivity().RESULT_OK && null != data) { 
     Uri selectedImage = data.getData(); 
     String[] filePathColumn = { MediaStore.Images.Media.DATA }; 
     Cursor cursor = getActivity().getContentResolver().query(selectedImage,filePathColumn, null, null, null); 
     cursor.moveToFirst(); 
     int columnIndex = cursor.getColumnIndex(filePathColumn[0]); 
     String picturePath = cursor.getString(columnIndex); 
     cursor.close(); 
     CircleImageView imageView = getActivity().findViewById(R.id.circle_profile); 
     imageView.setImageBitmap(BitmapFactory.decodeFile(picturePath)); 
    } 
} 

XML :

<de.hdodenhof.circleimageview.CircleImageView 
    android:layout_width="70dp" 
    android:layout_height="70dp" 
    android:layout_column="0" 
    android:layout_row="1" 
    android:layout_rowSpan="3" 
    android:layout_marginLeft="30dp" 
    android:layout_columnWeight="1" 
    android:id="@+id/circle_profile" 
    android:src="@drawable/profile" 
    app:civ_border_color="#FFFFFF" 
    app:civ_border_width="2dp" 
    /> 

그건은 테두리 색상은

+0

picturePath 값을 확인 했습니까? –

+0

내 모습이 좋네요. –

+0

예를 들어 이미지 선택 도구 라이브러리를 사용할 수 있습니다. https://github.com/esafirm/android-image-picker – Expiredmind

답변

0

내가 의심 왼쪽과 같은 당신의 코드 : BitmapFactory.decodeFile(picturePath) 반환,이미지의 크기가 크기 때문에 어쩌면

I가 BitmapFactory.Options을 사용하여 제안하고 두 번째 매개 변수로하여 BitmapFactory.OptionsdecodeFile 함수 내부를 통과한다.

편집 :

BitmapFactory.Options 아래 같은 코드를 가질 수 있습니다

// Get the dimensions of the bitmap 
    BitmapFactory.Options bmOptions = new BitmapFactory.Options(); 
    bmOptions.inJustDecodeBounds = true; 


    BitmapFactory.decodeFile(picturePath, bmOptions); 

int photoW= bmOptions.outWidth; 
int photoH = bmOptions.outHeight; 

// Get the dimensions of the View 
    int targetW = imageView.getWidth(); 
    int targetH = imageView.getHeight(); 

//Determine how much to scale down the image 
int scaleFactor = Math.min(photoW/targetW, photoH/targetH); 

//Decode the image file into a Bitmap sized to fill the view 
bmOptions.inJustDecodeBounds = false; 
bmOptions.inSampleSize = scaleFactor; 
bmOptions.inPurgeable = true; 

Bitmap bitmap = BitmapFactory.decodeFile(picturePath, bmOptions); 
imageView.setImageBitmap(bitmap); 

는 희망이 도움이!

+0

옵션으로 무엇을 제공해야합니까? –

+0

BitmapFactory.Options 코드로 내 대답을 편집했습니다 –

+0

picturePath 내가 이렇게 작성해야하나요? ""@ drawable/profile " –

관련 문제