Flash CS6 (AS3):
This is what I am trying to accomplish...
Convert bitmapdata -> bytearray -> encode using JPEGencoder (PNGencoder, or any other alternatives) -> base64 string.
Once i get hold of this base64 string, I will be able to use my string obfuscation algorithm, and send that string to php.
Now the reverse (decryption) to get back my original image.
Load the obfuscated string from php into flash -> deobfuscation algorithm -> decodebase64toBytearray -> bitmapdata
The challenge for me rite now is in converting base64 to bytearray, and then to bitmapdata.
Can someone guide me on how to get back the bitmap image from base64 string?
var pBytes:ByteArray = Base64.decodeToByteArray(pString);
var pBitmapData:BitmapData = PNGEncoder2.decode(pBytes);
Related
val sanitizedHTML = Jsoup.clean(html, whitelist)
val textRenderer = ITextRenderer()
val outputStream = ByteArrayOutputStream()
textRenderer.setDocumentFromString(sanitizedHTML)
textRenderer.layout()
textRenderer.createPDF(outputStream)
textRenderer.finishPDF()
return Base64.getDecoder().decode(outputStream.toByteArray())
I would like to generate pdf from html content and rather than saving as file, would like to upload to server which expects it to be ByteArray.
I tried to do above using jsoup to clean html and textRenderer for generating pdf but keep receiving error about invalid Base64 character 25. Could someone help what I am doing wrong here.
return Base64.getDecoder().decode(outputStream.toByteArray())
This was incorrect, if I remove Base64 decoding it is working well.
I am trying to decode base64 string type image to bitmap but my android studio is not recognizing "decode" method in
val imageBytes = Base64.decode(string, 0)
val image = BitmapFactory.decodeByteArray(imageBytes, 0, imageBytes.size)
This could caused by importing the wrong class. It might be that Android Studio is interpreting that as java.util.Base64 which has no decode method. Instead, you want to use the Base64 class declared in android.util. Try using a fully qualified reference to make sure the IDE selects the right one
val encodedImage: String
val imageBytes = android.util.Base64.decode(encodedImage, 0)
I am currently making an app for students where they can upload a PDF file to a server. I am using the android Volley API but have been testing the function using JPEG files.
This is my code
public String getStringImage(Bitmap bmp) {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
bmp.compress(Bitmap.CompressFormat.JPEG, 100, baos);
byte[] imageBytes = baos.toByteArray();
String encodedImage = Base64.encodeToString(imageBytes, Base64.DEFAULT);
return encodedImage;
}
How would I change this code so that a PDF can be uploaded instead?
Do I still used Base64? and imageBytes?
Or is there an alternate method?
You should be able to reuse most of the code that you have there, instead of taking in a Bitmap, you would take in a File. You won't be able to use Bitmap.Compress on it though so that will need to be removed.
For uploading a PDF, you can Base64 encode it and send it as a string as part of the request, this might get out of control if you are handling large files.
The other option is to use a multipart form, I would suggest taking a look at this stackoverflow question and answer for how to do that.
I am facing a problem with Gzip uncompressing.
The situation is like this. I have some text in UTF-8 format. Now this text is compressed using gzdeflate() function in PHP and then stored in a blob object in Mysql.
Now I tried to retrieve the blob object and then used Java's Gzip Stream to un compress it. But it throws an error saying that it is not in GZIP format.
I even used Inflater in Java to do the same but now I get "DataFormatException:incorrect header check". The code for the inflater is as below.
//rs is the resultset
//blobAsBytes is the byte array
while(rs.next()){
blob = rs.getBlob("old_text");
int blobLength = (int) blob.length();
blobAsBytes = blob.getBytes(1, blobLength);
}
Inflater decompresser = new Inflater();
decompresser.setInput(blobAsBytes);
byte[] result = new byte[100];
int resultLength = decompresser.inflate(result); // this is the line where the exception is occurring.
decompresser.end();
// Decode the bytes into a String
String outputString = new String(result, 0, resultLength, "UTF-8");
System.out.println(outputString);
I have to do this using Java and get all the text back that is stored in the database.
Can someone please help me with this.
Use gzencode(), not gzdeflate(). The latter does not produce the gzip format, it produces the deflate format. The former does produce the gzip format. The PHP functions are horribly and confusingly named.
Alternatively, use the java.util.zip.Inflater class with nowrap true in the Inflater constructor. That will decode raw deflate data on the Java end.
i have compressed an xml file and converted it into base64 format in web page.then i have passed the base64 string to windows application and converted it to unbase64 format.now i want to decompress this string in windows form only.
i have done the following in windows
dim decoded as byte()
decoded=convert.frombase64string(strreturndata) // strreturndata is base64 string
dim decoders as string
decoders = encoding.utf8.getstring(decoded)
now i want to decompress this string using gzip stream class in windows form
If you want to get back the Base64 string, use this.
Try this:
byte[] x = Convert.FromBase64String(decodedString);
string mytext = System.Encoding.utf8.getstring(x, 0, x.length)
If you need to do more compression, you can use Gzip compression and decompression or DeflateStream class.