tag:blogger.com,1999:blog-1661517518925762010.post6631796616290617749..comments2023-11-30T22:48:28.111-08:00Comments on Java-Buddy: QRCode generator on JavaFX, using ZXingErikhttp://www.blogger.com/profile/04983894331825656853noreply@blogger.comBlogger5125tag:blogger.com,1999:blog-1661517518925762010.post-72178041028847526552017-08-09T11:22:42.653-07:002017-08-09T11:22:42.653-07:00This can be doen with _pure_ JavaFX as well: No ne...This can be doen with _pure_ JavaFX as well: No need foor java.awt nor SwingFXUtils.<br /><br />Replace the code from line 32 (which is unused anyway) until line 60 with what is below.<br />Notice how the same action plan is used as before (white rectange, filled in black bit by bit), but now using JavaFX objects instead of Swing.<br /><br /><br /> try {<br /> BitMatrix bitMatrix = qrCodeWriter.encode(inputUrl, BarcodeFormat.QR_CODE, width, height);<br /><br /> //Create a Canvas (a place to draw on), with a 2D Graphic (a kind of drawing)<br /> Canvas canvas = new Canvas(width, height);<br /> GraphicsContext gc2D = canvas.getGraphicsContext2D();<br /><br /> //in white, paint a rectangle on it, with the full size<br /> gc2D.setFill(javafx.scene.paint.Color.WHITE);<br /> gc2D.fillRect(0, 0, width, height);<br /><br /> //start painting in black: each bit/pixel set in the bitMatix<br /> gc2D.setFill(javafx.scene.paint.Color.BLACK);<br /> for (int v = 0; v < height; v++) {<br /> for (int h = 0; h < width; h++) {<br /> if (bitMatrix.get(v, h)) {<br /> gc2D.fillRect(h, v, 1, 1);<br /> }<br /> }<br /> }<br /><br /> //Take a snapshot of the canvas and set it as an image in the ImageView control<br /> qrView.setImage(canvas.snapshot(null, null));<br /> } catch (WriterException e) {<br /> e.printStackTrace();<br /> }<br /><br /><br />Notes:<br />1) you don't need to spell out the colors in full (javafx.scene.paint.Color.WHITE).<br />I needed it since the swing/awt imports were still present and the wrong kind of Color was used...<br />2) I created the ImageView (called qrView) elsewhere (using FXML) that is why there is no line<br />ImageView qrView = new ImageView();<br />in my code. It can be addes if needed, obviously.<br />3) I moved the qrView.setImage() inside the try {}, since this was more convenient for me: the canvas lives only there.<br />4) Imports:<br />import com.google.zxing.BarcodeFormat;<br />import com.google.zxing.WriterException;<br />import com.google.zxing.common.BitMatrix;<br />import com.google.zxing.qrcode.QRCodeWriter;<br />import javafx.scene.canvas.Canvas;<br />import javafx.scene.canvas.GraphicsContext;<br />import javafx.scene.image.ImageView;<br />import javafx.scene.paint.Color;<br />Remove<br /> - java.awt.*<br /> - javafx.embed.swing.SwingFXUtils;<br />5) I added some more comments to explain what is going on.<br />6) Notice how I used "h" and "v" (for Horizontal and Vertical) instead of "i" and "j" as loop counters.<br />This is more verbose and exposed that the original code has the axes flipped...<br />I guess that caused no problems because it was done twice ("byteMatrix.get(i, j)" and "graphics.fillRect(i, j, 1, 1)") and/or since QR-codes still work when flipped and mirorred etc.Unknownhttps://www.blogger.com/profile/15860778794186448643noreply@blogger.comtag:blogger.com,1999:blog-1661517518925762010.post-64199994280585627792017-05-09T07:00:16.883-07:002017-05-09T07:00:16.883-07:00Thanks Working Perfect
Thanks Working Perfect<br />இம்மானுவேல்.மhttps://www.blogger.com/profile/02741978310549470791noreply@blogger.comtag:blogger.com,1999:blog-1661517518925762010.post-43110192101055477902017-04-04T06:20:44.180-07:002017-04-04T06:20:44.180-07:00i want code for image based barcode or Qr code sca...i want code for image based barcode or Qr code scanning with zxing library.somone pls help me...Projunhttps://www.blogger.com/profile/16276273696822501656noreply@blogger.comtag:blogger.com,1999:blog-1661517518925762010.post-87070526470893842632017-02-19T04:15:55.146-08:002017-02-19T04:15:55.146-08:00just replace code segment String myWeb ="ente...just replace code segment String myWeb ="enter your text "<br />with any text you wantgkhttps://www.blogger.com/profile/06085579205367471966noreply@blogger.comtag:blogger.com,1999:blog-1661517518925762010.post-26966666040398206432017-01-05T00:20:51.231-08:002017-01-05T00:20:51.231-08:00How to edit to generate a code that reads somethin...How to edit to generate a code that reads something other than java-buddy.blogspot.inAnonymoushttps://www.blogger.com/profile/01475889421860397456noreply@blogger.com