簡體   English   中英

無法將imageview圖片保存到圖庫。.(未實現eglSurfaceAttrib)..(android)

[英]Unable to save imageview image to gallery..(eglSurfaceAttrib not implemented)..(android)

我正在嘗試制作一個非常簡單的應用程序,它允許用戶在提供的圖像上書寫並將其保存到他們的畫廊。 我嘗試了下面的代碼。 並且它觸發錯誤並且無法保存圖像。

@Override
public boolean onOptionsItemSelected(MenuItem item) {


switch(item.getItemId()){
    case R.id.savebutton:
             Bitmap bitmap = ((BitmapDrawable)imagecp.getDrawable()).getBitmap();


            saveBitmap(bitmap);

    default:
        return super.onOptionsItemSelected(item);


}

public void saveBitmap(Bitmap bmp) {
    String _time = "";
    Calendar cal = Calendar.getInstance();
    int millisecond = cal.get(Calendar.MILLISECOND);
    int second = cal.get(Calendar.SECOND);
    int minute = cal.get(Calendar.MINUTE);
    int hourofday = cal.get(Calendar.HOUR_OF_DAY);
    _time = "image_" + hourofday + "" + minute + "" + second + ""
            + millisecond + ".png";
    String file_path = Environment.getExternalStorageDirectory()
            .getAbsolutePath();
    try {
        File dir = new File(file_path);
        if (!dir.exists())
            dir.mkdirs();
        File file = new File(dir, _time);
        FileOutputStream fOut = new FileOutputStream(file);
        bmp.compress(Bitmap.CompressFormat.PNG, 90, fOut);
        fOut.flush();
        fOut.close();
        Toast.makeText(getApplicationContext(),
                "Image has been saved in Couponmaker folder",
                Toast.LENGTH_LONG).show();
    } catch (Exception e) {
        Toast.makeText(getApplicationContext(),
                "saving failed",
                Toast.LENGTH_LONG).show();
        Log.e("error in saving image", e.getMessage());
    }
}

和錯誤消息

 E/error in saving image﹕ /storage/0C11-3814/image_162259256.png: open failed: EACCES (Permission denied)
W/EGL_emulation﹕ eglSurfaceAttrib not implemented
W/OpenGLRenderer﹕ Failed to set EGL_SWAP_BEHAVIOR on surface 0xad78df60, error=EGL_SUCCESS
E/Surface﹕ getSlotFromBufferLocked: unknown buffer: 0xab7dd67 W/art﹕ Suspending all threads took: 13.866ms

xml文件

 <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />

<application
    android:allowBackup="true"....

我相信在棉花糖中,外部設備目錄是sd卡目錄。 我試圖在SD卡上寫,但是失敗了。 因為他們不允許這樣做(我在某處閱讀,但是由於忘記了,所以無法在此處添加鏈接)。 Gallery不一定從外部存儲讀取圖像。 查看此答案,可能會幫助解決您的問題: 如何在Android Gallery中保存圖片

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM