Message Boards Message Boards

1
|
5360 Views
|
4 Replies
|
2 Total Likes
View groups...
Share
Share this post:

Export vector image

Posted 10 years ago

Hello, I made a QR code and export it in this way

BarcodeImage["http://www.wolfram.com/", "QR"]
Export["QR.pdf", %]

but while i can scale the output of BarcodeImage without loss quality, if i scale the pdf (for example with Acrobat reader) i have a bad quality image.

How can I obtain a pdf file that can be scaled without loss of quality??

Many many thanks

POSTED BY: g p
4 Replies
Posted 10 years ago

Hello again; I did some tests and maybe there is a bug in BarcodeImage or BarcodeRecognize: I tried to test the code

Graphics[Rectangle[Reverse[#]{1,-1}]&/@Position[ImageData[BarcodeImage["http://www.wolfram.com/","QR"]],0]]

with some random string (here of length 500)

StringJoin[RandomChoice[CharacterRange["a", "z"], 500]]

I did

  Do[
     str = StringJoin[RandomChoice[CharacterRange["a", "z"], 500]];
     If[BarcodeRecognize[
        Graphics[
         Rectangle[Reverse[#] {1, -1}] & /@ 
          Position[ImageData[BarcodeImage[
             str
             , "QR"]], 0]]] == str, , Print[str], Print[str]]
     , {i, 50}]

and, for example, if i code the string

 str = "gfcrvuwurteqkcvuzuojiegqsyhkneoqpihetyenmacgrsvzzafpjdaqcuhqvbn\
    zscmcbcwuqfemjcvtyfrksngvyyjczlqdtqxgptcbsislzgxgzfqlqwliacnbpeaytoafc\
    hogzcjkiqtmlrhcyxnjaimeexmxwuhnattymjbpqgydledfvfnicjngdgvubqtumhfxugp\
    tmowvqufoliatwuilcmvdzlxjouvgzzmpyefmqfqvozgukksungahgmbyibqecmmfpgpna\
    nhksjtmvcvpryxtdeggpllpfitfhflvmrgikodtsbkyrxyqxugyfbmppugmzjnmxsnivhx\
    gtymhttvpcsqnvpajebblskmyqwodkprmyttdzcbzymcvofwwogudisnulczmxtzybmpav\
    ufpcvuxakcujuskrmqcexbpdixvmcphwrzigbyzicsoitsapycfnkpshgjlwyfibbcpcgd\
    ujdvvmqktzefwfdnm"

the decode gives

160886041590044

I suppose it's a Mathematica bug.

P.S. about the initial question, to save space in the pdf output we could use the code

 Graphics[Rectangle[First[#], Last[#] + {1, 1}] & /@ 
      Split[Reverse[#] {1, -1} & /@ 
        Position[
         ImageData[BarcodeImage["http://www.wolfram.com/", "QR", 1]], 0], 
       First[#1] + 1 == First[#2] &]]

that generates rectangles and not only squares (less rectangle and less bites ;) )

POSTED BY: g p

BarcodeImage produces a 1-bit bitmap, not a vector image. You can convert to vector Graphics this way:

   With[{mat = {{0, 1}, {-1, 0}}}, 
     Graphics[Flatten@
       MapIndexed[{If[#1 == 0, Rectangle[mat.#2, mat.#2 + {1, -1}], 
           Sequence @@ {}]} &, 
        ImageData[BarcodeImage["http://www.wolfram.com/", "QR"]], {2}]]]
POSTED BY: Gianluca Gorni

Or try:

Graphics[Rectangle[Reverse[#]{1,-1}]&/@Position[ImageData[BarcodeImage["http://www.wolfram.com/","QR"]],0]]

Which uses position which should be faster than scanning using mapIndexed and If.

POSTED BY: Sander Huisman
Posted 10 years ago

Hi I don't understand why BarcodeImage produces a bitmap image. However, in this situation, the Sander's solution is what I was looking for :)

By the way, I think it's better to consider the "size" option of BarcodeImage, in this way

BarcodeImage["http://www.wolfram.com/","QR" , 1 ]

so that ImageData gives an array in which every 0 corresponds to a black square and every 1 to a white square. So

Graphics[Rectangle[Reverse[#] {1, -1}] & /@ 
  Position[ImageData[
    BarcodeImage["http://www.wolfram.com/", "QR", 1]], 0]]

is a very good solution

Many many thanks to you all!! :)

POSTED BY: g p
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract