代码如下
- package leadtools.datasetdemo;
- import leadtools.ILeadStream;
- import leadtools.LeadEvent;
- import leadtools.LeadSizeF;
- import leadtools.LeadStreamFactory;
- import leadtools.RasterColor;
- import leadtools.RasterImage;
- import leadtools.RasterImageFormat;
- import leadtools.RasterSizeFlags;
- import leadtools.codecs.RasterCodecs;
- import leadtools.controls.ImageViewerCenterAtInteractiveMode;
- import leadtools.controls.ImageViewerInteractiveMode;
- import leadtools.controls.ImageViewerNoneInteractiveMode;
- import leadtools.controls.ImageViewerSizeMode;
- import leadtools.controls.ImageViewerMagnifyGlassInteractiveMode;
- import leadtools.controls.ImageViewerPanZoomInteractiveMode;
- import leadtools.controls.RasterImageViewer;
- import leadtools.demos.Messager;
- import leadtools.demos.OpenFileDialog;
- import leadtools.demos.Progress;
- import leadtools.demos.SplashScreen;
- import leadtools.demos.Support;
- import leadtools.demos.Utils;
- import leadtools.dicom.DicomDataSet;
- import leadtools.dicom.DicomDataSetLoadFlags;
- import leadtools.dicom.DicomElement;
- import leadtools.dicom.DicomEngine;
- import leadtools.dicom.DicomGetImageFlags;
- import leadtools.dicom.DicomLoadAsyncCompletedListener;
- import leadtools.dicom.DicomTag;
- import leadtools.imageprocessing.ResizeCommand;
- import leadtools.imageprocessing.core.ResizeInterpolateCommand;
- import leadtools.imageprocessing.core.ResizeInterpolateCommandType;
- import android.os.AsyncTask;
- import android.os.Bundle;
- import android.os.Environment;
- import android.os.Handler;
- import android.app.Activity;
- import android.app.AlertDialog;
- import android.app.Dialog;
- import android.app.ProgressDialog;
- import android.content.Context;
- import android.content.DialogInterface;
- import android.content.DialogInterface.OnDismissListener;
- import android.graphics.Color;
- import android.graphics.PointF;
- import android.view.LayoutInflater;
- import android.view.Menu;
- import android.view.View;
- import android.view.View.OnClickListener;
- import android.view.ViewGroup;
- import android.view.WindowManager;
- import android.widget.Button;
- import android.widget.EditText;
- import android.widget.RadioButton;
- import android.widget.RadioGroup;
- import android.widget.RadioGroup.OnCheckedChangeListener;
- import android.widget.TextView;
- import android.widget.Toast;
- import java.io.File;
- import java.io.FileInputStream;
- import java.io.FileNotFoundException;
- import java.io.FileOutputStream;
- import java.net.URI;
- import java.net.URISyntaxException;
- public class DatasetDemoActivity extends Activity {
- private DicomDataSet _loadedDataSet;
- private RasterImageViewer _imageViewer;
- private TextView _noImageTextView;
- private RasterImage _loadedImage;
- private View _moreOptionsLinearLayout;
- private ImageViewerSizeMode _currentSizeMode;
- private ProgressDialog mProgressDlg;
- @Override
- protected void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.activity_main);
- DicomEngine.startup();
- if (Support.isKernelExpired()) {
- Messager.showKernelExpiredMessage(this, new OnDismissListener() {
- @Override
- public void onDismiss(DialogInterface dialog) {
- finish();
- }
- });
- return;
- }
- SplashScreen.show(this);
- _imageViewer = (RasterImageViewer) findViewById(R.id.imageviewer);
- _imageViewer.setImage(_loadedImage);
- _imageViewer.setAutoFreeImages(true);
- _noImageTextView = (TextView) findViewById(R.id.noImageTextView);
- _moreOptionsLinearLayout = (View) findViewById(R.id.moreOptionsLinearLayout);
- _currentSizeMode = ImageViewerSizeMode.FIT_ALWAYS;
- _imageViewer.setSizeMode(_currentSizeMode);
- _imageViewer.setTouchInteractiveMode(new ImageViewerPanZoomInteractiveMode());
- }
- public void onClickMoreButton(View view) {
- Button moreButton = (Button) view;
- if (_moreOptionsLinearLayout.getVisibility() == View.GONE) {
- moreButton.setText("Less...");
- _moreOptionsLinearLayout.setVisibility(View.VISIBLE);
- } else {
- moreButton.setText("More...");
- _moreOptionsLinearLayout.setVisibility(View.GONE);
- }
- }
- //频繁调用此函数会出现内存泄漏
- public void onClickFileOption(View view) {
- FileInputStream fileInputStream = null;
- try {
- fileInputStream = new FileInputStream("/sdcard/测试/测试/CR/CR.dcm");
- } catch (FileNotFoundException e) {
- e.printStackTrace();
- }
- if (fileInputStream != null) {
- ILeadStream leadStream = LeadStreamFactory.create(fileInputStream, true);
- if (leadStream != null) {
- mProgressDlg = Progress.show(DatasetDemoActivity.this, "", "Loading");
- DatasetDemoActivity.this.loadDataSetFromStream(leadStream);
- }
- }
- }
- private void loadDataSetFromStream(final ILeadStream stream) {
- String tempPath = "/data/data/leadtools.datasetdemo/";
- final DicomDataSet ds = new DicomDataSet(tempPath);
- ds.addLoadAsyncCompletedListener(new DicomLoadAsyncCompletedListener() {
- @Override
- public void onLoadAsyncCompleted() {
- _loadedDataSet = ds;
- DicomElement pixelDataElement = _loadedDataSet.findFirstElement(null, DicomTag.PIXEL_DATA, true);
- if (pixelDataElement != null) {
- int bitmapCount = ds.getImageCount(pixelDataElement);
- _noImageTextView.setVisibility(View.GONE);
- if (_loadedImage != null) {
- _loadedImage.dispose();
- _loadedImage = null;
- }
- _loadedImage = getDataSetImages(_loadedDataSet, pixelDataElement, bitmapCount);
- _imageViewer.setImage(_loadedImage);
- _imageViewer.setSizeMode(_currentSizeMode);
- _imageViewer.setPaintFlags(2);
- Progress.close(mProgressDlg);
- }
- }
- });
- ds.loadAsync(stream, DicomDataSetLoadFlags.LOAD_AND_CLOSE);
- }
- public RasterImage getDataSetImages(DicomDataSet ds, DicomElement element, int imageCount) {
- RasterImage resultImage = null;
- for (int x = 0; x < imageCount; x++) {
- RasterImage image = null;
- try {
- image = _loadedDataSet.getImage(element, x, 0, DicomGetImageFlags.AUTO_APPLY_MODALITY_LUT |
- DicomGetImageFlags.AUTO_APPLY_VOI_LUT);
- } catch (Exception ex) {
- //DemoUtilities.ShowToast(ex);
- }
- if (image != null) {
- if (x == 0) {
- resultImage = image;
- } else {
- resultImage.addPage(image);
- }
- } else {
- //string errorMsg = string.Format("Note that this dataset contains an invalid image. No image will be displayed ");
- //DemoUtilities.ShowToast(errorMsg);
- break;
- }
- }
- return resultImage;
- }
- }
复制代码
我已经调用dispose释放RasterImage内存,native heap 还是持续增长,是不是leadtools 的库有内存泄漏,还是我使用的不对,求解答,谢谢!!!!!!! |