導航:首頁 > 操作系統 > android文件轉byte

android文件轉byte

發布時間:2023-06-15 06:28:42

1. android中怎麼將音頻文件轉成Byte

為何要轉呢?這個哥們也是不懂,你可以去看一下教程。http://www.eoeandroid.com/thread-565331-1-1.html

2. android如何把byte數據存到內存中並轉為bitmap,求高手~~~~~~~~~~~~~~~~~~~~~~~~~~~

import java.io.File;

import android.app.Activity;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.ImageView;

public class MainAct extends Activity {
private ImageView img;
//圖片路徑
private String filepath = "/sdcard/sample.jpg";

@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
img = (ImageView) findViewById(R.id.img);
File file = new File(filepath);
if (file.exists()) {
Bitmap bm = BitmapFactory.decodeFile(filepath);
//將圖片顯示到ImageView中
img.setImageBitmap(bm);
}
}
}

請參考

3. android 字元串轉byte數組

Android 字元串、byte數組與16進制數組間的轉換

<spanstyle="font-family:SimSun;font-size:14px;">//字元串轉換成16進制文字列的方法
publicStringtoHex(Stringstr){
StringhexString="0123456789ABCDEF";
byte[]bytes=str.getBytes();
StringBuilderhex=newStringBuilder(bytes.length*2);
for(inti=0;i<bytes.length;i++){
hex.append(hexString.charAt((bytes[i]&0xf0)>>4));//作用同n/16
hex.append(hexString.charAt((bytes[i]&0x0f)>>0));//作用同n
hex.append('');//中間用空格隔開
}
returnhex.toString();
}

//將16進制數組轉換為字元串
publicstaticStringdecode(Stringbytes){
StringhexString="0123456789ABCDEF";
ByteArrayOutputStreambaos=newByteArrayOutputStream(bytes.length()/2);
//將每2位16進制整數組裝成一個位元組
//for(inti=0;i<bytes.length();i+=2)
//baos.write((hexString.indexOf(bytes.charAt(i))<<4|hexString.indexOf(bytes.charAt(i+1))));
//將每3位(第3位為空格)中的前2位16進制整數組裝成一個位元組
for(inti=0;i<bytes.length();i+=3){
baos.write((hexString.indexOf(bytes.charAt(i))<<4|hexString.indexOf(bytes.charAt(i+1))));
}
returnnewString(baos.toByteArray());
}</span>

詳細

4. WebService返回byte[],在Android怎麼才能接收byte[]啊,跪求大神

1、使用ISO 8859-1編碼將位元組數組轉為字元串;

android接收到之後使用byte[] receive = String.getBytes("ISO 8859-1");


2、還可以將位元組數組拼成字元串,用,符號隔開每個值。

Arrays.toString(byte[] b);可以將位元組數組轉成這種格式。

?

其實位元組也是數值型。


importjava.io.UnsupportedEncodingException;
importjava.util.Arrays;
importjava.util.Random;
publicclassMainClass{
/**
*@paramargs
*/
publicstaticvoidmain(String[]args){
//TODO自動生成的方法存根
byte[]rand=newbyte[256];
newRandom().nextBytes(rand);
Stringtranslation=null;
try{
translation=newString(rand,"ISO-8859-1");
}catch(UnsupportedEncodingExceptione){
//TODO自動生成的catch塊
e.printStackTrace();
}
System.out.println("要傳輸的內容:"+translation);
System.out.println("模擬傳輸過去...");
byte[]receive=null;
try{
receive=translation.getBytes("ISO-8859-1");
}catch(UnsupportedEncodingExceptione){
//TODO自動生成的catch塊
e.printStackTrace();
}
System.out.println("傳輸前後的內容是否相同:"+Arrays.equals(rand,receive));
}
}

5. android上傳圖片到php android用bitmap.compress壓縮為byte流 php怎麼解壓轉為圖片啊

android 文件上傳,自己封裝了個方法,
<?php
var_mp($_POST);
var_mp($_FILES);
foreach($_FILES as $key => $value){
move_uploaded_file($_FILES[$key]['tmp_name'],
$_SERVER['DOCUMENT_ROOT'].'/FileUpload/files/'.$_FILES[$key]['name']);
}
?>
PHP就這樣接受了

閱讀全文

與android文件轉byte相關的資料

熱點內容
51單片機摘要 瀏覽:402
英語經典pdf下載 瀏覽:314
大學文件夾怎麼刪除 瀏覽:665
linux科研軟體 瀏覽:550
ue4打包編譯著色器 瀏覽:772
雲伺服器可以在手機上登錄嗎 瀏覽:673
網游腳本為什麼要連接伺服器 瀏覽:4
程序員發展路線圖 瀏覽:318
手機語音加密會議 瀏覽:587
冰與火pdf 瀏覽:416
為什麼叫我買阿里雲伺服器 瀏覽:470
加密貨幣征稅一覽表 瀏覽:959
llc編譯器 瀏覽:922
數控可編程電阻器 瀏覽:757
培訓app源碼 瀏覽:433
phpcurl啟用 瀏覽:535
ubuntu圖形編程 瀏覽:441
jar包啟動命令 瀏覽:680
java數組一維轉二維 瀏覽:500
office批量轉pdf 瀏覽:185