ami*_*ita 4 java android drawable android-camera android-imageview
我正在实现如果ImageView有位图然后它应该将图像从imageview保存到内部存储器,否则在应用程序的内部存储器中设置另一个位图.这是代码:_
croppedImage = cropImageView.getCroppedImage();
croppedImageView = (ImageView) findViewById(R.id.croppedImageView);
croppedImageView.setImageBitmap(croppedImage);@Override
public void onClick(View v) {
// TODO Auto-generated method stub
switch (v.getId()) {
case R.id.btn_save:
counter++;
if(croppedImageView.getDrawable() != null)
{
System.out.println("nullllllllllllll");
try {
Bitmap photo = ((BitmapDrawable)croppedImageView.getDrawable()).getBitmap();
FileOutputStream mFileOutStream1 = openFileOutput("IMG" + counter + ".png", Context.MODE_PRIVATE);
photo.compress(CompressFormat.JPEG, 100, mFileOutStream1);}
catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();}
}else{
System.out.println("notttttnullllllllllllll");
try {
FileOutputStream mFileOutStream1 = openFileOutput("IMG" + counter + ".png", Context.MODE_PRIVATE);
bitmap.compress(Bitmap.CompressFormat.JPEG, 100, mFileOutStream1);
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
Editor editor = def.edit();
editor.putInt("value", counter);
editor.commit();
break;
default:
break;
}
}
Run Code Online (Sandbox Code Playgroud)
Amu*_*are 12
您可以按如下方式检查:
boolean hasDrawable = (croppedImageView.getDrawable() != null);
if(hasDrawable) {
// imageView has image in it
}
else {
// no image assigned to image view
}
Run Code Online (Sandbox Code Playgroud)
只需检查Bitmap值,如下所示:
if(bitmap == null) {
// set the toast for select image
} else {
uploadImageToServer();
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
16405 次 |
| 最近记录: |