Search in sources :

Example 26 with Options

use of android.graphics.BitmapFactory.Options in project PocketHub by pockethub.

the class ImageUtils method getSize.

/**
     * Get size of image
     *
     * @param imagePath
     * @return size
     */
public static Point getSize(final String imagePath) {
    final Options options = new Options();
    options.inJustDecodeBounds = true;
    RandomAccessFile file = null;
    try {
        file = new RandomAccessFile(imagePath, "r");
        BitmapFactory.decodeFileDescriptor(file.getFD(), null, options);
        return new Point(options.outWidth, options.outHeight);
    } catch (IOException e) {
        Log.d(TAG, e.getMessage(), e);
        return null;
    } finally {
        if (file != null) {
            try {
                file.close();
            } catch (IOException e) {
                Log.d(TAG, e.getMessage(), e);
            }
        }
    }
}
Also used : Options(android.graphics.BitmapFactory.Options) RandomAccessFile(java.io.RandomAccessFile) Point(android.graphics.Point) IOException(java.io.IOException)

Example 27 with Options

use of android.graphics.BitmapFactory.Options in project mobile-android by photo.

the class BordersPanel method onCreate.

@SuppressWarnings("deprecation")
@Override
public void onCreate(Bitmap bitmap) {
    super.onCreate(bitmap);
    mImageManager = new AsyncImageManager(1);
    mThumbnailOptions = new Options();
    mThumbnailOptions.inPreferredConfig = Config.RGB_565;
    mPluginService = getContext().getService(PluginService.class);
    mCacheService = getContext().getService(ImageCacheService.class);
    mPreferenceService = getContext().getService(PreferenceService.class);
    if (mPluginType == FeatherIntent.PluginType.TYPE_FILTER)
        mExternalPacksEnabled = Constants.getValueFromIntent(Constants.EXTRA_EFFECTS_ENABLE_EXTERNAL_PACKS, true);
    else
        mExternalPacksEnabled = Constants.getValueFromIntent(Constants.EXTRA_FRAMES_ENABLE_EXTERNAL_PACKS, true);
    mViewFlipper = (ViewFlipper) getOptionView().findViewById(R.id.flipper);
    mHList = (HorizontalVariableListView) getOptionView().findViewById(R.id.list);
    mHList.setOverScrollMode(View.OVER_SCROLL_ALWAYS);
    mPreview = BitmapUtils.copy(mBitmap, Bitmap.Config.ARGB_8888);
    // ImageView Switcher setup
    mImageSwitcher = (ImageSwitcher) getContentView().findViewById(R.id.switcher);
    initContentImage(mImageSwitcher);
    // Horizontal list setup
    mHList.setOnScrollListener(this);
    View content = getOptionView().findViewById(R.id.background);
    content.setBackgroundDrawable(RepeatableHorizontalDrawable.createFromView(content));
    try {
        updateArrowBitmap = BitmapFactory.decodeResource(getContext().getBaseContext().getResources(), R.drawable.feather_update_arrow);
    } catch (Throwable t) {
    }
    mEnableEffectAnimation = Constants.ANDROID_SDK > android.os.Build.VERSION_CODES.GINGERBREAD && SystemUtils.getCpuMhz() > 800;
// mSelectedPosition = 0;
}
Also used : Options(android.graphics.BitmapFactory.Options) PreferenceService(com.aviary.android.feather.library.services.PreferenceService) PluginService(com.aviary.android.feather.library.services.PluginService) ImageCacheService(com.aviary.android.feather.library.services.ImageCacheService) AsyncImageManager(com.aviary.android.feather.async_tasks.AsyncImageManager) ImageView(android.widget.ImageView) View(android.view.View) AdapterView(android.widget.AdapterView) TextView(android.widget.TextView) HorizontalVariableListView(com.aviary.android.feather.widget.HorizontalVariableListView)

Example 28 with Options

use of android.graphics.BitmapFactory.Options in project AisenWeiBo by wangdan.

the class WallpaperDownloadTask method setWallpaper.

// 设置壁纸
public static void setWallpaper(Context context, File file, final OnProgressCallback callback) throws TaskException {
    long time = System.currentTimeMillis();
    try {
        WallpaperManager wallpaperManager = WallpaperManager.getInstance(GlobalContext.getInstance());
        try {
            DisplayMetrics dm = new DisplayMetrics();
            WindowManager windowManager = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
            windowManager.getDefaultDisplay().getMetrics(dm);
            int width = dm.widthPixels;
            int height = dm.heightPixels;
            int navigationBarHeight = SystemUtils.getNavigationBarHeight(context);
            int wallpaperWidth = width;
            int wallpaperHeight = height;
            Options opts = new Options();
            opts.inJustDecodeBounds = true;
            Bitmap bitmap = BitmapFactory.decodeFile(file.getAbsolutePath(), opts);
            boolean decode = false;
            if (opts.outHeight > height + navigationBarHeight) {
                decode = true;
            }
            Logger.d(TAG, "image height = %d, screen height = %d", opts.outHeight, height + navigationBarHeight);
            if (decode) {
                // docode的时间会稍微长一点,idol3测试在1S内,所以先显示一个99%的进度
                //                    if (progress <= 0) {
                //                        progress = 999l;
                //                        total = 1000l;
                //                        publishProgress(progress, total);
                //                    }
                opts.inJustDecodeBounds = false;
                bitmap = BitmapFactory.decodeStream(new FileInputStream(file));
                Matrix matrix = new Matrix();
                float scale = wallpaperHeight * 1.0f / bitmap.getHeight();
                matrix.setScale(scale, scale);
                bitmap = Bitmap.createBitmap(bitmap, 0, 0, bitmap.getWidth(), bitmap.getHeight(), matrix, true);
                ByteArrayOutputStream out = new ByteArrayOutputStream();
                bitmap.compress(Bitmap.CompressFormat.JPEG, 90, out);
                ByteArrayInputStream in = new ByteArrayInputStream(out.toByteArray());
                wallpaperManager.setStream(in);
                if (callback != null) {
                    new Handler(Looper.getMainLooper()).post(new Runnable() {

                        @Override
                        public void run() {
                            callback.onSetWallpaper(true);
                        }
                    });
                }
                Logger.d(TAG, "设置处理后的壁纸耗时 : " + (System.currentTimeMillis() - time));
                return;
            }
        } catch (Throwable e) {
            Logger.printExc(WallpaperDownloadTask.class, e);
        }
        wallpaperManager.setStream(new FileInputStream(file));
        Logger.d(TAG, "设置原壁纸耗时 : " + (System.currentTimeMillis() - time));
        if (callback != null) {
            new Handler(Looper.getMainLooper()).post(new Runnable() {

                @Override
                public void run() {
                    callback.onSetWallpaper(true);
                }
            });
        }
    } catch (Exception e) {
        Logger.printExc(WallpaperDownloadTask.class, e);
        if (callback != null) {
            new Handler(Looper.getMainLooper()).post(new Runnable() {

                @Override
                public void run() {
                    callback.onSetWallpaper(false);
                }
            });
        }
        throw new TaskException("", context.getResources().getString(R.string.txt_set_wallpaper_fail));
    }
}
Also used : Options(android.graphics.BitmapFactory.Options) Handler(android.os.Handler) ByteArrayOutputStream(java.io.ByteArrayOutputStream) DisplayMetrics(android.util.DisplayMetrics) FileInputStream(java.io.FileInputStream) TaskException(org.aisen.android.network.task.TaskException) IOException(java.io.IOException) WindowManager(android.view.WindowManager) Bitmap(android.graphics.Bitmap) Matrix(android.graphics.Matrix) TaskException(org.aisen.android.network.task.TaskException) ByteArrayInputStream(java.io.ByteArrayInputStream) WallpaperManager(android.app.WallpaperManager)

Example 29 with Options

use of android.graphics.BitmapFactory.Options in project AisenWeiBo by wangdan.

the class PictureFragment method readGifPicture.

@SuppressLint("SetJavaScriptEnabled")
private void readGifPicture(final WebView webview, byte[] bytes, File file) {
    Options options = new Options();
    options.inJustDecodeBounds = true;
    BitmapFactory.decodeByteArray(bytes, 0, bytes.length, options);
    int picWidth = options.outWidth;
    int picHeight = options.outHeight;
    int availableWidth = SystemUtils.getScreenWidth(getActivity()) - getResources().getDimensionPixelOffset(R.dimen.normal_gif_webview_margin_left) - getResources().getDimensionPixelOffset(R.dimen.normal_gif_webview_margin_right);
    int availableHeight = getAppHeight(getActivity());
    int maxPossibleResizeHeight = availableWidth * availableHeight / picWidth;
    if (picWidth >= availableWidth || picHeight >= availableHeight || maxPossibleResizeHeight >= availableHeight) {
        readLargePicture(webview, file);
        return;
    }
    webview.getSettings().setJavaScriptEnabled(true);
    webview.getSettings().setUseWideViewPort(true);
    webview.getSettings().setLoadWithOverviewMode(true);
    webview.getSettings().setBuiltInZoomControls(false);
    webview.getSettings().setDisplayZoomControls(false);
    webview.getSettings().setSupportZoom(false);
    webview.setVerticalScrollBarEnabled(false);
    webview.setHorizontalScrollBarEnabled(false);
    String str1 = "file://" + file.getAbsolutePath().replace("/mnt/sdcard/", "/sdcard/");
    String str2 = "<html>\n<head>\n     <style>\n          html,body{background:#3b3b3b;margin:0;padding:0;}          *{-webkit-tap-highlight-color:rgba(0, 0, 0, 0);}\n     </style>\n     <script type=\"text/javascript\">\n     var imgUrl = \"" + str1 + "\";" + "     var objImage = new Image();\n" + "     var realWidth = 0;\n" + "     var realHeight = 0;\n" + "\n" + "     function onLoad() {\n" + "          objImage.onload = function() {\n" + "               realWidth = objImage.width;\n" + "               realHeight = objImage.height;\n" + "\n" + "               document.gagImg.src = imgUrl;\n" + "               onResize();\n" + "          }\n" + "          objImage.src = imgUrl;\n" + "     }\n" + "\n" + "     function imgOnClick() {\n" + "			window.picturejs.onClick();" + "     }\n" + "     function onResize() {\n" + "          var scale = 1;\n" + "          var newWidth = document.gagImg.width;\n" + "          if (realWidth > newWidth) {\n" + "               scale = realWidth / newWidth;\n" + "          } else {\n" + "               scale = newWidth / realWidth;\n" + "          }\n" + "\n" + "          hiddenHeight = Math.ceil(30 * scale);\n" + "          document.getElementById('hiddenBar').style.height = hiddenHeight + \"px\";\n" + "          document.getElementById('hiddenBar').style.marginTop = -hiddenHeight + \"px\";\n" + "     }\n" + "     </script>\n" + "</head>\n" + "<body onload=\"onLoad()\" onresize=\"onResize()\" onclick=\"Android.toggleOverlayDisplay();\">\n" + "     <table style=\"width: 100%;height:100%;\">\n" + "          <tr style=\"width: 100%;\">\n" + "               <td valign=\"middle\" align=\"center\" style=\"width: 100%;\">\n" + "                    <div style=\"display:block\">\n" + "                         <img name=\"gagImg\" src=\"\" width=\"100%\" style=\"\" onclick=\"imgOnClick()\" />\n" + "                    </div>\n" + "                    <div id=\"hiddenBar\" style=\"position:absolute; width: 0%; background: #3b3b3b;\"></div>\n" + "               </td>\n" + "          </tr>\n" + "     </table>\n" + "</body>\n" + "</html>";
    webview.loadDataWithBaseURL("file:///android_asset/", str2, "text/html", "utf-8", null);
    webview.postDelayed(new Runnable() {

        @Override
        public void run() {
            webview.setVisibility(View.VISIBLE);
        }
    }, 500);
}
Also used : Options(android.graphics.BitmapFactory.Options) SuppressLint(android.annotation.SuppressLint) SuppressLint(android.annotation.SuppressLint)

Example 30 with Options

use of android.graphics.BitmapFactory.Options in project AisenWeiBo by wangdan.

the class PictureFragment method onDownloadPicture.

private void onDownloadPicture(byte[] bytes, File file) {
    if (getActivity() == null)
        return;
    getActivity().invalidateOptionsMenu();
    progressView.setVisibility(View.INVISIBLE);
    Options opts = new Options();
    opts.inJustDecodeBounds = true;
    BitmapFactory.decodeByteArray(bytes, 0, bytes.length, opts);
    // gif
    if (BitmapUtil.getType(bytes) == BitmapType.gif) {
        readGifPicture(mWebView, bytes, file);
    } else // 图片太大
    if (opts.outWidth > 1024 || opts.outHeight > 1024) {
        readLargePicture(mWebView, file);
    } else // 解析图片
    {
        readPicture(bytes, file, photoView);
    }
    getActivity().invalidateOptionsMenu();
}
Also used : Options(android.graphics.BitmapFactory.Options)

Aggregations

Options (android.graphics.BitmapFactory.Options)30 Bitmap (android.graphics.Bitmap)12 IOException (java.io.IOException)10 BitmapFactory (android.graphics.BitmapFactory)6 FileInputStream (java.io.FileInputStream)6 InputStream (java.io.InputStream)4 File (java.io.File)3 Matrix (android.graphics.Matrix)2 Paint (android.graphics.Paint)2 Point (android.graphics.Point)2 BitmapDrawable (android.graphics.drawable.BitmapDrawable)2 ExifInterface (android.media.ExifInterface)2 Handler (android.os.Handler)2 ImageSize (com.nostra13.universalimageloader.core.assist.ImageSize)2 ImageSize (com.smartandroid.sa.zUImageLoader.core.assist.ImageSize)2 ByteArrayInputStream (java.io.ByteArrayInputStream)2 ByteArrayOutputStream (java.io.ByteArrayOutputStream)2 FileDescriptor (java.io.FileDescriptor)2 FileNotFoundException (java.io.FileNotFoundException)2 FileOutputStream (java.io.FileOutputStream)2