Android:將View的內容對映成Bitmap轉圖片匯出
- contentLayout.setDrawingCacheEnabled(true);
- contentLayout.measure(
- MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED),
- MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED));
- contentLayout.layout(0, 0, contentLayout.getMeasuredWidth(),
- contentLayout.getMeasuredHeight());
- contentLayout.buildDrawingCache();
- //會報Canvas: trying to use a recycled bitmap android.graphics.Bitmap
- //Bitmap bitmap= contentLayout.getDrawingCache();
- //解決辦法:
//Copy the bitmap before you pass it to the static variable.
Bitmap bitmap = contentLayout.getDrawingCache(true);
//to
Bitmap bitmap
= Bitmap.createBitmap(contentLayout.getDrawingCache(true));
- public void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.set_view);
- contentLayout = (LinearLayout) findViewById(R.id.content);
- imgSource1 = (ImageView) findViewById(R.id.imgSource1);
- imgSource2 = (ImageView) findViewById(R.id.imgSource2);
- imgCache = (ImageView) findViewById(R.id.imgCache);
- imgSource1.setImageResource(R.drawable.source1);
- imgSource2.setImageResource(R.drawable.source2);
- contentLayout.setDrawingCacheEnabled(true);
- contentLayout.measure(
- MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED),
- MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED));
- contentLayout.layout(0, 0, contentLayout.getMeasuredWidth(),
- contentLayout.getMeasuredHeight());
- contentLayout.buildDrawingCache();
- Bitmap bitmap= contentLayout.getDrawingCache();
- if(bitmap!=null){
- imgCache.setImageBitmap(bitmap);
- }else{
- Log.i("CACHE_BITMAP", "DrawingCache=null");
- }
- }
- private void addRelativeLayout() {
- // TODO Auto-generated method stub
- RelativeLayout.LayoutParams layoutpare = new RelativeLayout.LayoutParams(
- LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT);
- RelativeLayout relativeLayout = new RelativeLayout(this);
- relativeLayout.setLayoutParams(layoutpare);
- ImageView imgView1 = new ImageView(this);
- ImageView imgView2 = new ImageView(this);
- imgView1.setImageResource(R.drawable.source1);
- imgView2.setImageResource(R.drawable.source2);
- RelativeLayout.LayoutParams img1 = new RelativeLayout.LayoutParams(38,
- 38);
- img1.addRule(RelativeLayout.ALIGN_PARENT_LEFT, RelativeLayout.TRUE);
- RelativeLayout.LayoutParams img2 = new RelativeLayout.LayoutParams(38,
- 38);
- img2.addRule(RelativeLayout.ALIGN_PARENT_RIGHT, RelativeLayout.TRUE);
- relativeLayout.addView(imgView1, img1);
- relativeLayout.addView(imgView2, img2);
- addViewContent.addView(relativeLayout);
- }
- /**
- * 新增圖片源
- */
- private void addImgSource() {
- ImageView imgView1 = new ImageView(this);
- ImageView imgView2 = new ImageView(this);
- imgView1.setImageResource(R.drawable.source1);
- imgView2.setImageResource(R.drawable.source2);
- addViewContent.addView(imgView1, new LayoutParams(
- LinearLayout.LayoutParams.WRAP_CONTENT,
- LinearLayout.LayoutParams.WRAP_CONTENT));
- addViewContent.addView(imgView2, new LayoutParams(
- LinearLayout.LayoutParams.WRAP_CONTENT,
- LinearLayout.LayoutParams.WRAP_CONTENT));
- }
相關文章
- 將treeview控制元件內容匯出圖片View控制元件
- 將網路圖片 轉化成bitmap
- 將Excel表格內容直接轉換成圖片Excel
- 利用網路請求將網路圖片轉換成Bitmap格式
- 將字串轉換成Bitmap型別 或者 將Bitmap轉換成字串字串型別
- 將 SAP ABAP 內表內容本地匯出成 Excel 檔案試讀版Excel
- 對映本地圖片地圖
- html2canvas將指定區域匯出為圖片(js將div匯出為圖片)HTMLCanvasJS
- Android把一個View轉成Bitmap+處理帶圓角View轉化後黑邊AndroidView
- PDF 轉換圖片然後識別圖片內容
- 如何將圖片轉換成影片?
- 利用bitmap將圖片部分顏色透明
- Android圖片快取之Bitmap詳解Android快取
- Android將view儲存為圖片並放在相簿中AndroidView
- 將網頁內容以圖片形式儲存在本地網頁
- 生成對抗網路,AI將圖片轉成漫畫風格AI
- 在ASP.NET中將資料直接輸出成Excel內容 (轉)ASP.NETExcel
- 如何將heic格式轉換成jpg圖片?
- 如何將一個PDF檔案裡的圖片批量匯出
- html5中將圖片的絕對路徑轉換成檔案物件HTML物件
- 怎麼將pdf轉換成jpg圖片格式
- Android 設定圖片 Bitmap任意透明度Android
- HTML 標籤(圖片對映、熱點)的使用HTML
- Activity轉換為View和把圖片轉換為ViewView
- Android 中 Base64 轉換成 圖片Android
- iOS圖片,視訊上傳&視訊內容旋轉iOS
- 圖片格式轉換,JPG圖片轉換成PDF
- 線上將網頁轉成PDF檔案\JPG圖片的工具網頁
- Android圖片編碼機制(Bitmap,Skia,libJpeg)Android
- 將dataGridView內容匯出到Excel檔案ViewExcel
- Bitmap的圖片壓縮彙總
- ThinkPHP6.0 內容匯出 Word 案例PHP
- Android 合併生成分享圖片(View截圖)AndroidView
- 圖片怎麼轉換成PDF,圖片轉PDF教程
- laravel結合maatwebsite/excel包,匯出excel,將部分內容設定不可LaravelWebExcel
- 將網站儲存成圖片網站
- 如何從將xcode工程中圖片pdf轉成png?XCode
- Laravel maatwebsite/excel 3.1 匯出圖片LaravelWebExcel