2017-04-08 7 views
1

Google 통합을 통해 얻은 링크에서 이미지를 검색하려고하는 앱이 있습니다. 그러나, 언제든지 비트 맵으로 그림을 가져 오려고 할 때마다 항상 오류가 발생합니다. 코드 및 오류는 다음과 같습니다 :google 프로필 사진 URL에서 비트 맵을 가져올 수 없습니다.

코드 :

if (google_user_gallery_pic.isEmpty() == true) 
{ 
    if (google_user_pic.isEmpty() == false) 
    { 
     onPost = null; 
     onPost2 = null; 
     onPost = getBitmapFromURL(google_user_pic); 
     onPost2 = onPost2.createScaledBitmap(onPost, 100, 100, false); 
    } 

    else 
    { 
     onPost = null; 
     onPost2 = null; 
     onPost = BitmapFactory.decodeFile(google_user_gallery_pic); 
     if (onPost == null) 
     { 
      onPost2 = BitmapFactory.decodeResource(getResources(), R.drawable.the_smallperson); 
     } 

     else 
     { 
      onPost2 = onPost2.createScaledBitmap(onPost, 100, 100, false); 
     } 
    } 
} 

else 
{ 
    onPost = null; 
    onPost2 = null; 
    onPost = BitmapFactory.decodeFile(google_user_gallery_pic); 
    if (onPost == null) 
    { 
     onPost2 = BitmapFactory.decodeResource(getResources(), R.drawable.the_smallperson); 
     //onPost2 = onPost2.createScaledBitmap(onPost, 100, 100, false); 
    } 

    else 
    { 
     onPost2 = onPost2.createScaledBitmap(onPost, 100, 100, false); 
    } 
} 

오류 :

E/BitmapFactory: Unable to decode stream: java.io.FileNotFoundException: https:/lh3.googleusercontent.com/-HW5Tk9h1V2I/AAAAAAAAAAI/AAAAAAAADA8/7UbMeHbyFLM/photo.jpg: open failed: ENOENT (No such file or directory) 

의 URL :

https://lh3.googleusercontent.com/-HW5Tk9h1V2I/AAAAAAAAAAI/AAAAAAAADA8/7UbMeHbyFLM/photo.jpg 

URL을 한 페이지 만에 나던 작업에서 작동 다른. 두 페이지 모두 조각 활동입니다. 어떤 도움을 주시면 감사하겠습니다.

+0

: Gradle을 추가에

private Target mTarget; //declare variable void loadImage(Context context, String url) { final ImageView imageView = (ImageView) findViewById(R.id.image); mTarget = new Target() { @Override public void onBitmapLoaded (final Bitmap bitmap, Picasso.LoadedFrom from){ //Do something on the bitmap imageView.setImageBitmap(bitmap); //set the bitmap } @Override public void onBitmapFailed(Drawable errorDrawable) { } @Override public void onPrepareLoad(Drawable placeHolderDrawable) { } }; Picasso.with(context) .load(url) .into(mTarget); ..error(R.drawable.the_smallperson) // will be displayed if the image cannot be loaded } 

? – rafsanahmad007

+0

@ rafsanahmad007 idk 사용 방법 –

+0

파일에 비트 맵을 저장 했습니까? 열려고합니까? – rafsanahmad007

답변

1

이런 식으로하는 경우와 다른 조건을 반전 시도 :

if (google_user_gallery_pic.isEmpty() == false) 
{ 
    if (google_user_pic.isEmpty() == false) 
    { 
     onPost = null; 
     onPost2 = null; 
     onPost = getBitmapFromURL(google_user_pic); 
     onPost2 = onPost2.createScaledBitmap(onPost, 100, 100, false); 
    } 

    else 
    { 
     onPost = null; 
     onPost2 = null; 
     onPost = BitmapFactory.decodeFile(google_user_gallery_pic); 
     if (onPost == null) 
     { 
      onPost2 = BitmapFactory.decodeResource(getResources(), R.drawable.the_smallperson); 
     } 

     else 
     { 
      onPost2 = onPost2.createScaledBitmap(onPost, 100, 100, false); 
     } 
    } 
} 

else 
{ 
    onPost = null; 
    onPost2 = null; 
    onPost = BitmapFactory.decodeFile(google_user_gallery_pic); 
    if (onPost == null) 
    { 
     onPost2 = BitmapFactory.decodeResource(getResources(), R.drawable.the_smallperson); 
     //onPost2 = onPost2.createScaledBitmap(onPost, 100, 100, false); 
    } 

    else 
    { 
     onPost2 = onPost2.createScaledBitmap(onPost, 100, 100, false); 
    } 
} 

권한 오히려이 코드보다 다른 것을 제공하기 때문에,이

+0

괜찮아요,이 동생을 보자. –

+0

아니, 미안하지만 ... –

1

시도 이외의 거기에 아무 문제가 없었다 picasso를 사용하여 URL에서 이미지 비트 맵을로드합니다. 왜 피카소를 사용하지

compile 'com.squareup.picasso:picasso:2.5.2' 
+0

이 목표는 무엇입니까? 수업 이니? –

+0

그래, 당신은 그것을 가져올 필요가있다. 당신이 grad을 추가 한 후 – rafsanahmad007

+0

나는 Saim의 대답에 따라 조건을 바꿨을 때 약간의 시간 동안 작동했기 때문에 논리에 문제가 있다고 생각한다. –

관련 문제