zoukankan      html  css  js  c++  java
  • 16_读取bitmap资源在canvas绘画


    import java.io.IOException;
    import java.io.InputStream;

    import android.app.Activity;
    import android.content.Context;
    import android.content.res.AssetManager;
    import android.graphics.Bitmap;
    import android.graphics.BitmapFactory;
    import android.graphics.Canvas;
    import android.graphics.Rect;
    import android.os.Bundle;
    import android.util.Log;
    import android.view.View;
    import android.view.Window;
    import android.view.WindowManager;

    public class MainActivity extends Activity {
      

        @Override
        public void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            requestWindowFeature(Window.FEATURE_NO_TITLE);
            getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
                    WindowManager.LayoutParams.FLAG_FULLSCREEN);
            setContentView(new RenderView(this));
        }
    }


    class RenderView extends View {
        Bitmap bob565;
        Bitmap bob4444;
        Rect dst = new Rect();

        public RenderView(Context context) {
            super(context);

            try {
                AssetManager assetManager = context.getAssets();
                InputStream inputStream = assetManager.open("bobrgb888.png");
                bob565 = BitmapFactory.decodeStream(inputStream);
                inputStream.close();
                Log.d("BitmapText",
                        "bobrgb888.png format: " + bob565.getConfig());

                inputStream = assetManager.open("bobargb8888.png");
                BitmapFactory.Options options = new BitmapFactory.Options();
                options.inPreferredConfig = Bitmap.Config.ARGB_4444;
                bob4444 = BitmapFactory
                        .decodeStream(inputStream, null, options);
                inputStream.close();
                Log.d("BitmapText",
                        "bobargb8888.png format: " + bob4444.getConfig());

            } catch (IOException e) {
                // silently ignored, bad coder monkey, baaad!
            } finally {
                // we should really close our input streams here.
            }
        }

        protected void onDraw(Canvas canvas) {
            dst.set(50, 50, 350, 350);
            canvas.drawBitmap(bob565, null, dst, null);
            canvas.drawBitmap(bob4444, 100, 100, null);
            invalidate();
        }
    }

  • 相关阅读:
    delphi debug release区别是什么?
    Delphi异形窗口之PNG
    WebBrowser实现编辑网页
    父子窗体滚动条支持鼠标滚轮移动
    Com进程通信(Delphi2007)
    Android实例-Delphi开发蓝牙官方实例解析(XE10+小米2+小米5)
    教程-Close、Halt、terminate、ExitProcess的区别
    各国特种部队名称
    关于c#字典key不存在的测试
    关于scut使用WebService
  • 原文地址:https://www.cnblogs.com/xl711436/p/3060786.html
Copyright © 2011-2022 走看看