bitmap转byteandroid
❶ 如何将从图库中查到的图片转换成 二进制 android 代码
1、获得图库返回的URL
2、根据URL获得图片的本地绝对地址,构建Bitmap
3、将Bitmap转换成byte[]数组
public void onActivityResult(int requestCode, int resultCode, Intent data) {
Uri uri = data.getData();
String path=uri.getPath();
Bitmap bitmap = BitmapFactory.decodeFile(path,);
byte[] datas=bitmap2Bytes(bitmap );
}
public byte[] bitmap2Bytes(Bitmap bm) {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
bm.compress(Bitmap.CompressFormat.PNG, 100, baos);
return baos.toByteArray();
}
❷ android bitmap对象怎样转化成uri
//Bitmap转byte数组publicbyte[]Bitmap2Bytes(Bitmapbm){ByteArrayOutputStreambaos=newByteArrayOutputStream();bm.compress(Bitmap.CompressFormat.PNG,100,baos);//png类型returnbaos.toByteArray();}//写到sdcard中publicvoidwrite(byte[]bs)throwsIOException{FileOutputStreamout=newFileOutputStream(newFile("/sdcard/test.png"));out.write(bs);out.flush();out.close();}先将Bitmap转byte数组,然后再将byte数组写到sdcard中。
❸ Android Bitmap 与 Drawable之间的区别和转换
Android bitmap和drawable的区别和转换如下:
1.bitmap 转换 drawable
java">Bitmapbitmap=newBitmap(...);Drawabledrawable=newBitmapDrawable(bitmap);
//Drawabledrawable=newFastBitmapDrawable(bitmap);
2.Drawable to Bitmap
BitmapDrawable, FastBitmapDrawable直接用getBitmap
b. 其他类型的Drawable用Canvas画到一个bitmap上
Canvascanvas=newCanvas(bitmap)
drawable.draw(canvas);
Drawabled=ImagesList.get(0);Bitmapbitmap=((BitmapDrawable)d).getBitmap();
区别如下:
1.Bitmap - 称作位图,一般位图的文件格式后缀为bmp,当然编码器也有很多如RGB565、RGB888。作为一种逐像素的显示对象执行效率高,但是缺点也很明显存储效率低。
2.Drawable - 作为Android平下通用的图形对象,它可以装载常用格式的图像,比如GIF、PNG、JPG,当然也支持BMP,当然还提供一些高级的可视化对象,比如渐变、图形等。
另外还有如下相类似的格式:
Canvas - 名为画布,可以看作是一种处理过程,使用各种方法来管理Bitmap、GL或者Path路径,同时它可以配合Matrix矩阵类给图像做旋转、缩放等操作,同时Canvas类还提供了裁剪、选取等操作。
Paint - 可以把它看做一个画图工具,比如画笔、画刷。管理了每个画图工具的字体、颜色、样式。
❹ 能不能将像素数组转化成android里的Bitmap呢
如果有颜色数组int c[]=....
android中用创建
Bitmap m=Bitmap.createBitmap(c, 640,480, Config.ARGB_8888);
这样最闷隐粗直接,按理蚂镇也最快携历。必须用ARGB_8888才能使用透明alpha数据。
也可以 setPixels方法也一样。
❺ 如何将BitmapImage转换为byte[]
这样可以: [mw_shl_code=csharp,true] Uri uri = new Uri("ms-appx:///Assets/logo.png"); RandomAccessStreamReference streamRef = RandomAccessStreamReference.CreateFromUri(uri); // Create a buffer for reading the stream Windows.Storage.Streams.Buffer buffer = null; // Read the entire file into buffer using ( fileStream = await streamRef.OpenReadAsync()) { buffer = new Windows.Storage.Streams.Buffer((uint)fileStream.Size); await fileStream.ReadAsync(buffer, (uint)fileStream.Size, InputStreamOptions.None); } // Read buffer into byte array DataReader reader = DataReader.FromBuffer(buffer); byte[] imageBytes = new byte[buffer.Length]; reader.ReadBytes(imageBytes);[/迅悉mw_shl_code]楼主试试,成蠢昌激不成带袜给个信 到DEVDIV.COM网站查看回答详情>>
❻ Android Bitmap转为Byte[]的问题
C输出的是地址,每次运行从新构建对象,地址改变,但是指向的值不变
❼ android bitmap怎么转byte数组
ByteArrayOutputStreamstream=newByteArrayOutputStream();
bmp.compress(Bitmap.CompressFormat.PNG,100,stream);
byte[]byteArray=stream.toByteArray();
❽ 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);
}
}
}
请参考
❾ android byte[]转化成bitmap 发生了错误,要如何解决呢大神快来呀 高悬赏
建议使用BitmapFactory的其他decode方法,如果是网络读过来的流,最好在本地存成文件缓存,然后通过decodeFileDescriptor方法就没这种问题了。
你可以看一下这里 http://www.thinksaas.cn/group/topic/203384/,也碰到了类似的问题
❿ 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就这样接受了