我将一个view转化为bitmap,然后将bitmap转化为图片存储到sdcard上,这些步骤都成功,结果在模拟器里用图片搜索,搜索不到图片,并且用eclipse把图片pull出来的图片也打不开,说文件编码格式不支持,但是在程序之中我用过各种格式及编码,效果还是一样,请问问题到底出在哪里,代码如下://触发截图事件
protected void onSaveClick(View v)
{
String strFilePath = getStrokeFilePath();
Bitmap bmp = m_sketchPad.getCanvasSnapshot();
if (null != bmp)
{
BitmapUtil.saveBitmapToSDCard(bmp, strFilePath);
}
}
//获取view转化为bitmap
public Bitmap getCanvasSnapshot()
{
setDrawingCacheEnabled(true);
buildDrawingCache(true);
Bitmap bmp = getDrawingCache(true); if (null == bmp)
{
android.util.Log.d("leehong2", "getCanvasSnapshot getDrawingCache == null");
}
return BitmapUtil.duplicateBitmap(bmp);
}
//犹如打水印一样,画在另一张图上
public static Bitmap duplicateBitmap(Bitmap bmpSrc)
{
if (null == bmpSrc)
{
return null;
}
int bmpSrcWidth = bmpSrc.getWidth();
int bmpSrcHeight = bmpSrc.getHeight();
//create a new blank bitmap
Bitmap bmpDest = Bitmap.createBitmap(bmpSrcWidth, bmpSrcHeight, Config.ARGB_8888);
if (null != bmpDest)
{
Canvas canvas = new Canvas(bmpDest);
final Rect rect = new Rect(0, 0, bmpSrcWidth, bmpSrcHeight);
canvas.drawBitmap(bmpSrc, rect, rect, null);
}
return bmpDest;
}//存到sdcard里
public static void saveBitmapToSDCard(Bitmap bmp, String strPath)
{
if (null != bmp && null != strPath && !strPath.equalsIgnoreCase(""))
{
try
{
File file = new File(strPath);
FileOutputStream fos = new FileOutputStream(file);
byte[] buffer = BitmapUtil.bitampToByteArray(bmp);
fos.write(buffer);
fos.flush();
fos.close();
}
catch (FileNotFoundException e)
{
e.printStackTrace();
}
catch (IOException e)
{
e.printStackTrace();
}
}
}
protected void onSaveClick(View v)
{
String strFilePath = getStrokeFilePath();
Bitmap bmp = m_sketchPad.getCanvasSnapshot();
if (null != bmp)
{
BitmapUtil.saveBitmapToSDCard(bmp, strFilePath);
}
}
//获取view转化为bitmap
public Bitmap getCanvasSnapshot()
{
setDrawingCacheEnabled(true);
buildDrawingCache(true);
Bitmap bmp = getDrawingCache(true); if (null == bmp)
{
android.util.Log.d("leehong2", "getCanvasSnapshot getDrawingCache == null");
}
return BitmapUtil.duplicateBitmap(bmp);
}
//犹如打水印一样,画在另一张图上
public static Bitmap duplicateBitmap(Bitmap bmpSrc)
{
if (null == bmpSrc)
{
return null;
}
int bmpSrcWidth = bmpSrc.getWidth();
int bmpSrcHeight = bmpSrc.getHeight();
//create a new blank bitmap
Bitmap bmpDest = Bitmap.createBitmap(bmpSrcWidth, bmpSrcHeight, Config.ARGB_8888);
if (null != bmpDest)
{
Canvas canvas = new Canvas(bmpDest);
final Rect rect = new Rect(0, 0, bmpSrcWidth, bmpSrcHeight);
canvas.drawBitmap(bmpSrc, rect, rect, null);
}
return bmpDest;
}//存到sdcard里
public static void saveBitmapToSDCard(Bitmap bmp, String strPath)
{
if (null != bmp && null != strPath && !strPath.equalsIgnoreCase(""))
{
try
{
File file = new File(strPath);
FileOutputStream fos = new FileOutputStream(file);
byte[] buffer = BitmapUtil.bitampToByteArray(bmp);
fos.write(buffer);
fos.flush();
fos.close();
}
catch (FileNotFoundException e)
{
e.printStackTrace();
}
catch (IOException e)
{
e.printStackTrace();
}
}
}
希望这篇文章可以帮到你噢 。