简体   繁体   English

NFC标签上的图片

[英]Picture on NFC tags

With the latest NFC tags, it is possible to store up to 8k of data. 使用最新的NFC标签,最多可以存储8k数据。 So I would like to know how to store a picture on a tag, like the NXP TagWriter app. 因此,我想知道如何将图片存储在标签上,例如NXP TagWriter应用程序。

I found no information about it. 我没有找到任何信息。 Can anyone explain how to do that? 谁能解释该怎么做?

You can use MIME type records to store images on NFC tags. 您可以使用MIME类型记录将图像存储在NFC标签上。 If, for instance, your image is a JPEG image, you would use the MIME type "image/jpeg". 例如,如果您的图像是JPEG图像,则将使用MIME类型“ image / jpeg”。 You NDEF record could then look like this: 您的NDEF记录可能如下所示:

+----------------------------------------+
+ MB=1, ME=1, CF=0, SR=0, IL=0, TNF=MIME +
+----------------------------------------+
+ Type Length = 10                       +
+----------------------------------------+
+ Payload Length = N                     +
+----------------------------------------+
+ image/jpeg                             +
+----------------------------------------+
+ <Your image data (N bytes)>            +
+----------------------------------------+

On Android, you could create such a record using 在Android上,您可以使用

byte[] myImage = ...;
NdefRecord myImageRecord = NdefRecord.createMime("image/jpeg", myImage);

Or using the constructor of NdefRecord : 或使用NdefRecord的构造NdefRecord

byte[] myImage = ...;
NdefRecord myImageRecord = new NdefRecord(
        NdefRecord.TNF_MIME_MEDIA,
        "image/jpeg".getBytes("US-ASCII"),
        null,
        myImage
);

Once you have a Tag handle of an NDEF tag (ie through receiving and NFC discovery intent), you could then write the NDEF record to the tag: 一旦有了NDEF标签的Tag句柄(即通过接收和NFC发现意图),就可以将NDEF记录写入标签:

NdefMessage ndefMsg = new NdefMessage(new NdefRecord[] { myImageRecord });

Tag tag = ...;
Ndef ndefTag = Ndef.get(tag);
if (ndefTag != null) {
    ndefTag.connect();
    ndefTag.writeNdefMessage(ndefMsg);
    ndefTag.close();
} else {
    NdefFormatable ndefFormatable = NdefFormatable.get(tag);
    if (ndefFormatable != null) {
        ndefFormatable.connect();
        ndefFormatable.format(ndefMsg);
        ndefFormatable.close();
    }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM