如何在android的当前活动图像视图中显示画布 [英] how to display Canvas in current activity Image view in android

查看:144
本文介绍了如何在android的当前活动图像视图中显示画布的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

public class AndroidBarcodeView extends ImageView {

    public AndroidBarcodeView(Context context) {
        super(context);
    }

    @Override
    protected void onDraw(Canvas canvas) {
        super.onDraw(canvas);

        try {

            testQRCode(canvas);

        } catch (Exception e) {
            e.printStackTrace();
        }
    }


    private static void testQRCode(Canvas canvas) throws Exception {
        QRCode barcode = new QRCode();

        /*
         * QRCode Valid data char set: numeric data (digits 0 - 9); alphanumeric
         * data (digits 0 - 9; upper case letters A -Z; nine other characters:
         * space, $ % * + - . / : ); byte data (default: ISO/IEC 8859-1); Kanji
         * characters
         */
        // BIZCARD:N:Kelly;X:Goto;T:Design Ethnographer;C:gotomedia LLC;A:2169
        // Folsom Street
        // M302;B:4158647007;F:4158647004;M:4159907005;E:kelly@gotomedia.com;;
        // barcode.setData("BIZCARD:N:Kelly;X:Goto;T:Design Ethnographer;C:gotomedia LLC;A:2169 Folsom Street M302;B:4158647007;F:4158647004;M:4159907005;E:kelly@gotomedia.com;;");

        barcode.setData("StudentId:11;SectionId:A2;TimeStamp:20-04-2015 12:18PM;;");

        barcode.setDataMode(QRCode.M_AUTO);
        barcode.setVersion(1);
        barcode.setEcl(QRCode.ECL_L);

        // if you want to encode GS1 compatible QR Code, you need set FNC1 mode
        // to IBarcode.FNC1_ENABLE
        barcode.setFnc1Mode(IBarcode.FNC1_NONE);

        // Set the processTilde property to true, if you want use the tilde
        // character "~" to specify special characters in the input data.
        // Default is false.
        // 1-byte character: ~ddd (character value from 0 ~ 255)
        // ASCII (with EXT): from ~000 to ~255
        // 2-byte character: ~6ddddd (character value from 0 ~ 65535)
        // Unicode: from ~600000 to ~665535
        // ECI: from ~7000000 to ~7999999
        // SJIS: from ~9ddddd (Shift JIS 0x8140 ~ 0x9FFC and 0xE040 ~ 0xEBBF)
        barcode.setProcessTilde(false);

        // unit of measure for X, Y, LeftMargin, RightMargin, TopMargin,
        // BottomMargin
        barcode.setUom(IBarcode.UOM_PIXEL);
        // barcode module width in pixel
        barcode.setX(3f);

        barcode.setLeftMargin(50f);
        barcode.setRightMargin(50f);
        barcode.setTopMargin(50f);
        barcode.setBottomMargin(50f);
        // barcode image resolution in dpi
        barcode.setResolution(72);

        // barcode bar color and background color in Android device
        barcode.setForeColor(AndroidColor.black);
        barcode.setBackColor(AndroidColor.white);

        /*
         * specify your barcode drawing area
         */
        RectF bounds = new RectF(0, 0, 0, 0);
        barcode.drawBarcode(canvas, bounds);
    }

}

使用这个时能够产生酒吧,code

using this am able to generate bar-code :

这是我的code:

 Imageview img;
@Override
    public void onClick(View v) {
        // TODO Auto-generated method stub
        if (v.getId() == R.id.textView3) {
            AndroidBarcodeView view = new AndroidBarcodeView(
                    StudentManinPage.this);
            setContentView(view);
        }

    }  

在这里我要对ImageView的显示条code,但,当我点击生成酒吧code则显示栏code,但它目前的actvity ImageView的亘古不显示它在另一个视图中显示,请帮助我在当前活动的ImageView的显示我有IMG ImageView的。

where i have to display Barcode on Imageview But when i click on generate bar code then it display barcode but it doesnot display in current actvity imageview it display in another view please help me to display in current activity on imageview i have img imageview .

推荐答案

我不会写code你。这仅仅是对你问题的答案:

I won't write code for you. This is just an answer on your question:

查找和替换 RectF边界=新RectF(0,0,0,0); RectF边界=新RectF(0,0 ,canvas.getWidth(),canvas.getHeight());

public class AndroidBarcodeView extends ImageView {
    //...
    private static void testQRCode(Canvas canvas) throws Exception {
      //...
      RectF bounds = new RectF(0, 0, canvas.getWidth(), canvas.getHeight());
      barcode.drawBarcode(canvas, bounds);
    }
}


public class StudentManinPage extends Activity {
  //...
  @Override
  protected void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);

      AndroidBarcodeView bar_code_view = new AndroidBarcodeView(this);
      bar_code_view.setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT));

      setContentView(bar_code_view);
      //...
  }
  //...
}

这篇关于如何在android的当前活动图像视图中显示画布的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆