當前位置: 首頁>>代碼示例>>Java>>正文


Java BitmapFactory.decodeFile方法代碼示例

本文整理匯總了Java中android.graphics.BitmapFactory.decodeFile方法的典型用法代碼示例。如果您正苦於以下問題:Java BitmapFactory.decodeFile方法的具體用法?Java BitmapFactory.decodeFile怎麽用?Java BitmapFactory.decodeFile使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在android.graphics.BitmapFactory的用法示例。


在下文中一共展示了BitmapFactory.decodeFile方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: compressPhotoByQuality

import android.graphics.BitmapFactory; //導入方法依賴的package包/類
private void compressPhotoByQuality(File file, final OutputStream os, final int quality) throws IOException, OutOfMemoryError {
    BoxingLog.d("start compress quality... ");
    BitmapFactory.Options options = new BitmapFactory.Options();
    options.inPreferredConfig = Bitmap.Config.RGB_565;
    Bitmap bitmap = BitmapFactory.decodeFile(file.getAbsolutePath(), options);
    if (bitmap != null) {
        bitmap.compress(Bitmap.CompressFormat.JPEG, quality, os);
        bitmap.recycle();
    } else {
        throw new NullPointerException("bitmap is null when compress by quality");
    }
}
 
開發者ID:devzwy,項目名稱:NeiHanDuanZiTV,代碼行數:13,代碼來源:ImageCompressor.java

示例2: a

import android.graphics.BitmapFactory; //導入方法依賴的package包/類
private Bitmap a(Context context, String str) {
    File file = new File(str);
    if (file.exists()) {
        CompressFormat bmpFormat = BitmapHelper.getBmpFormat(str);
        int dipToPx = R.dipToPx(context, 120);
        if (CompressFormat.PNG == bmpFormat) {
            dipToPx = R.dipToPx(context, 90);
        }
        Bitmap decodeFile = BitmapFactory.decodeFile(str, new Options());
        if (file.length() > this.b) {
            Bitmap bitmap = decodeFile;
            while (dipToPx > 40 && a(bitmap, bmpFormat) > 32768) {
                int i = dipToPx - 5;
                int width = bitmap.getWidth();
                int height = bitmap.getHeight();
                double d = (height > i || width > i) ? height > width ? ((double) i) / ((double) height) : ((double) i) / ((double) width) : PathListView.NO_ZOOM;
                bitmap = Bitmap.createScaledBitmap(bitmap, (int) (((double) width) * d), (int) (d * ((double) height)), true);
                dipToPx = i;
            }
            OutputStream fileOutputStream = new FileOutputStream(File.createTempFile("sina_bm_tmp", "." + bmpFormat.name().toLowerCase()));
            bitmap.compress(bmpFormat, 100, fileOutputStream);
            fileOutputStream.flush();
            fileOutputStream.close();
            return bitmap;
        }
        Ln.i("sina weibo decode bitmap size ==>>" + a(decodeFile, bmpFormat), new Object[0]);
        return decodeFile;
    }
    throw new FileNotFoundException();
}
 
開發者ID:JackChan1999,項目名稱:boohee_v5.6,代碼行數:31,代碼來源:SinaActivity.java

示例3: compressBitmap

import android.graphics.BitmapFactory; //導入方法依賴的package包/類
/**
 * 壓縮圖片
 *
 * @param path 圖片路徑
 * @return 返回壓縮後的圖片,
 */
public static Bitmap compressBitmap(String path) {
    Bitmap bitmap;

    BitmapFactory.Options options = new BitmapFactory.Options();
    options.inJustDecodeBounds = true;
    BitmapFactory.decodeFile(path, options);
    int i = 0;

    while (true) {
        if ((options.outWidth >> i <= 1000)
                && (options.outHeight >> i <= 1000)) {
            options.inSampleSize = (int) Math.pow(2.0D, i);
            options.inJustDecodeBounds = false;
            bitmap = BitmapFactory.decodeFile(path, options);
            break;
        }
        i += 1;
    }
    return bitmap;
}
 
開發者ID:sundevin,項目名稱:utilsLibrary,代碼行數:27,代碼來源:BitmapUtils.java

示例4: getScaledBitmap

import android.graphics.BitmapFactory; //導入方法依賴的package包/類
private Bitmap getScaledBitmap(String filePath, int width) {
    BitmapFactory.Options options = new BitmapFactory.Options();
    options.inJustDecodeBounds = true;
    BitmapFactory.decodeFile(filePath, options);
    int sampleSize = options.outWidth > width ? options.outWidth / width
            + 1 : 1;
    options.inJustDecodeBounds = false;
    options.inSampleSize = sampleSize;
    return BitmapFactory.decodeFile(filePath, options);
}
 
開發者ID:appteam-nith,項目名稱:Nimbus,代碼行數:11,代碼來源:EditorView.java

示例5: startOCR

import android.graphics.BitmapFactory; //導入方法依賴的package包/類
/**
 * don't run this code in main thread - it stops UI thread. Create AsyncTask instead.
 * http://developer.android.com/intl/ru/reference/android/os/AsyncTask.html
 *
 * @param imgUri
 */
private void startOCR(Uri imgUri) {
    try {
        BitmapFactory.Options options = new BitmapFactory.Options();
        options.inSampleSize = 4; // 1 - means max size. 4 - means maxsize/4 size. Don't use value <4, because you need more memory in the heap to store your data.
        Bitmap bitmap = BitmapFactory.decodeFile(imgUri.getPath(), options);

        CV4JImage cv4JImage = new CV4JImage(bitmap);
        Threshold threshold = new Threshold();
        threshold.adaptiveThresh((ByteProcessor)(cv4JImage.convert2Gray().getProcessor()), Threshold.ADAPTIVE_C_MEANS_THRESH, 12, 30, Threshold.METHOD_THRESH_BINARY);
        Bitmap newBitmap = cv4JImage.getProcessor().getImage().toBitmap(Bitmap.Config.ARGB_8888);

        ivImage2.setImageBitmap(newBitmap);

        String result = extractText(newBitmap);
        resultView.setText(result);

    } catch (Exception e) {
        Log.e(TAG, e.getMessage());
    }
}
 
開發者ID:fengzhizi715,項目名稱:Tess-TwoDemo,代碼行數:27,代碼來源:TestEnglishWithCV4JActivity.java

示例6: compressPic

import android.graphics.BitmapFactory; //導入方法依賴的package包/類
private void compressPic() {
    // Get the dimensions of the bitmap
    BitmapFactory.Options bmOptions = new BitmapFactory.Options();
    bmOptions.inJustDecodeBounds = true;
    BitmapFactory.decodeFile(mCurrentPhotoPath, bmOptions);
    // Determine how much to scale down the image
    int scaleFactor = 2;

    // Decode the image file into a Bitmap sized to fill the View
    bmOptions.inJustDecodeBounds = false;
    bmOptions.inSampleSize = scaleFactor;
    bmOptions.inPurgeable = true;

    Bitmap bitmap = BitmapFactory.decodeFile(mCurrentPhotoPath, bmOptions);
    mImageView.setImageBitmap(bitmap);
}
 
開發者ID:gejiaheng,項目名稱:TakingPhotosSimply,代碼行數:17,代碼來源:MainActivity.java

示例7: decodeBitmapFromFile

import android.graphics.BitmapFactory; //導入方法依賴的package包/類
/**
 * Decode and sample down a bitmap from a file to the requested width and height.
 *
 * @param filename The full path of the file to decode
 * @param reqWidth The requested width of the resulting bitmap
 * @param reqHeight The requested height of the resulting bitmap
 * @return A bitmap sampled down from the original with the same aspect ratio and dimensions
 *         that are equal to or greater than the requested width and height
 */
public static Bitmap decodeBitmapFromFile(String filename, int reqWidth, int reqHeight) {
    // First decode with inJustDecodeBounds=true to check dimensions
    final BitmapFactory.Options options = new BitmapFactory.Options();
    options.inJustDecodeBounds = true;
    BitmapFactory.decodeFile(filename, options);

    // Calculate inSampleSize
    options.inSampleSize = calculateInSampleSize(options, reqWidth, reqHeight);

    // Decode bitmap with inSampleSize set
    options.inJustDecodeBounds = false;
    return BitmapFactory.decodeFile(filename, options);
}
 
開發者ID:Kaufland,項目名稱:andcouchbaseentity,代碼行數:23,代碼來源:ImageUtil.java

示例8: compressBitmapFromFile

import android.graphics.BitmapFactory; //導入方法依賴的package包/類
/**
    *壓縮指定路徑的圖片,並得到圖片對象
    * @param path
    * @return
    */
   private Bitmap compressBitmapFromFile(String path)
   {
       BitmapFactory.Options options=new BitmapFactory.Options();
       options.inJustDecodeBounds = true;
       Bitmap bitmap=BitmapFactory.decodeFile(path, options);

       options.inJustDecodeBounds = false;
       int width=options.outWidth;
       int height=options.outHeight;

       float widthRadio=480f;
       float heightRadio=800f;
       int inSampleSize=1;
       if (width > height && width > widthRadio)
{
           inSampleSize = (int) (width * 1.0f / widthRadio);
       }
else if (width < height && height > heightRadio)
{
           inSampleSize = (int) (height * 1.0f / heightRadio);
       }
       if (inSampleSize <= 0)
{
           inSampleSize = 1;
       }
       options.inSampleSize = inSampleSize;
       bitmap = BitmapFactory.decodeFile(path, options);
       return compressBitmap(bitmap);
   }
 
開發者ID:stytooldex,項目名稱:stynico,代碼行數:35,代碼來源:l.java

示例9: onBackground

import android.graphics.BitmapFactory; //導入方法依賴的package包/類
public Attachment onBackground(final Uri value) throws Exception {
    final File file = makeFile(value);
    final String type = resolver.getType(value);
    if (type != null
            && type.startsWith("image/")
            && BitmapFactory.decodeFile(file.getAbsolutePath()) != null) {
        return new Attachment(file, Attachment.Type.IMAGE);
    } else {
        return new Attachment(file, Attachment.Type.UNKNOWN);
    }
}
 
開發者ID:PacktPublishing,項目名稱:Hands-On-Android-UI-Development,代碼行數:12,代碼來源:CreateAttachmentCommand.java

示例10: composeBitmap

import android.graphics.BitmapFactory; //導入方法依賴的package包/類
private Bitmap composeBitmap(List<String> posters) {

        View compositionView  = LayoutInflater.from(mContext).inflate(R.layout.all_movies_icon, null);

        // Get the 8 ImagesViews from the layout
        ArrayList<ImageView> imageViews = new ArrayList<>(8);
        for (int id : new int[] {R.id.poster1, R.id.poster2, R.id.poster3, R.id.poster4, R.id.poster5, R.id.poster6, R.id.poster7, R.id.poster8}) {
            imageViews.add((ImageView) compositionView.findViewById(id));
        }

        BitmapFactory.Options options = new BitmapFactory.Options();
        options.inSampleSize = 2; // posters are way larger than needed here, we can sub-sample
        options.inScaled = false; // no need to take care of the screen density at this stage

        // Decode the posters and assign to the image views
        Iterator<String> poster = posters.iterator();
        for (ImageView iv : imageViews) {
            // try next posters in case the first one fails to decode
            while (poster.hasNext()) {
                Bitmap b = BitmapFactory.decodeFile(poster.next(), options);
                if (b!=null) {
                    iv.setImageBitmap(b);
                    break;
                }
            }
        }

        // measureAndLayout
        compositionView.measure(View.MeasureSpec.makeMeasureSpec(mWidth, View.MeasureSpec.EXACTLY), View.MeasureSpec.makeMeasureSpec(mHeight, View.MeasureSpec.EXACTLY));
        compositionView.layout(0, 0, mWidth, mHeight);

        // make the bitmap
        Canvas canvas = new Canvas();
        Bitmap bitmap = Bitmap.createBitmap( mWidth, mHeight, Bitmap.Config.ARGB_8888 );
        canvas.setBitmap(bitmap);
        compositionView.draw(canvas);
        return bitmap;
    }
 
開發者ID:archos-sa,項目名稱:aos-Video,代碼行數:39,代碼來源:AllMoviesIconBuilder.java

示例11: loadBitmap

import android.graphics.BitmapFactory; //導入方法依賴的package包/類
private static Bitmap loadBitmap(String path) throws FileNotFoundException {
  Bitmap bitmap = BitmapFactory.decodeFile(path);
  if (bitmap == null) {
    throw new FileNotFoundException("Couldn't open " + path);
  }
  return bitmap;
}
 
開發者ID:mangestudio,項目名稱:GCSApp,代碼行數:8,代碼來源:RGBLuminanceSource.java

示例12: handleCrop

import android.graphics.BitmapFactory; //導入方法依賴的package包/類
private void handleCrop(int resultCode, Intent result) {
    if (resultCode == RESULT_OK) {
    	Uri pp=Crop.getOutput(result);
    	String p1=pp.toString();
        p = comman.compressImage(AddNewGroup.this, p1);
        selectedImage = BitmapFactory.decodeFile(p);
        mImgGroupPhoto.setImageBitmap(selectedImage);
    } else if (resultCode == Crop.RESULT_ERROR) {
        Toast.makeText(this, Crop.getError(result).getMessage(), Toast.LENGTH_SHORT).show();
    }
}
 
開發者ID:mityung,項目名稱:XERUNG,代碼行數:12,代碼來源:AddNewGroup.java

示例13: resizeBitmap

import android.graphics.BitmapFactory; //導入方法依賴的package包/類
public static Bitmap resizeBitmap(File file, int widthMax, int heightMax) {
    BitmapFactory.Options decodeOptions = new BitmapFactory.Options();
    Bitmap bitmap = null;
    // If we have to resize this image, first get the natural bounds.
    decodeOptions.inJustDecodeBounds = true;
    BitmapFactory.decodeFile(file.getPath(), decodeOptions);
    int actualWidth = decodeOptions.outWidth;
    int actualHeight = decodeOptions.outHeight;

    int desiredWidth = getResizedDimension(widthMax, heightMax, actualWidth, actualHeight);
    int desiredHeight = getResizedDimension(heightMax, widthMax, actualHeight, actualWidth);

    // TODO(ficus): Do we need this or is it okay since API 8 doesn't
    // support it?
    // decodeOptions.inPreferQualityOverSpeed = PREFER_QUALITY_OVER_SPEED;
    decodeOptions.inSampleSize = findBestSampleSize(actualWidth, actualHeight, desiredWidth, desiredHeight);

    // Decode to the nearest power of two scaling factor.
    decodeOptions.inJustDecodeBounds = false;
    Bitmap tempBitmap = BitmapFactory.decodeFile(file.getPath(), decodeOptions);

    // If necessary, scale down to the maximal acceptable size.
    if (tempBitmap != null && (tempBitmap.getWidth() > desiredWidth || tempBitmap.getHeight() > desiredHeight)) {
        bitmap = Bitmap.createScaledBitmap(tempBitmap, desiredWidth, desiredHeight, true);
        tempBitmap.recycle();
    } else {
        bitmap = tempBitmap;
    }

    return bitmap;
}
 
開發者ID:HanyeeWang,項目名稱:GeekZone,代碼行數:32,代碼來源:ImageUtils.java

示例14: getImageThumbnail

import android.graphics.BitmapFactory; //導入方法依賴的package包/類
public static Bitmap getImageThumbnail(String imagePath, int width, int height) {
    Bitmap bitmap;
    BitmapFactory.Options options = new BitmapFactory.Options();
    options.inJustDecodeBounds = true;
    // 獲取這個圖片的寬和高,注意此處的bitmap為null
    bitmap = BitmapFactory.decodeFile(imagePath, options);
    options.inJustDecodeBounds = false; // 設為 false
    // 計算縮放比
    int h = options.outHeight;
    int w = options.outWidth;
    int beWidth = w / width;
    int beHeight = h / height;
    int be = 1;
    if (beWidth < beHeight) {
        be = beWidth;
    } else {
        be = beHeight;
    }
    if (be <= 0) {
        be = 1;
    }
    options.inSampleSize = be;
    // 重新讀入圖片,讀取縮放後的bitmap,注意這次要把options.inJustDecodeBounds 設為 false
    bitmap = BitmapFactory.decodeFile(imagePath, options);
    // 利用ThumbnailUtils來創建縮略圖,這裏要指定要縮放哪個Bitmap對象
    bitmap = ThumbnailUtils.extractThumbnail(bitmap, width, height,
            ThumbnailUtils.OPTIONS_RECYCLE_INPUT);
    return bitmap;
}
 
開發者ID:zhonglikui,項目名稱:cardinalsSample,代碼行數:30,代碼來源:PhotoCaptureUtil.java

示例15: newProfileImageSelected

import android.graphics.BitmapFactory; //導入方法依賴的package包/類
@Test
public void newProfileImageSelected() throws Exception {
    Bitmap image = null;
    mPresenter.newProfileImageSelected(image);
    verify(mView, never()).updateProgress(true);

    image = BitmapFactory.decodeFile("../test.png");
    mPresenter.newProfileImageSelected(image);
    verify(mView).updateProgress(true);

    verify(mView, timeout(Constants.ASYNC_CONNECTION_EXTENDED_TIMEOUT).times(1)).updateProgress(false);
    verify(mView).uploadComplete(true, image, null);
}
 
開發者ID:Q115,項目名稱:Goalie_Android,代碼行數:14,代碼來源:ProfilePresenterUnitTest.java


注:本文中的android.graphics.BitmapFactory.decodeFile方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。