0

내가 VectorDrawable에서 Bitmap을 얻으려고 XML (이미지) : Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'void android.graphics.Bitmap.setHasAlpha(boolean)' on a null object reference 오류VectorDrawable 비트 맵 : null 객체 참조에 Bitmap.setHasAlpha (부울) '

Bitmap.createBitmap 방법에

VectorDrawable vectorDrawable = (VectorDrawable) ContextCompat.getDrawable(mContext, R.drawable.test); 

Bitmap bitmap = UtilMethods.getBitmapFromVector(vectorDrawable); 

그러나 응용 프로그램 충돌

public static Bitmap getBitmapFromVector(VectorDrawable vectorDrawable) { 
     Bitmap bitmap = Bitmap.createBitmap(vectorDrawable.getIntrinsicWidth(), 
       vectorDrawable.getIntrinsicHeight(), Bitmap.Config.ARGB_8888); 
     Canvas canvas = new Canvas(bitmap); 
     vectorDrawable.setBounds(0, 0, canvas.getWidth(), canvas.getHeight()); 
     vectorDrawable.draw(canvas); 
     return bitmap; 
    } 

ps 내가 Getting Bitmap from vector drawable 그들 모두에서 모든 방법을 시도

<?xml version="1.0" encoding="utf-8"?> 
<vector xmlns:android="http://schemas.android.com/apk/res/android" 
    android:width="16000dp" 
    android:height="16000dp" 
    android:viewportWidth="16000" 
    android:viewportHeight="16000"> 


    <path 
     android:fillColor="#040607" 
     android:strokeWidth="1" 
     android:pathData="M3637 11910 l486 -730 484 0 c265 0 483 3 483 8 0 4 -130 331 -288 727 l-288 720 
-682 3 -682 2 487 -730z" /> 

</vector> 

여기

compile 'com.android.support:appcompat-v7:25.3.1' 
compile 'com.android.support:support-v4:25.3.1' 

몇 가지 간단한 XML 드로어 블 (쉼표 기호)로

보인다이 .createBitmap 방식에 실패

android:width="16000dp" 
android:height="16000dp" 
android:viewportWidth="16000" 
android:viewportHeight="16000"> 

은 큰 값으로 ...

나는 더 path 태그가 완전하지 XML을 추가했습니다, 그래서 그것은 바로 그러한 큰 값 : I 2000 (예) 값을 줄이기 위해 노력하고 응용 프로그램이 충돌을 중지

와 기호를 쉼표로하지,하지만 그것은 내가 http://inloop.github.io/svg2android/

+0

망 했니? 크기를 변경하려면 width 및 height 속성 만 변경하고 viewportWidth 및 viewportHeight는 그대로 두십시오. –

답변

0

변화

android:width="16000dp" 
android:height="16000dp" 

android:width="24dp" 
android:height="24dp" 

는 chagne 할 필요가 없습니다 :

당신이 당신의 이미지, 방법은 무엇인지에 망쳐 말
android:viewportWidth="16000" 
android:viewportHeight="16000"> 
0

당신은 당신이 당신의 응용 프로그램을 실행하고 화면의 밀도에 따라 계수를 곱한해야하는 16000x16000dp 비트 맵을 할당하려고를 사용하여 SVG에서 벡터 당김을 만들어

내 이미지를 파괴 xhdpi는 2, xxhdpi는 3, xxxhdpi는 4입니다. 1000MB보다 큰 비트 맵을 할당하려고하므로 메모리 문제가 발생합니다.

드로어 블의 크기를 줄여야합니다. 그것은 당신이 경험하고있는 품질 손실을 일으키지 않아야합니다. SVG 또는 svg2android의 출력을 검사하여 오류를 찾아내는 것이 좋습니다 ...

또한 GL_MAX_TEXTURE_SIZE보다 크거나 큰 비트 맵을 ImageView에 저장할 수 없습니다 . 참조 : "Bitmap too large to be uploaded into a texture"

관련 문제