사용자 정의 ContentProvider를 사용하고 openFile()을 재정 의하여 스트림을 Tempfile로 반환하십시오.
URI를 HTML A 태그의 src로 사용할 수 있습니다. @goldenparrot 화상의 주석에 기초
<a src="Example://file"></a>
는
public class ExampleProvider extends ContentProvider {
@Override
public ParcelFileDescriptor openFile(Uri uri, String mode) throws FileNotFoundException {
//Get your bitmap
Bitmap bmp = BitmapFactory.decodeResource(getContext().getResources(), R.drawable.file_example);
File tempFile = null;
try {
//Create the tempfile form a stream
tempFile = File.createTempFile("tempfile", ".thumb", getContext().getCacheDir());
BufferedOutputStream out = new BufferedOutputStream(new FileOutputStream(tempFile));
bmp.compress(Bitmap.CompressFormat.JPEG, 100, out);
out.close();
if(mode.equals("r")) {
return ParcelFileDescriptor.open(tempFile, ParcelFileDescriptor.MODE_READ_ONLY);
}
}
catch(IOException e) {
LOGGER.error("Couldn't generate temp file for thumb view, guid:" + guid, e);
}
finally {
if(tempFile != null {
//The unix filesystem automatically deletes the file once all handles are gone
tempFile.delete();
}
}
}
}
이 발생한다? Jelly Bean (4.1.1)에서 작동합니다. 캔버스에서 이미지를 생성 할 수 있으며 문제없이 저장할 수 있습니다. – alex
src와 함께 img를 만드는 대신 CSS 스타일'background-image : url (data : image/png; base64datahere ....);가있는 div를 만들면 어떻게 될까요? – Prasanth