2016-03-02 9 views
7

मैं अपने Environment.getExternalStorageDirectory से एक स्क्रीनशॉट लोड करने के लिए कोशिश कर रहा हूँ() और यह बिटमैपएंड्रॉयड पीएनजी बिटमैप करने के लिए --- SkImageDecoder :: फैक्टरी लौटे अशक्त

public void onPictureTaken(String path) throws IOException { 

    String photoPath = filepath + "/" + path;; //UPDATE WITH YOUR OWN JPG FILE 

    File directory = new File (filepath); 
    File file = new File(directory, path); 

    final BitmapFactory.Options options = new BitmapFactory.Options(); 
    options.inJustDecodeBounds = true; 
    BitmapFactory.decodeFile(photoPath, options); 

    // Calculate inSampleSize 
    options.inSampleSize = 4; 
    options.inJustDecodeBounds = false; 
    BitmapFactory.decodeFile(photoPath, options); 

} 

बदलने की कोशिश -

private void observeSceenshot(){ 
    filepath = Environment.getExternalStorageDirectory() 
      + File.separator + Environment.DIRECTORY_PICTURES 
      + File.separator + "Screenshots"; 
    Log.d(TAG, filepath); 

    FileObserver fileObserver = new FileObserver(filepath, FileObserver.CREATE) { 
     @Override 
     public void onEvent(int event, String path) { 
      Log.d(TAG, event + " " + path); 
      try { 
       onPictureTaken(path); 
      } catch (FileNotFoundException e) { 
       e.printStackTrace(); 
      } catch (IOException e) { 
       e.printStackTrace(); 
      } 
     } 
    }; 

    fileObserver.startWatching(); 
} 
: - SkImageDecoder :: फैक्टरी अशक्त लौट आए

यहाँ मेरी समारोह जो onPictureTaken कहता है

क्या कोई इस समस्या को हल करने के बारे में जानता है? शायद क्योंकि मेरा पीएनजी बड़ा है (1280x720)? http://developer.android.com/training/displaying-bitmaps/load-bitmap.html

संपादित करें:: 56:: यहाँ लॉग

03-02 11 है मैं भी एक ही परिणाम के साथ इस समाधान की कोशिश की 19.806 11,581-11,716/com.example.chilred_pc.myapplication डी/DBG_com.example.chilred_pc.myapplication.ObserveScreenshots: 256 स्क्रीनशॉट_2016-03-02-11-56-19.png 03-02 11: 56: 19.806 11581-11716/com.example.chilred_pc.myapplication डी/निर्देशिका:/भंडारण/नकली/0/चित्र/स्क्रीनशॉट 03-02 11: 56: 19.806 11581-11716/com.example.chilred_pc.myapplication डी/फ़ाइल:/भंडारण/नकली/0/चित्र/स्क्रीनशॉट/स्क्रीनशॉट_2016-03-01-16 -38-08.png 03-02 11: 56: 19.806 11581-11716/com.example.chilred_pc.myapplication डी/फ़ाइल आकार: 35061 03-02 11: 56: 19.807 11581-11716/com.example.chilred_pc.myapplication डी/स्कीया: - 56: 19.808 11,581-11,716/com.example.chilred_pc.myapplication डी/skia: - SkImageDecoder :: फैक्टरी अशक्त 03-02 नवम्बर लौटे --- decoder-> डिकोड लौटे झूठी

+0

सुनिश्चित करें कि आप WRITE_EXTERNAL_STORAGE और AndroidManifest.xml में WRITE_EXTERNAL_STORAGE की अनुमति प्रदान करता है बनाओ:

> SystemClock.sleep(3000); 

लेकिन अंत में मैं एक और तरीका है, जो यहाँ दिखाया गया है इस्तेमाल किया। कृपया अपना त्रुटि लॉग पोस्ट करें। – pRaNaY

+0

जब आप 'int fileSize = file.length() 'करते हैं तो आपको क्या मिलता है? फ़ाइल आकार – Bhargav

+0

का मान क्या है मैंने इसे पहले ही androidmanifest.xml में लिखा था। – Maddin

उत्तर

1

मुझे लगता है कि समस्या का समाधान यह है कि स्क्रीनशॉट को छवि बनाने के लिए कुछ सेकंड की आवश्यकता होती है। तो मैंने कुछ सेकंड के लिए सिस्टम को रोकने की कोशिश की और अब यह काम कर रहा है। Detect only screenshot with FileObserver Android

0

के बजाय दिया options.inSampleSize = 4 करने के लिए मैन्युअल मूल्य नीचे दिए InSampleSize गणना:

... 
int reqWidth=100; // give your requested width 
int reqHeight=100;// give your requested height 
options.inSampleSize = calculateSampleSize(options,reqWidth,reqHeight); 
... 

public static int calculateSampleSize(BitmapFactory.Options options, 
     int reqWidth, int reqHeight) { 

    final int width = options.outWidth; 
    final int height = options.outHeight; 
    int inSampleSize = 1; 

    if (width > reqWidth || height > reqHeight) { 
     if (width > height) { 
      inSampleSize = Math.round((float) height/(float) reqHeight); 
     } else { 
      inSampleSize = Math.round((float) width/(float) reqWidth); 
     } 
    } 
    return inSampleSize; 
} 

गणना InSampleSize ही like जो आप बात कर रहे हैं पर दिया।

+0

मैंने कोशिश की, लेकिन यह कुछ भी नहीं बदले – Maddin

संबंधित मुद्दे