我想用我的应用程序拍照并将其发送到 Instagram,但我遇到了一些问题,因为当我拍摄照片时,我的应用程序有一些延迟保存。
我的应用程序正在这样做
首先,我用我的应用程序拍照并将这张照片保存在图库中。
在用户批准或不批准图像之后。如果他同意,他会单击一个按钮并将其发送到 Instagram,但我不知道为什么该应用程序需要几秒钟来保存我的图像。
我获取要使用的图像的方法是获取保存在文件夹图库中的最后一张图片。
这是我调用拍照的代码。
camera = cameraSurfaceView.getCamera();
camera.takePicture(new ShutterCallback() {
@Override
public void onShutter() {
AudioManager mgr = (AudioManager) getSystemService(Context.AUDIO_SERVICE);
mgr.playSoundEffect(AudioManager.FLAG_PLAY_SOUND);
}
}, null, new HandlePictureStorage(preview,cameraSurfaceView.getFront()));
imageSelected = false;
sendBroadcast(new Intent(Intent.ACTION_MEDIA_MOUNTED, Uri.parse("file://"+ Environment.getExternalStorageDirectory())));
这是我用来获取图片并保存的类
public class HandlePictureStorage implements PictureCallback {
FrameLayout preview;
int wid = 0;
Bitmap bitmapFinal;
boolean front;
File storagePath = new File(Environment.getExternalStorageDirectory() + "/Tubagram/");
public HandlePictureStorage(FrameLayout preview, boolean front){
this.preview = preview;
this.front = front;
}
@Override
public void onPictureTaken(byte[] picture, Camera camera) {
Matrix matrix = new Matrix();
if (front){
matrix.postRotate(270);
}else{
matrix.postRotate(90);
}
Bitmap cameraBitmap = BitmapFactory.decodeByteArray(picture, 0, picture.length);
wid = cameraBitmap.getWidth();
Bitmap scaledBitmap = Bitmap.createScaledBitmap(cameraBitmap, wid, wid, true);
Bitmap imagemRotacionada = Bitmap.createBitmap(scaledBitmap,0,0,scaledBitmap.getWidth(),scaledBitmap.getHeight(),matrix,true);
Bitmap newImage = Bitmap.createBitmap
(612, 612, Bitmap.Config.ARGB_8888);
Canvas canvas = new Canvas(newImage);
canvas.drawBitmap(imagemRotacionada, 0f, 0f, null);
Drawable drawable = preview.getForeground();
drawable.setBounds(0, 0, 612, 612);
drawable.draw(canvas);
File myImage = new File(storagePath,"TUBAGRAM_" + System.currentTimeMillis() +".png");
try
{
FileOutputStream out = new FileOutputStream(myImage);
newImage.compress(Bitmap.CompressFormat.PNG, 100, out);
bitmapFinal = newImage;
out.flush();
out.close();
Log.i("Imagem Tubagram salva em ", ""+ myImage);
}
catch(FileNotFoundException e)
{
Log.d("In Saving File", e + "");
}
catch(IOException e)
{
Log.d("In Saving File", e + "");
}
drawable = null;
// newImage.recycle();
newImage = null;
cameraBitmap.recycle();
cameraBitmap = null;
}
这是我接受照片并发送到 Instagram 时的代码
if (verificaInstagram()){
Intent shareIntent = new Intent(android.content.Intent.ACTION_SEND);
shareIntent.setType("image/*");
Cursor c1 = pickLastPhotoAlbum();
shareIntent.putExtra(Intent.EXTRA_STREAM, Uri.parse("file://"+Environment.getExternalStorageDirectory()+ "/Tubagram/" + c1.getString(1)+".png"));
shareIntent.setPackage("com.instagram.android");
c1.close();
startActivity(shareIntent);
}else{
Toast.makeText(v.getContext(), "Você não possui o Instagram no seu smartphone!", Toast.LENGTH_SHORT).show();
}
任何人都可以帮助我吗?