截屏代码

来源:互联网 发布:淘宝店下架宝贝怎么做 编辑:程序博客网 时间:2024/04/28 15:16
截取应用 
private void getScreen(){    View content = findViewById(R.id.layoutroot);    Bitmap bitmap = content.getDrawingCache();    File file = new File( Environment.getExternalStorageDirectory() + "/test.png");    try     {        file.createNewFile();        FileOutputStream ostream = new FileOutputStream(file);        bitmap.compress(CompressFormat.PNG, 100, ostream);        ostream.close();    }     catch (Exception e)     {        e.printStackTrace();    }}

   


<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" /> 

view 写入图片

public Bitmap screenShot(View view) {    Bitmap bitmap = Bitmap.createBitmap(view.getWidth(),            view.getHeight(), Config.ARGB_8888);    Canvas canvas = new Canvas(bitmap);    view.draw(canvas);    return bitmap;}



Bitmap bitmap = Bitmap.createBitmap(width, height,Config.ARGB_8888);//创建一个你需要尺寸的BitmapCanvas canvas = new Canvas(bitmap);//用这个Bitmap生成一个Canvas,然后canvas就会把内容绘制到上面这个bitmap中Paint paint = new Paint();//定义一个画笔paint.setColor(Color.RED);//红色画笔canvas.drawText(text, x, y , paint);//绘制文案//绘制LogoBitmap logo = xxx;//获得你的Logobitmapcanvas.drawBitmap(logo, x,y, logo.getWidth(), logo.getHeight());



0 0
原创粉丝点击