当前位置: 首页>>代码示例>>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;未经允许,请勿转载。