Skip to content

Commit

Permalink
Fix compatibility of convert to data to better support vector pictures
Browse files Browse the repository at this point in the history
  • Loading branch information
wqweto committed Jan 29, 2024
1 parent b7a0d14 commit a927668
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 4 deletions.
6 changes: 5 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,11 @@ Note that you can stretch/zoom the returned picture to any size without loss of
### MS Access Support

For compatibility with image controls on forms/reports you can use `QRCodegenConvertToData` function like this:
```
Image0.PictureData = QRCodegenConvertToData(QRCodegenBarcode("Sample text"))
```
If this does not work in your version of MS Access (for some reason) then you can try converting QR Code to a bitmap instead like this:
```
Image0.PictureData = QRCodegenConvertToData(QRCodegenBarcode("Sample text"), 500, 500)
```
Note that this produces bitmap picture of the QR Code so might need to tweak output size parameters.
Note that this produces 500x500 bitmap picture of the QR Code so might need to tweak output size parameters.
14 changes: 11 additions & 3 deletions src/mdQRCodegen.bas
Original file line number Diff line number Diff line change
Expand Up @@ -440,6 +440,7 @@ Public Function QRCodegenConvertToData(ByVal pPicture As IPicture, Optional ByVa
Dim cSize As Currency
Dim baOutput() As Byte
Dim hResult As Long
Dim lOffset As Long

If pPicture Is Nothing Then
baOutput = vbNullString
Expand All @@ -449,6 +450,7 @@ Public Function QRCodegenConvertToData(ByVal pPicture As IPicture, Optional ByVa
'--- super sample to 4x4 for cheap anti-aliasing
Set pPicture = QRCodegenResizePicture(pPicture, NewWidth * 4, NewHeight * 4)
Set pPicture = QRCodegenResizePicture(pPicture, NewWidth, NewHeight)
lOffset = 8
End If
Set pStream = SHCreateMemStream(ByVal 0, 0)
If IID_IPersistStream(0) = 0 Then
Expand All @@ -466,19 +468,25 @@ Public Function QRCodegenConvertToData(ByVal pPicture As IPicture, Optional ByVa
If hResult < 0 Then
Err.Raise hResult, "IStream.Seek(STREAM_SEEK_END)"
End If
If cSize <= 8 Then
If cSize * 10000@ <= lOffset Then
baOutput = vbNullString
GoTo QH
End If
ReDim baOutput(0 To cSize * 10000@ - 9) As Byte
hResult = DispCallByVtbl(pStream, IDX_SEEK, 0.0008@, STREAM_SEEK_SET, VarPtr(cSize))
ReDim baOutput(0 To cSize * 10000@ - lOffset - 1) As Byte
hResult = DispCallByVtbl(pStream, IDX_SEEK, CCur(lOffset / 10000@), STREAM_SEEK_SET, VarPtr(cSize))
If hResult < 0 Then
Err.Raise hResult, "IStream.Seek(STREAM_SEEK_SET)"
End If
hResult = DispCallByVtbl(pStream, IDX_READ, VarPtr(baOutput(0)), UBound(baOutput) + 1, VarPtr(cSize))
If hResult < 0 Then
Err.Raise hResult, "IStream.Read"
End If
If lOffset = 0 Then
baOutput(0) = &HE
For lOffset = 1 To 7
baOutput(lOffset) = 0
Next
End If
QH:
QRCodegenConvertToData = baOutput
End Function
Expand Down

0 comments on commit a927668

Please sign in to comment.