java argb是什么图像_从一堆png图片中找出ARGB类型的图片

package com.example.grayalphatranstest;

import java.io.FileInputStream;

import java.io.FileNotFoundException;

import java.io.FileOutputStream;

import java.io.IOException;

import android.os.Bundle;

import android.os.Environment;

import android.app.Activity;

import android.content.Context;

import android.graphics.Bitmap;

import android.graphics.BitmapFactory;

import android.graphics.Canvas;

import android.util.Log;

import android.view.Menu;

import android.view.View;

import java.io.File;

import java.util.ArrayList;

import java.util.Iterator;public classMainActivity extends Activity {private static final String TAG = "GrayAlphaTest";private ArrayList nameList = newArrayList();int nameNum = 0;//private static String dirName = "D:";

private String pngFilePath = Environment.getExternalStorageDirectory().getAbsolutePath()+"/srx2/";

@Overrideprotected voidonCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

setContentView(R.layout.activity_main);//setContentView(new SampleView(this));//readFileByDirect();

Log.v(TAG,"oncreate==");

getPngFileList(pngFilePath);//getNameList();

readFileByDirect();

}private voidgetPngFileList(String FileName) {

File parentF= newFile(FileName);

String fileTest=parentF.getAbsoluteFile().getPath();if (!parentF.exists()) {

Log.v(TAG,"file not exits");return;

}if (parentF.isFile()) {//>10K file//if (parentF.isFile() && (parentF.length()>10240)) {//>10K file

Log.v(TAG,"fileTestPath=="+fileTest);//nameList.add(parentF.getAbsoluteFile());//

//if(parentF.length()>10240) {

nameList.add(fileTest);//}

return;

}

String[] subFiles=parentF.list();for (int i = 0; i < subFiles.length; i++) {

getPngFileList(fileTest+ "/" +subFiles[i]);

}

}publicArrayList getNameList() {//ArrayList mList = getNameList();

Iterator it1 =nameList.iterator();while(it1.hasNext()) {

Log.v(TAG,"element="+it1.next());

}returnnameList;

}private voidreadFileByDirect() {//ArrayList mList = getNameList();

Iterator it1 =nameList.iterator();

String allFilePath= "";while(it1.hasNext()) {

allFilePath=it1.next().toString();if (allFilePath != null) {

findARGBFile(allFilePath);

}

}

}private voidfindARGBFile(String filePath) {byte[] b = new byte[1];byte[] b1 = new byte[30];

String fileoutPath=Environment.getExternalStorageDirectory()

.getAbsolutePath()+ "/srxout/";try{

FileInputStream fin= newFileInputStream(filePath);//int len = fin.read(b,0,4);

int inputNum =fin.available();byte[] outBuffer = new byte[inputNum];for (int i = 0; i < 26; i++) {

fin.read(b);

}//fin.skip(20);//fin.read(b);//if (b.equals("-119 80 78 71")) {//Log.v(TAG, "This is png...");//fin.read(b1, 25, 1);//int mm = (int)b1[26];

int bb = (int) b[0];if (bb == 6) {

fin.close();

Log.v(TAG,"this is ARGB png");

FileInputStream finargb= newFileInputStream(filePath);

finargb.read(outBuffer);//finargb.//int len = fin.read(b,0,4);//int inputNumargb = finargb.available();

String houzhui =seperateName(filePath);/*if (houzhui.endsWith(".9.png")) {// 9png返回

finargb.close();

return;

}*/String fileoutPath1= fileoutPath +seperateName(filePath);if(judgeFileNameExit(fileoutPath1)) {//seperateName(filePath);

fileoutPath1 = fileoutPath +changeSameName(filePath);

}//if(fileoutPath.)//fileoutPath += "/" + nameNum + ".png";

Log.v(TAG, "fileoutpath==" +fileoutPath1);

FileOutputStream fout= newFileOutputStream(fileoutPath1);//if()//for (int i = 1; i <= inputNum; i++) {

fout.write(outBuffer, 0, inputNum);

fout.close();

finargb.close();

}else{

fin.close();

}

}catch(FileNotFoundException e) {//TODO Auto-generated catch block

e.printStackTrace();

}catch(IOException e) {//TODO Auto-generated catch block

e.printStackTrace();

}

}privateString seperateName(String filePath) {//String filePath = "c:\\image\\product\\001.png";

String[] aa = filePath.split("/");

String name= aa[aa.length - 1];

Log.v(TAG,"realname ="+name);returnname;

}privateString changeSameName(String filePath){

String name=seperateName(filePath);

String[] aa= name.split(".png");

String nameout= aa[0]+"_" + nameNum + ".png";returnnameout;

}privateboolean judgeFileNameExit(String path){

File file= newFile(path);if(file.exists()){

nameNum++;return true;

}return false;

}

@Overridepublicboolean onCreateOptionsMenu(Menu menu) {//Inflate the menu; this adds items to the action bar if it is present.

getMenuInflater().inflate(R.menu.main, menu);return true;

}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值