有人请尝试向我解释原因
public void addView(View child) {
child.setDrawingCacheEnabled(true);
child.setWillNotCacheDrawing(false);
child.setWillNotDraw(false);
child.buildDrawingCache();
if(child.getDrawingCache() == null) { //TODO Make this work!
Log.w("View", "View child's drawing cache is null");
}
setImageBitmap(child.getDrawingCache()); //TODO MAKE THIS WORK!!!
}
Run Code Online (Sandbox Code Playgroud)
ALWAYS记录绘图缓存为空,并将位图设置为null?
在设置缓存之前,我是否必须实际绘制视图?
谢谢!
我需要将视图转换为位图以预览我的视图并将其保存为图像.我尝试使用以下代码,但它创建了一个空白图像.我无法理解我犯了什么错误.
View viewToBeConverted; Bitmap viewBitmap = Bitmap.createBitmap(viewToBeConverted.getWidth(), viewToBeConverted.getHeight(),Bitmap.Config.ARGB_8888);
Canvas canvas = new Canvas(viewBitmap);
viewToBeConverted.draw(canvas);
savephoto(“f1”, viewBitmap);
//// public void savephoto(String filename,Bitmap bit)
{
File newFile = new File(Environment.getExternalStorageDirectory() + Picture_Card/"+ filename+ ".PNG");
try
{
newFile.createNewFile();
try
{
FileOutputStream pdfFile = new FileOutputStream(newFile); Bitmap bm = bit; ByteArrayOutputStream baos = new ByteArrayOutputStream(); bm.compress(Bitmap.CompressFormat.PNG,100, baos); byte[] bytes = baos.toByteArray();
pdfFile.write(bytes);
pdfFile.close();
}
catch (FileNotFoundException e)
{ //
}
} catch (IOException e)
{ //
}
}
Run Code Online (Sandbox Code Playgroud) 我正在开发一个简单的相机应用 我有代码截取整个活动的截图并将其写入Sd卡.问题是Surfaceview返回黑屏.
我想知道如何独立拍摄surfaceview的截图.这是获取整个活动屏幕截图的代码.
findViewById(R.id.screen).setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
final RelativeLayout layout = (RelativeLayout) findViewById(R.id.RelativeLayout1);
layout.setVisibility(RelativeLayout.GONE);
Bitmap bitmap = takeScreenshot();
Toast.makeText(getApplicationContext(),"Please Wait", Toast.LENGTH_LONG).show();
saveBitmap(bitmap);
}
});
}
public Bitmap takeScreenshot() {
View rootView = findViewById(android.R.id.content).getRootView();
rootView.setDrawingCacheEnabled(true);
return rootView.getDrawingCache();
}
public void saveBitmap(Bitmap bitmap) {
final MediaPlayer cheer = MediaPlayer.create(PicShot.this, R.raw.shutter);
cheer.start();
Random generator = new Random();
int n = 10000;
n = generator.nextInt(n);
String fname = "Image-"+ n +".png";
final RelativeLayout layout = (RelativeLayout) findViewById(R.id.RelativeLayout1);
File imagePath …Run Code Online (Sandbox Code Playgroud) 我正在尝试截取LinearLayout的内容.布局包含一个可以高度/宽度可变的滚动视图.当布局不是太大时(即您不需要在屏幕上滚动很多以查看所有内容),此代码可以正常工作:
View v1 = (LinearLayout)theLayout;
v1.setDrawingCacheEnabled(true);
Bitmap bitmap = Bitmap.createBitmap(v1.getDrawingCache());
v1.setDrawingCacheEnabled(false);
Run Code Online (Sandbox Code Playgroud)
但是,如果我尝试捕获的LinearLayout很大,则应用程序在v1.getDrawingCache()上使用空指针崩溃.
logcat中有一个错误:
05-11 13:16:20.999:W/View(17218):视图太大而无法适应绘图缓存,需要4784400字节,只有3932160可用
如何正确截取此布局的屏幕截图?还有另一种方法可以解决它没有使用如此多的内存吗?
主要问题是将整个滚动视图保存为位图图像,而不仅仅是屏幕上显示的内容.有没有办法保存整个滚动视图,如果是这样如何?
我有一个MainActivity和3个碎片 -
我必须用PageCurl EffectA-> B-> C 替换片段
我如何使用PageCurl EffectFragments?
我已阅读PageCurl链接,但它们仅用于图像.
在我的Fragment的布局中,我有一个带有LinearLayout的ScrollView
<ScrollView
android:id="@+id/scrollview"
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<LinearLayout
android:id="@+id/container"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
<!-- Other views -->
</LinearLayout>
</ScrollView>
Run Code Online (Sandbox Code Playgroud)
所以我需要创建和分享scrollview的整个内容的图片.我试过的所有解决方案都只截取可见区域的截图,而不是整个scrollview内容.我能怎么做?
android ×8
screenshot ×3
android-view ×2
bitmap ×2
camera ×1
page-curl ×1
scrollview ×1
surfaceview ×1
view ×1