如何使用com.android.camera.action.crop裁剪位图
我读了很多使用com.android.camera.action.CROP的例子,但他们都说从galery或camera裁剪图像。。任何人都可以告诉我如何使用com.android.camera.crop裁剪位图?? 我试过很多方法,但还是失败了。。 我试图将位图保存到文件中,并从该文件中创建一个uri变量,并将该uri变量用作com.android.camera.action.CROP上的数据。。。但还是失败了。。。T.T 这是我的密码如何使用com.android.camera.action.crop裁剪位图,android,image,bitmap,crop,android-image,Android,Image,Bitmap,Crop,Android Image,我读了很多使用com.android.camera.action.CROP的例子,但他们都说从galery或camera裁剪图像。。任何人都可以告诉我如何使用com.android.camera.crop裁剪位图?? 我试过很多方法,但还是失败了。。 我试图将位图保存到文件中,并从该文件中创建一个uri变量,并将该uri变量用作com.android.camera.action.CROP上的数据。。。但还是失败了。。。T.T 这是我的密码 public class CobaSaveImageAc
public class CobaSaveImageActivity extends Activity {
public ImageView tampilan;
public static Bitmap bmp;
public Uri mImageCaptureUri;
int i = 1;
File f;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
tampilan = (ImageView)findViewById(R.id.imageView1);
//bmp = BitmapFactory.decodeFile("/mnt/sdcard/bluetooth/enigma.bmp");
bmp = BitmapFactory.decodeFile("/mnt/sdcard/enigma.jpg");
tampilan.setImageBitmap(bmp);
}
public void save (View v){
f = new File(Environment.getExternalStorageDirectory()+"/image/save"+i+".jpg");
if (f.exists()) fileCheker(f);
try {
FileOutputStream fos = new FileOutputStream(f);
BufferedOutputStream bit = new BufferedOutputStream(fos);
bmp.compress(Bitmap.CompressFormat.JPEG, 50, bit);
bit.flush();
bit.close();
//bmp.recycle();
sendBroadcast(new Intent(Intent.ACTION_MEDIA_MOUNTED, Uri.parse
("file://" + Environment.getExternalStorageDirectory())));
Toast.makeText(this, "save complete to "+f.toString(), Toast.LENGTH_LONG).show();
mImageCaptureUri = Uri.fromFile(f);
doCrop();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
public void fileCheker(File in){
i++;
f = new File(Environment.getExternalStorageDirectory()+"/image/save"+i+".jpg");
if (f.exists()) fileCheker(f);
}
public static Bitmap grayscale (Bitmap bmp){
int height, width;
int pixel, A, R, G, B;
width = bmp.getWidth();
height = bmp.getHeight();
Bitmap bmpGray = Bitmap.createBitmap(width, height, Bitmap.Config.RGB_565);
for (int i =0;i<width;++i){
for(int j=0;j<height;++j){
pixel = bmp.getPixel(i,j);
A = Color.alpha(pixel);
R = Color.red(pixel);
G = Color.green(pixel);
B = Color.blue(pixel);
R = G = B = (int)((R+G+B)/3);
bmpGray.setPixel(i, j, Color.argb(A, R, G, B));
}
}
return bmpGray;
}
public void gray(View v){
new backtask().execute();
//bmp = grayscale(bmp); tampilan.setImageBitmap(bmp);
//
}
public class backtask extends AsyncTask<Void, Void, Void>{
//Bitmap temp;
ProgressDialog prog;
@Override
protected void onPreExecute(){
super.onPreExecute();
prog = ProgressDialog.show(CobaSaveImageActivity.this, "", "Progress...",true);
}
@Override
protected Void doInBackground(Void... params) {
// TODO Auto-generated method stub
bmp = grayscale(bmp);
return null;
}
@Override
protected void onPostExecute(Void result){
super.onPostExecute(result);
prog.dismiss();
tampilan.setImageBitmap(bmp);
}
}
private void doCrop() {
Intent intent = new Intent("com.android.camera.action.CROP");
intent.setType("image/*");
intent.setData(mImageCaptureUri);
//intent.putExtra("crop", true);
intent.putExtra("outputX", 200);
intent.putExtra("outputY", 200);
intent.putExtra("aspectX", 1);
intent.putExtra("aspectY", 1);
intent.putExtra("scale", true);
intent.putExtra("return-data", true);
startActivityForResult(intent, 1);
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data){
if (resultCode != RESULT_OK) return;
switch (requestCode){
case 1 :
Bundle extras = data.getExtras();
if (extras != null){
Bitmap crop = extras.getParcelable("data");
tampilan.setImageBitmap(crop);
}
break;
}
}
公共类CobasaviemageActivity扩展活动{
坦皮兰公共景观;
公共静态位图;
公共Uri mImageCaptureUri;
int i=1;
文件f;
/**在首次创建活动时调用*/
@凌驾
创建时的公共void(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
tampilan=(ImageView)findViewById(R.id.imageView1);
//bmp=BitmapFactory.decodeFile(“/mnt/sdcard/bluetooth/enigma.bmp”);
bmp=BitmapFactory.decodeFile(“/mnt/sdcard/enigma.jpg”);
tampilan.setImageBitmap(bmp);
}
公共作废保存(视图v){
f=新文件(Environment.getExternalStorageDirectory()+”/image/save“+i+”.jpg”);
如果(f.exists())fileCheker(f);
试一试{
FileOutputStream fos=新的FileOutputStream(f);
BufferedOutputStream位=新的BufferedOutputStream(fos);
bmp.compress(Bitmap.CompressFormat.JPEG,50位);
bit.flush();
bit.close();
//bmp.recycle();
sendBroadcast(新意图(Intent.ACTION\u MEDIA\u挂载,Uri.parse
(“文件:/”+Environment.getExternalStorageDirectory());
Toast.makeText(这是“将完成保存到”+f.toString(),Toast.LENGTH\u LONG.show();
mImageCaptureUri=Uri.fromFile(f);
doCrop();
}捕获(IOE异常){
//TODO自动生成的捕捉块
e、 printStackTrace();
}
}
公共无效文件检查器(文件输入){
i++;
f=新文件(Environment.getExternalStorageDirectory()+”/image/save“+i+”.jpg”);
如果(f.exists())fileCheker(f);
}
公共静态位图灰度(位图bmp){
int高度、宽度;
int像素,A,R,G,B;
宽度=bmp.getWidth();
height=bmp.getHeight();
位图bmpGray=Bitmap.createBitmap(宽度、高度、Bitmap.Config.RGB_565);
对于(int i=0;i来说,该意图不是公开的Android API的一部分,也不能保证由任何设备制造商实现。在Android 1.x和早期的2.x设备上很常见,但从那时起已经下降了
最好使用Bitmap.createBitmap()
或Bitmap.createScaledBitmap()之类的方法
创建原始图像的大小调整或裁剪版本。这一意图不属于公共Android API的一部分,也不保证由任何设备制造商实施。在Android 1.x和早期的2.x设备上很常见,但后来逐渐消失
最好使用Bitmap.createBitmap()
或Bitmap.createScaledBitmap()之类的方法
创建原始图像的大小调整或裁剪版本。没错,这从未公开过。如果你真的想在应用程序中使用它,最好是在应用程序中复制代码,并根据需要进行修改。只有几个类,可以稍加修改即可使用。没错,这从未公开过。如果你真的想要在你的应用程序中使用它,你最好复制应用程序中的代码,并根据需要进行修改。只有几个类,只需稍加修改即可使用。