如何将图像,Pdf,Docx和Doc文件转换为位图[关闭]

问题描述 投票:0回答:1

我正在使用代码将图像转换为位图:

public Bitmap getBitmap() throws IOException {
        if (!getInformation())
            throw new FileNotFoundException();

        if (!getStoredDimensions())
            throw new InvalidObjectException(null);

        RectF rect = new RectF(0, 0, storedWidth, storedHeight);
        orientation.mapRect(rect);
        int width = (int) rect.width();
        int height = (int) rect.height();
        int subSample = 1;

        while (width > MAX_WIDTH || height > MAX_HEIGHT) {
            width /= 2;
            height /= 2;
            subSample *= 2;
        }

        if (width == 0 || height == 0)
            throw new InvalidObjectException(null);

        BitmapFactory.Options options = new BitmapFactory.Options();
        options.inSampleSize = subSample;
        Bitmap subSampled = BitmapFactory.decodeStream(resolver.openInputStream(uri), null, options);

        Bitmap picture;
        if (!orientation.isIdentity()) {
            picture = Bitmap.createBitmap(subSampled, 0, 0, options.outWidth, options.outHeight,
                    orientation, false);
            subSampled.recycle();
        } else
            picture = subSampled;

        return picture;
    }

我面临的问题是如何从Pdf,Docx和Doc扩展文件转换为Bitmap。文件转换到位图是否有任何常用功能。我想发送到位图中的服务器文件。

android pdf docx doc
1个回答
1
投票

我使用Retrofit将所有类型的文件转换为Bitmap.by使用这个Retrofit非常容易和轻松转换成位图android

© www.soinside.com 2019 - 2024. All rights reserved.