我使用代码将图片转换为位图:
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。 文件转换到位图是否有任何常用功能。 我想在位图中发送到服务器文件。
答案 0 :(得分:1)
我正在使用Retrofit将所有类型的文件转换为Bitmap.by使用此Retrofit非常轻松,轻松地转换为位图android