2017-06-28 71 views
0

這是我的xml文件:捕獲框架佈局有這個問題

<RelativeLayout 
    android:id="@+id/relativeLayoutTemplateMain" 
    android:layout_width="match_parent" 
    android:layout_height="fill_parent" 
    android:layout_below="@+id/LinearLayouttools" 
    android:layout_above="@+id/lltexttools" 
    android:layout_gravity="center"> 

    <FrameLayout 
     android:id="@+id/frame" 
     android:layout_width="wrap_content" 
     android:layout_height="match_parent" 
     android:layout_gravity="center" 
     android:layout_centerInParent="true"> 

     <ImageView 
      android:id="@+id/imageView2" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_gravity="center" 
      android:scaleType="centerInside" /> 

    </FrameLayout> 

</RelativeLayout> 

我捕捉的FrameLayout與此代碼:

fOut = new FileOutputStream(file); 
framelayout.setDrawingCacheEnabled(true); 
Bitmap bitmap = framelayout.getDrawingCache(); 
bitmap.compress(Bitmap.CompressFormat.jpeg, 100, fOut); 
fOut.flush(); 
fOut.close(); 

,但周圍的人的照片是黑色的:

http://uupload.ir/files/z8cv_smsbaaz.ir_4.jpg

也當我設置scaleType =「FitXY」:

<ImageView 
android:id="@+id/imageView2" 
android:layout_width="wrap_content" 
android:layout_height="wrap_content" 
android:layout_gravity="center" 
android:scaleType="FitXY"/> 

image scale(我不想要縮放圖像) 我該如何解決這個問題?

回答

1

您可以使用下面的方法來創建視圖到位圖。

public static Bitmap loadBitmapFromView(View v) { 
    Bitmap b = Bitmap.createBitmap(v.getLayoutParams().width, v.getLayoutParams().height, Bitmap.Config.ARGB_8888);     
    Canvas c = new Canvas(b); 
    v.layout(v.getLeft(), v.getTop(), v.getRight(), v.getBottom()); 
    v.draw(c); 
    return b; 
} 

Converting a view to Bitmap without displaying it in Android?