Android从SD卡读取图片并显示为点阵图Word文件下载.docx
- 文档编号:21734870
- 上传时间:2023-02-01
- 格式:DOCX
- 页数:17
- 大小:19.89KB
Android从SD卡读取图片并显示为点阵图Word文件下载.docx
《Android从SD卡读取图片并显示为点阵图Word文件下载.docx》由会员分享,可在线阅读,更多相关《Android从SD卡读取图片并显示为点阵图Word文件下载.docx(17页珍藏版)》请在冰豆网上搜索。
publicvoidonClick(Viewv)
{
Intentintent=newIntent();
intent.setClass(Activity01Activity.this,FileToBitMapActivity.class);
startActivity(intent);
Activity01Activity.this.finish();
}
});
}
publicvoidonStart()
super.onStart();
publicvoidonResume()
super.onResume();
publicvoidonPause()
super.onPause();
publicvoidonStop()
super.onStop();
publicvoidonDestroy()
super.onDestroy();
publicvoidonRestart()
super.onRestart();
FileToBitMapActivity.java:
importjava.io.BufferedReader;
importjava.io.File;
importjava.io.FileInputStream;
importjava.io.FileNotFoundException;
importjava.io.FileOutputStream;
importjava.io.IOException;
importjava.io.InputStreamReader;
importandroid.graphics.Bitmap;
importandroid.graphics.BitmapFactory;
importandroid.graphics.Canvas;
importandroid.os.Environment;
importandroid.widget.ImageView;
importandroid.widget.TextView;
importandroid.widget.Toast;
importandroid.graphics.Matrix;
publicclassFileToBitMapActivityextendsActivity
StringSDcardPath;
StringFolderPath;
StringfilePath;
intstate=0;
//0没参数,1取得imagepath,2取得资源文件path
intwidth=16;
intheight;
intinitWidth;
intinitHeight;
Bitmapbmp;
int[]Bitmap1;
//缩放后16行的像素矩阵
intsize=20;
//1格点阵的边长
int[]Bitmap2;
//缩略图
Stringres=null;
ImageViewmImageView;
publicStringgetSDPath(){
FilesdDir=null;
booleansdCardExist=Environment.getExternalStorageState()
.equals(android.os.Environment.MEDIA_MOUNTED);
//判断sd卡是否存在
if
(sdCardExist)
{
sdDir=Environment.getExternalStorageDirectory();
//获取根目录
}
returnsdDir.toString();
super.onCreate(savedInstanceState);
setContentView(R.layout.filetobitmap);
SDcardPath=getSDPath();
FolderPath=SDcardPath+"
/MagicSwing"
;
Bundlebundle=newBundle();
bundle=this.getIntent().getExtras();
if(bundle!
=null){
filePath=bundle.getString("
filePath"
);
state=bundle.getInt("
state"
if(state==1){
Bitmap
image=BitmapFactory.decodeFile(filePath);
initWidth=image.getWidth();
initHeight=image.getHeight();
floatscale=((float)width)/initWidth;
height=(int)(initHeight*scale);
//将image缩放后存在bmp中
Matrixmatrix=newMatrix();
//缩放矩阵
matrix.postScale(scale,scale);
//缩放
bmp=Bitmap.createBitmap(image,0,0,initWidth,initHeight,matrix,true);
//得到缩放后的像素矩阵
Bitmap1=newint[width*height];
bmp.getPixels(Bitmap1,0,width,0,0,width,height);
elseif(state==2)
Filefile=newFile(FolderPath+"
/res.txt"
if(file.exists())
try{
FileInputStreamfi=newFileInputStream(FolderPath+"
BufferedReaderbr=newBufferedReader(newInputStreamReader(fi));
StringreadString=newString();
while((readString=br.readLine())!
=null){
//数据多的话须要在这里处理readString
res+=readString;
}catch(Exceptione)
{
}
if(res!
res=res.substring(5);
intlen=0;
intcur=0;
intnum=1;
for(inti=0;
i<
res.length();
i++)
if(res.charAt(i)=='
'
)
num++;
Bitmap1=newint[num];
Stringtmp=newString();
i++){
while(i<
res.length()&
&
res.charAt(i)!
='
i++;
len++;
tmp=res.substring(i-len,i);
Bitmap1[cur++]=Integer.parseInt(tmp);
len=0;
height=cur/width;
Bitmap2=newint[width*height*size*size];
res=newString();
width;
for(intj=0;
j<
height;
j++)
intRGB=Bitmap1[i+j*width];
for(intii=i*size;
ii<
(i+1)*size;
ii++)
for(intjj=j*size;
jj<
(j+1)*size;
jj++)
Bitmap2[ii+jj*width*size]=RGB;
res="
"
intRGB=Bitmap1[j+i*width];
res+="
"
+RGB;
//这一句出错
//bmp=Bitmap.createBitmap(Bitmap2,width*size,height*size,bmp.getConfig());
mImageView=(ImageView)findViewById(R.id.imageView1);
mImageView.setImageBitmap(bmp);
//Canvascanvas=newCanvas();
//canvas.drawBitmap(Bitmap2,0,width*size,0,0,width*size,height*size,false,null);
Buttonbutton5=(Button)findViewById(R.id.imageImport);
button5.setOnClickListener(newButton.OnClickListener(){
intent.setClass(FileToBitMapActivity.this,SDCardFileExplorerActivity.class);
Bundlebundle=newBundle();
bundle.putBoolean("
imageORresfile"
true);
intent.putExtras(bundle);
FileToBitMapActivity.this.finish();
Buttonbutton6=(Button)findViewById(R.id.resFileImport);
button6.setOnClickListener(newButton.OnClickListener(){
false);
Buttonbutton7=(Button)findViewById(R.id.save);
button7.setOnClickListener(newButton.OnClickListener(){
FileOutputStreamstream=null;
try{
Filefile=newFile(FolderPath,"
res.txt"
if(!
file.exists())
file.createNewFile();
stream=newFileOutputStream(file);
}catch(FileNotFoundExceptione){
}catch(IOExceptione){
//TODOAuto-generatedcatchblock
e.printStackTrace();
stream.write(res.getBytes());
}catch(IOExceptione){
stream.close();
Buttonbutton8=(Button)findViewById(R.id.done);
button8.setOnClickListener(newButton.OnClickListener(){
SDCardFileExplorerActivity.java:
importjava.text.SimpleDateFormat;
importjava.util.ArrayList;
importjava.util.Date;
importjava.util.HashMap;
importjava.util.List;
importjava.util.Map;
importandroid.widget.AdapterView;
importandroid.widget.AdapterView.OnItemClickListener;
importandroid.widget.ListView;
importandroid.widget.SimpleAdapter;
publicclassSDCardFileExplorerActivityextendsActivity{
privateTextViewtvpath;
privateListViewlvFiles;
privateButtonbtnParent;
BooleanimageORresfile;
//记录当前的父文件夹
FilecurrentParent;
//记录当前路径下的所有文件夹的文件数组
File[]currentFiles;
StringSDCardPath;
StringfolderPath;
publicStringgetSDPath(){
FilesdDir
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- Android SD 读取 图片 显示 点阵图
![提示](https://static.bdocx.com/images/bang_tan.gif)