bytearray

How can I print an image on a Bluetooth printer in Android?

蹲街弑〆低调 提交于 2019-12-17 02:27:20
问题 I have to print some data on thermal bluetooth printer, I'm doing with this: String message="abcdef any message 12345"; byte[] send; send = message.getBytes(); mService.write(send); It works well for text, but not for images. I think I need to get the byte[] of the image data. I tried getting the data of the image this way: Bitmap bitmap=BitmapFactory.decodeResource(getResources(), R.drawable.qrcode); ByteArrayOutputStream stream=new ByteArrayOutputStream(); bitmap.compress(Bitmap

How to convert NSData to byte array in iPhone?

时光怂恿深爱的人放手 提交于 2019-12-17 02:24:26
问题 I want to convert NSData to a byte array, so I write the following code: NSData *data = [NSData dataWithContentsOfFile:filePath]; int len = [data length]; Byte byteData[len]; byteData = [data bytes]; But the last line of code pops up an error saying "incompatible types in assignment". What is the correct way to convert the data to byte array then? 回答1: You can't declare an array using a variable so Byte byteData[len]; won't work. If you want to copy the data from a pointer, you also need to

How Do I Create a System.Windows.Media.ImageSource From a Byte Array?

流过昼夜 提交于 2019-12-14 03:39:51
问题 How do I create a System.Windows.Media.ImageSource from a byte array? I have a byte array, containing the exact and complete file contents of a TIFF image file. I need to display this on the screen, and I have no idea where to even start. Supposedly, it can be done (according to my boss, our dev team has done it in the past, but nobody remembers how). Has anyone here ever done something like this before? 回答1: BitmapImage bi = new BitmapImage(); bi.BeginInit(); bi.StreamSource = new

Find single line comments in byte array

房东的猫 提交于 2019-12-14 03:37:18
问题 Is it possible to find instances of // in a line read from a file into a byte array and then "snip" from // to the end of the line out? I'm trying FileInputStream fis = new FileInputStream(file); byte[] buffer = new byte[8 * 1024]; int read; while ((read = fis.read(buffer)) != -1) { for (int i = 0; i < read; i++) { if (buffer[i] == '//') { buffer = buffer[0:i]; } } } but I'm getting Invalid character constant at if (buffer[i] == '//') on the '//' part. Am I doing something wrong, or is this

How to fix corrupt byte[]-s in win socket

不羁的心 提交于 2019-12-14 03:21:34
问题 I have two win socket apps, server and client. The server app is at my virtual and client at host machine and the communication is OK. I am sending a ISO file (700MB) through that socket and I came across the error that received bytes are corrupt. When my file come to virtual machine, it has the original size, but the content is not OK. At the client side, I am using this code: public class ProgramClient { public static void StartClient() { // Data buffer for incoming data. byte[] msg; try {

How to convert the data extracted from a file to bytes in python?

允我心安 提交于 2019-12-14 02:28:13
问题 I am a newbie to python scripting. I have to extract data line by line from a text file and then convert each line of data received to bytes or bytearray in my .py file. i am able to extract the data from the file line by line, but not able to convert that to bytes. The text in the file is as follows: 04/nov/14 09:15:30 4.6 2.3 05/nov/14 09:30:45 3.2 06/nov/14 10:00:00 1.2 3.4 5.6 I am not very sure how to use bitArray or bytes/bytearray to the data for conversion. I am sorry I have no code

How to retrieve String from DatagramPacket [duplicate]

安稳与你 提交于 2019-12-14 02:12:57
问题 This question already has answers here : DatagramPacket to string (6 answers) Closed 2 years ago . The following code prints [B@40545a60,[B@40545a60abc exp But I want to print abc , so that I can retrieve the correct message from the receiving system. public class Operation { InetAddress ip; DatagramSocket dsock; DatagramPacket pack1; byte[] bin,bout; WifyOperation(InetAddress Systemip) { ip=Systemip; try { dsock=new DatagramSocket(); } catch (SocketException e) { // TODO Auto-generated catch

Generating a Random JPG Image From Console Application

家住魔仙堡 提交于 2019-12-14 00:33:36
问题 I have an API that takes the base64string of an image of size 80x20(either JPG, PNG or GIF) and stores in database. In order to test this API I have to generate a random base64string which can be converted into a real image when decoded. I have find the example here which seems to work with WPF application. How to use the same for a console application? 回答1: A variety of methods should work. How about the following: public static string GenerateBase64ImageString() { // 1. Create a bitmap

Performance loss in VB.net equivalent of light weight conversion from hex to byte

梦想与她 提交于 2019-12-13 21:41:52
问题 I have read through the answers here https://stackoverflow.com/a/14332574/44080 I've also tried to produce equivalent VB.net code: Option Strict ON Public Function ParseHex(hexString As String) As Byte() If (hexString.Length And 1) <> 0 Then Throw New ArgumentException("Input must have even number of characters") End If Dim length As Integer = hexString.Length \ 2 Dim ret(length - 1) As Byte Dim i As Integer = 0 Dim j As Integer = 0 Do While i < length Dim high As Integer = ParseNybble

Comparing Bytes to Hex?

本小妞迷上赌 提交于 2019-12-13 20:53:23
问题 I need to compare the first 5 bytes of a UDP packet to two definitions, and act on them accordingly if it matches one. However, how should I represent the Hex for this since this obviously won't/isn't working? The commented lines are the original way I was doing it, but not very efficient. private static void HandleQuery(Socket socket, EndPoint Remote) { byte[] A2S_INFO_REQUEST = StringToByteArray("\xFF\xFF\xFF\xFF\x54"); byte[] A2S_PLAYER = StringToByteArray("\xFF\xFF\xFF\xFF\x55"); byte[]