android–canvas部分放大

android–canvas部分放大,第1张

概述我想部分放大帆布板,因为字母托盘按钮将被固定,而且电路板将被缩放,部分编码如下所述,屏幕完全画在画布上,可以在底部看到..请帮忙,谢谢你的关注.publicclassBoardViewextendsSurfaceViewimplementsSurfaceHolder.Callback{classDrawi

我想部分放大帆布板,因为字母托盘按钮将被固定,而且电路板将被缩放,
部分编码如下所述,屏幕完全画在画布上,可以在底部看到..请帮忙,谢谢你的关注.

        public class BoardVIEw extends SurfaceVIEw implements SurfaceHolder.Callback                {        class DrawingThread extends Thread implements OntouchListener {        public DrawingThread(SurfaceHolder holder, Handler handler) {                    mSurfaceHolder = holder;        public voID setRunning(boolean b) {                    mRun = b;                }                @OverrIDe                public voID run() {                    while (mRun) {                        Canvas c = null;                        try {                            c = mSurfaceHolder.lockCanvas(null);        synchronized (mSurfaceHolder) {                                // System.gc();                                // c.scale(canvasScaleX, canvasScaleY);                                // c.save();                                // c.translate(canvasTranslateX, canvasTranslateY);                                doDraw(c);                            }                            updateGame();                        } finally {                            if (c != null) {                                mSurfaceHolder.unlockCanvasAndPost(c);                            }                        }        }        private voID doDraw(Canvas canvas) {                    if (ge == null)                        return;                        Rect bRect = new Rect(0, 0, dims.getTotalWIDth(),                        dims.getscoreHeight() + dims.getBoardheight());                Drawable drawable = getResources().getDrawable(R.drawable.board);                drawable.setBounds(bRect);                drawable.draw(canvas);                Rect tRect = new Rect(0, dims.getscoreHeight()                        + dims.getBoardheight(), dims.getTotalWIDth(),                        dims.getTotalHeight());                canvas.drawRect(tRect, fillTrayPaint);                int topHeight = dims.getscoreHeight() + dims.getBoardheight();                int bottom = (dims.getTotalHeight() + 5)                        - (dims.getTotalWIDth() / Tray.TRAY_SIZE);                Rect rect = new Rect(0, topHeight, dims.getTotalWIDth(), bottom - 7);                Drawable drawableTray = getResources()                        .getDrawable(R.drawable.strip);                drawableTray.setBounds(rect);                drawableTray.draw(canvas);                        drawTray(canvas);                drawBoard(canvas);                // drawscore(canvas);                drawMovingTile(canvas);            }public BoardVIEw(Context context, AttributeSet attrs) {        super(context, attrs);        SurfaceHolder holder = getHolder();        holder.addCallback(this);        // endTurn=(Imagebutton)findVIEwByID(R.ID.endturn_button_horizontal);        thread = new DrawingThread(holder, handler);    }@OverrIDe    public voID surfaceChanged(SurfaceHolder holder, int format, int wIDth,            int height) {    }    @OverrIDe    public voID surfaceCreated(SurfaceHolder holder) {        final float scale1 = getResources().getdisplayMetrics().density;        defaultFontSize = (int) (MIN_Font_DIPS * scale1 + 0.5f);        thread.setDefaultFontSize(defaultFontSize);        dimensions = calculateDimensions(getWIDth(), getHeight());        thread.setDimensions(dimensions);        thread.setRunning(true);        // if (thread != null && !thread.isAlive())        thread.start();    }    @OverrIDe    public voID surfaceDestroyed(SurfaceHolder holder) {        boolean retry = true;        thread.setRunning(false);        while (retry) {            try {                thread.join();                retry = false;            } catch (InterruptedException e) {            }        }    }

解决方法:

我们可以通过canvas.clipRect(rectangle)来完成它,此时我们要做的是保存画布canvas.save()并在canvas.clipRect(rectangle)之后调用canvas.restore().

总结

以上是内存溢出为你收集整理的android – canvas部分放大全部内容,希望文章能够帮你解决android – canvas部分放大所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/web/1118880.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-29
下一篇 2022-05-29

发表评论

登录后才能评论

评论列表(0条)

保存