我尝试截图View
但R.id.layout
无法解决或不是字段
然后我尝试 import com.example.mye_card.R;
清理但不工作
btnsave.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
View v2 = findViewById(R.id.layout);
v2.setDrawingCacheEnabled(true);
Bitmap bmp = Bitmap.createBitmap(v2.getDrawingCache());
v2.setDrawingCacheEnabled(false);
try {
Date d = new Date();
String filename = (String)DateFormat.format("kkmmss-MMddyyyy"
, d.getTime());
File dir = new File(Environment.getExternalStorageDirectory(), "/Pictures/" + filename );
FileOutputStream out = new FileOutputStream(dir);
ByteArrayOutputStream bos = new ByteArrayOutputStream();
bmp.compress(Bitmap.CompressFormat.JPEG, 100, bos);
out.write(bos.toByteArray());
Toast.makeText(getApplicationContext(), "Save card!", Toast.LENGTH_SHORT).show();
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
});
错误线
View v2 = findViewById(R.id.layout);
关于进口
package com.example.mye_card;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.Date;