byte

convert to and from uncompressed bitmap to byte array

故事扮演 提交于 2019-12-13 07:27:05
问题 I am trying to implement two methods. One that takes an ImageView as input and outputs uncompressed byte array. The second takes byte array input and converts to a bitmap. These are the two methods I use however bytesToImage() fails to produce a valid bitmap representation of the output of imageToBytes: private static byte[] imageToBytes(ImageView iv) { byte[] imageInByte = null; Bitmap originalImage; BitmapDrawable drawable = (BitmapDrawable) iv.getDrawable(); originalImage = drawable

IllegalArgumentException ChaCha20 requires 128 bit or 256 bit key

走远了吗. 提交于 2019-12-13 05:54:44
问题 How could I convert String to 128 or 256 bit key for chacha20 Encryption . ChaCha20Encryptor chaCha20Encryptor = new ChaCha20Encryptor(); byte[] data = chaCha20Encryptor.encrypt(plaintext.getBytes(),key2.getBytes()); String enStr = BaseUtilityHelper.encodeBase64URLSafeString(data); encryptedTv.setText(enStr); ChaCha20Encryptor public class ChaCha20Encryptor implements Encryptor { private final byte randomIvBytes[] = {0, 1, 2, 3, 4, 5, 6, 7}; static { Security.addProvider(new

how write method in FileOutputStream truncates the int type argument

早过忘川 提交于 2019-12-13 05:49:33
问题 write() method in FileOutputStream takes an int but truncates the first 3 bytes and writes the byte to stream. If a file contains characters whose ASCII value is more than 127 and bytes are read from it and then written to output stream(another text file) how will it display it because in Java bytes can have a max value of +127. If a text file(input.text) has character '›' whose ASCII value is 155. An input stream,input, reads from it : int in= new FileInputStream("input.txt").read();//in =

How to encrypt / decrypt only first few bytes of a file (the rest should be unencrypted)?

瘦欲@ 提交于 2019-12-13 05:42:39
问题 So, I have implemented in C# Encryption / Decryption algorithm which works perfectly fine when Encrypting / Decrypting any file. And my question now is, how can I Encrypt (then Decrypt) only first few (mega)bytes of a file. For example: I have a 2GB file and I want to encrypt only 3MB of this file. I have tried some things, but nothing worked as I wanted to. I have tried to count readed bytes and if readed bytes are over the limit (3MB) then stop encrypting and just continue to write normal

How to change the allowed amout of allocated memory?

我的梦境 提交于 2019-12-13 05:20:04
问题 Fatal error: Allowed memory size of 33554432 bytes exhausted (tried to allocate 40000 bytes) in /mounted-storage/home20a/sub001/sc20063-GJYD/[...] on line 62 It looks like the PHP-script only allowes me to allocate 32 MB to the memory? This was with an example image to test what would happen if a user tries to upload a huge picture. My question is: How can i predict that this will happen, and then alert the user that the image was too big instead of returning this error? Its a while since I

Java byteArray[] to docx

China☆狼群 提交于 2019-12-13 05:16:45
问题 doc file in byte[] type. Is it possible to convert it from byte[] into .docx file. tried just change file extension programilly but it does not work. any suggestions? I generate report using BiRT eclipse code of saving doc: options = new RenderOptionBase(); ByteArrayOutputStream bos = new ByteArrayOutputStream(); options.setOutputStream(bos); options.setOutputFormat("doc"); if(parameters != null){ task.setParameterValues(parameters); } task.setRenderOption(options); task.run(); return bos

Write Hex in C (byte)

£可爱£侵袭症+ 提交于 2019-12-13 05:14:17
问题 I have to write a byte in hex to a file but I have a problem. For example. If I have: unsigned char a = 0x0; and I write to a file using fwrite: FILE *fp = fopen("file.txt",wb); fwrite(&a,sizeof(unsigned char),1,fp); fclose(fp); When I open file I always see 20h, why not 00h? So, I try to use: fprintf(fp,"%x",a); In this case I see 0h, but I need a full byte, not a nibble. What should I do? 回答1: The first example is hard to believe, it ought to generate a file with a single byte with the

Encrypt byte array using vigenere cipher in java

风格不统一 提交于 2019-12-13 04:50:42
问题 I have to encrypt some file (jpg) using vigenere cipher. I wrote some code, but after encryption and decryption my file is corrupted. The first 1/4 of image displays okay, but the rest of it is corrupted. Here is my code: @Override public byte[] encryptFile(byte[] file, String key) { char[] keyChars = key.toCharArray(); byte[] bytes = file; for (int i = 0; i < file.length; i++) { int keyNR = keyChars[i % keyChars.length] - 32; int c = bytes[i] & 255; if ((c >= 32) && (c <= 127)) { int x = c -

network byte order to host byte order in java

独自空忆成欢 提交于 2019-12-13 03:53:27
问题 I'm stuck with interpreting a response from a C server to my java application. Hoping that the C server is responding to my java in BIG_ENDIAN format, my question is how would I convert the response to an Integer . I'm pasting the response I got from the the C server and wondering how would I do "be64toh" function in java. Response from the C server - ^@^@^@^@^@^@^@^@^@^@^@^@^@^@^H^@^@^@^@^@^A^A^B^@^@^@^N^@^@^@^@^@^@^@^@^@^@^@^H^@^@^@^@^@^@^@^A^@^@^@^K^@^@^@^@^@^@^@^@^@^@^@<80>^@^@^@^@^@^@^BÃ

Make a bytes packet and send to External accessory Device for print using Bluetooth in iOS

爷,独闯天下 提交于 2019-12-13 03:37:18
问题 I am working to print image using External Accessory in iOS but I have problem to send request to Printer. Here, I attached image in which Packet need to send Printer. but i don't know how to make this packet and send packet to printer. 回答1: Here, I attached the sample code to make the packet and send to External Accessory Device (printer) using Objective C language. - (void)PrintImage:(UIImage *)image { NSMutableData* imagedata = [UIImageJPEGRepresentation(image, 0.0) mutableCopy];