int width = mViewWidth;
int height = mViewHeight;
Bitmap bitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ALPHA_8);
Canvas canvas = new Canvas(bitmap);
String testString = "This is a test string";
canvas.drawText(testString, 0, height, mPaint);
File file = new File("/sdcard/storage/emulated/0/water/0.png");
String filename = file.getPath() ;
try {
FileOutputStream fos = new FileOutputStream(file);
boolean ret = bitmap.compress(Bitmap.CompressFormat.PNG, 100, fos);
fos.flush();
fos.close();
Uri data = Uri.parse(filename);
sendBroadcast( new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE , data));
} catch (Exception e) {
e.printStackTrace();
return false;
} 这行代码返回false
boolean ret = bitmap.compress(Bitmap.CompressFormat.PNG, 100, fos);
int height = mViewHeight;
Bitmap bitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ALPHA_8);
Canvas canvas = new Canvas(bitmap);
String testString = "This is a test string";
canvas.drawText(testString, 0, height, mPaint);
File file = new File("/sdcard/storage/emulated/0/water/0.png");
String filename = file.getPath() ;
try {
FileOutputStream fos = new FileOutputStream(file);
boolean ret = bitmap.compress(Bitmap.CompressFormat.PNG, 100, fos);
fos.flush();
fos.close();
Uri data = Uri.parse(filename);
sendBroadcast( new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE , data));
} catch (Exception e) {
e.printStackTrace();
return false;
} 这行代码返回false
boolean ret = bitmap.compress(Bitmap.CompressFormat.PNG, 100, fos);
checkRecycled("Can't compress a recycled bitmap");
// do explicit check before calling the native method
if (stream == null) {
throw new NullPointerException();
}
if (quality < 0 || quality > 100) {
throw new IllegalArgumentException("quality must be 0..100");
}
Trace.traceBegin(Trace.TRACE_TAG_RESOURCES, "Bitmap.compress");
boolean result = nativeCompress(mFinalizer.mNativeBitmap, format.nativeInt,
quality, stream, new byte[WORKING_COMPRESS_STORAGE]);
Trace.traceEnd(Trace.TRACE_TAG_RESOURCES);
return result;
}第一:你的/sdcard/storage/emulated/0/water 存在不?
第二:看看报错报哪里不就得了???
ALPHA_8:只存储透明度,没有颜色信息,你是画不出图片的。