keytek 0 Posted January 6 Report Share Posted January 6 Boa noite, estou a usar o seguinte código para converter uma imagem para formato raster e posteriormente enviar para a impressora por motivos de compatibilidade e requisitos dos QRCode, mas está a acontecer o que aparece na imagem, alguém já passou pelo mesmo? já testei em vários modelos acontece o mesmo. Public Shared Function ConvertImagetoBytes(BM As Bitmap) As Byte() Dim Data As BitMapData = GetBitmapData(BM) Dim Op As New MemoryStream Dim bw As New BinaryWriter(Op) bw.Write(Chr(Keys.Escape)) bw.Write("@"c) bw.Write(Chr(Keys.Escape)) bw.Write("3"c) bw.Write(CByte(24)) Dim offset As Integer = 0 Dim width As Byte() While offset < Data.Height bw.Write(Chr(Keys.Escape)) bw.Write("*"c) bw.Write(CByte(33)) width = BitConverter.GetBytes(Data.Width) bw.Write(width(0)) bw.Write(width(1)) For x As Integer = 0 To Data.Width - 1 For k As Integer = 0 To 2 Dim slice As Byte = 0 For b As Integer = 0 To 7 Dim y As Integer = (((offset \ 8) + k) * 8) + b Dim i As Integer = (y * Data.Width) + x Dim v As Boolean = False If i < Data.Dots.Length Then v = Data.Dots(i) End If slice = slice Or CByte((If(v, 1, 0)) << (7 - b)) Next bw.Write(slice) Next Next offset = offset + 24 bw.Write(vbLf.ToCharArray) End While bw.Write(Chr(Keys.Escape)) bw.Write("2"c) bw.Write(CByte(30)) bw.Flush() Return Op.ToArray End Function Private Shared Function GetBitmapData(BM As Bitmap) As BitMapData Dim threshold = 127 Dim index As Integer = 0 Dim dimensions As Integer = BM.Width * BM.Height Dim dots As BitArray = New BitArray(dimensions) Dim res As New BitMapData Dim a As Integer For y = 0 To BM.Height - 1 For x = 0 To BM.Width - 1 Dim col As Color = BM.GetPixel(x, y) Dim luminance = CInt(col.R * 0.3 + col.G * 0.59 + col.B * 0.11) If (luminance < threshold) = True Then a = 1 End If dots(index) = (luminance < threshold) index = index + 1 Next Next res.Dots = dots : res.Height = BM.Height : res.Width = BM.Width Return res End Function Private Class BitMapData Public Dots As BitArray Public Height As Int16 Public Width As Int16 End Class imagem do problema. Link to post Share on other sites
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now