Android加载大图像打印

时间:2018-06-03 03:41:53

标签: android printing bitmap out-of-memory

我正在开发一款设计应用。它需要创建一个非常大的不可见视图,里面有图像然后将其转换为位图以进行打印,但Android不允许我将如此巨大的图像加载到内存中。有没有解决办法呢。

1 个答案:

答案 0 :(得分:0)

您不必采取隐形视图并加载图像。您可以直接在图像视图中加载图像并将其转换为位图。这是我的代码,我用XML加载图像,然后在位图中转换整个XML文件,因为我还有很多其他东西要在Bitmap中转换。希望这段代码可以帮到你。

RawMapInfoWindowBinding rawMapInfoWindowBinding = DataBindingUtil.inflate(getLayoutInflater(), R.layout.raw_map_info_window, (ConstraintLayout) mBinding.getRoot(), false);

rawMapInfoWindowBinding.clLike.measure( View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED), View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED)); rawMapInfoWindowBinding.clLike.layout(0, 0, rawMapInfoWindowBinding.clLike.getMeasuredWidth(), rawMapInfoWindowBinding.clLike.getMeasuredHeight());

我用滑动来加载我的图像

enter code here

    try {

        GlideApp.with(this).asBitmap().centerCrop().circleCrop().load(statusModel.profileurl)
                .diskCacheStrategy(DiskCacheStrategy.ALL).listener(new RequestListener<Bitmap>() {
            @Override
            public boolean onLoadFailed(@Nullable GlideException e, Object model, Target<Bitmap> target, boolean isFirstResource) {
                LogUtils.LOGE(TAG, "onLoadFailed: " + statusModel.statusID);
                Log.e(TAG, "onLoadFailed --------- " + isSearching);
                return false;
            }

            @Override
            public boolean onResourceReady(Bitmap bitmap, Object model, Target<Bitmap> target, DataSource dataSource, boolean isFirstResource) {
           rawMapInfoWindowBinding.ivProfileImage.setImageBitmap(bitmap);
           return true;
            }
        }).submit(100, 100);

    } catch (Throwable t) {
        t.printStackTrace();
    }
}`