本文介绍了创建从uncom $ P $一个PNG pssed原始PNG数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我用这。
请指向正确的算法作为如何产生从原始uncom pressed数据的PNG。 code样品将是巨大的;)
感谢
解决方案
公共静态字符串连接codeTobase64(位图图像)
{
位图immagex =图像;
ByteArrayOutputStream BAOS =新ByteArrayOutputStream();
immagex.com preSS(Bitmap.Com pressFormat.JPEG,100,BAOS);
字节[] B = baos.toByteArray();
字符串imageEn codeD = Base64.en codeToString(B,Base64.DEFAULT);Log.e(看,imageEn codeD);
返回imageEn codeD;
}公共静态位图德codeBase64(字符串输入){
字节[]德codedByte = Base64.de code(输入,0);
返回BitmapFactory.de codeByteArray的(德codedByte,0,德codedByte.length); }
I am using this Android Screenshot Library to capture screenshots. I want to show this screenshot in web browser.
I have written a small socket app on PC which connects to Android phone and encode the captured screenshot to base64.
String base64 = Base64.getEncoder().encodeToString(bytes);
This base64 is being sent to web page over websocket. Below is my html/JS code which should draw the image on canvas. I have stored the base64 image data in a text file for test purpose.
<div style="background: aqua; width: 500px; height: 660px;">
<canvas style="width: 480px; height: 640px;" id="sim">
</canvas>
</div>
<script type="text/javascript">
var ctx;
var width = 480;
var height = 640;
(function start() {
ctx = document.getElementById("sim").getContext("2d");
loadFromFile();
})();
function loadImage(data) {
var image = new Image();
image.onload = function() {
//this part never executes
ctx.drawImage(image, 0, 0);
console.log("images loaded!");
}
image.src = "data:image/png;base64," + data;
}
function loadFromFile() {
//please get data from **https://app.box.com/s/e19ww51fd37h4sy8getjnag31ud6tpp9**
var file = "imagefile.txt";
var rawFile = new XMLHttpRequest();
rawFile.open("GET", file, true);
rawFile.onreadystatechange = function() {
if (rawFile.readyState === 4) {
if (rawFile.status === 200 || rawFile.status == 0) {
var data = rawFile.responseText;
console.log("data loaded: " + data.length);
loadImage(data);
}
}
}
rawFile.send(null);
}
</script>
For convenience, here is the JsFiddle of same code.
Please point to right algorithm as how to generate the PNG from the raw uncompressed data. code sample would be great ;)
Thanks
解决方案
public static String encodeTobase64(Bitmap image)
{
Bitmap immagex=image;
ByteArrayOutputStream baos = new ByteArrayOutputStream();
immagex.compress(Bitmap.CompressFormat.JPEG, 100, baos);
byte[] b = baos.toByteArray();
String imageEncoded = Base64.encodeToString(b,Base64.DEFAULT);
Log.e("LOOK", imageEncoded);
return imageEncoded;
}
public static Bitmap decodeBase64(String input)
{
byte[] decodedByte = Base64.decode(input, 0);
return BitmapFactory.decodeByteArray(decodedByte, 0, decodedByte.length); }
这篇关于创建从uncom $ P $一个PNG pssed原始PNG数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!