コード例 #1
0
  public static int loadTexture(final Context context, final int resourceId) {
    final int[] textureHandle = new int[1];

    GLES20.glGenTextures(1, textureHandle, 0);

    if (textureHandle[0] != 0) {
      final BitmapFactory.Options options = new BitmapFactory.Options();
      options.inScaled = false;

      final Bitmap bitmap =
          BitmapFactory.decodeResource(context.getResources(), resourceId, options);

      GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, textureHandle[0]);

      GLES20.glTexParameteri(GLES20.GL_TEXTURE_2D, GLES20.GL_TEXTURE_MIN_FILTER, GLES20.GL_NEAREST);
      GLES20.glTexParameteri(GLES20.GL_TEXTURE_2D, GLES20.GL_TEXTURE_MAG_FILTER, GLES20.GL_NEAREST);

      GLUtils.texImage2D(GLES20.GL_TEXTURE_2D, 0, bitmap, 0);

      bitmap.recycle();
    }

    if (textureHandle[0] == 0) {
      throw new RuntimeException("Error loading texture.");
    }

    return textureHandle[0];
  }
コード例 #2
0
  public static int loadTexture(final Context context, final int resourceId) {
    final int[] textureHandle = new int[1];

    GLES20.glGenTextures(1, textureHandle, 0);

    if (textureHandle[0] != 0) {
      final BitmapFactory.Options options = new BitmapFactory.Options();
      options.inScaled = false; // No pre-scaling

      // Read in the resource
      final Bitmap bitmap =
          BitmapFactory.decodeResource(context.getResources(), resourceId, options);

      // Bind to the texture in OpenGL
      GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, textureHandle[0]);

      // Set filtering
      GLES20.glTexParameteri(GLES20.GL_TEXTURE_2D, GLES20.GL_TEXTURE_MIN_FILTER, GLES20.GL_NEAREST);
      GLES20.glTexParameteri(GLES20.GL_TEXTURE_2D, GLES20.GL_TEXTURE_MAG_FILTER, GLES20.GL_NEAREST);
      GLES20.glTexParameteri(GLES20.GL_TEXTURE_2D, GLES20.GL_TEXTURE_WRAP_S, GLES20.GL_REPEAT);
      GLES20.glTexParameteri(GLES20.GL_TEXTURE_2D, GLES20.GL_TEXTURE_WRAP_T, GLES20.GL_REPEAT);
      // Load the bitmap into the bound texture.
      GLUtils.texImage2D(GLES20.GL_TEXTURE_2D, 0, bitmap, 0);

      // Recycle the bitmap, since its data has been loaded into OpenGL.
      bitmap.recycle();
    }

    if (textureHandle[0] == 0) {
      throw new RuntimeException("Error loading texture.");
    }

    return textureHandle[0];
  }
コード例 #3
0
 private final Bitmap compress(String uri, int reqWidth, int reqHeight) {
   Bitmap bitmap = null;
   try {
     BitmapFactory.Options opts = new BitmapFactory.Options();
     opts.inJustDecodeBounds = true;
     BitmapFactory.decodeFile(uri, opts);
     int height = opts.outHeight;
     int width = opts.outWidth;
     int inSampleSize = 1;
     if (width > height && width > reqWidth) {
       inSampleSize = Math.round((float) width / (float) reqWidth);
     } else if (height > width && height > reqHeight) {
       inSampleSize = Math.round((float) height / (float) reqHeight);
     }
     if (inSampleSize <= 1) inSampleSize = 1;
     opts.inSampleSize = inSampleSize;
     opts.inJustDecodeBounds = false;
     opts.inPreferredConfig = Config.RGB_565;
     opts.inPurgeable = true;
     opts.inInputShareable = true;
     opts.inTargetDensity = getResources().getDisplayMetrics().densityDpi;
     opts.inScaled = true;
     opts.inTempStorage = new byte[16 * 1024];
     bitmap =
         BitmapFactory.decodeStream(new BufferedInputStream(new FileInputStream(uri)), null, opts);
   } catch (FileNotFoundException e) {
     e.printStackTrace();
   } catch (OutOfMemoryError e) {
     e.printStackTrace();
   }
   return bitmap;
 }
コード例 #4
0
  private boolean addTile() throws Exception {
    if (doesTileExist(client.getTileManager().getTiles().await(), tileId)) {
      return true;
    }

    /* Set the options */
    BitmapFactory.Options options = new BitmapFactory.Options();
    options.inScaled = false;
    options.inPreferredConfig = Bitmap.Config.ARGB_8888;
    Bitmap tileIcon =
        BitmapFactory.decodeResource(
            getBaseContext().getResources(), R.raw.drone_designer_icon, options);

    BandTile tile =
        new BandTile.Builder(tileId, "Drone", tileIcon)
            .setPageLayouts(createButtonLayout())
            .build();
    appendToUI("Button Tile is adding ...\n", 1);
    if (client.getTileManager().addTile(this, tile).await()) {
      appendToUI("Button Tile is added.\n", 1);
      return true;
    } else {
      appendToUI("Unable to add button tile to the band.\n", 1);
      return false;
    }
  }
コード例 #5
0
ファイル: ImageManager.java プロジェクト: pageman/PhotoChop
  public static Bitmap getBitmap(String img_url, Integer reqWidth, Integer reqHeight)
      throws FileNotFoundException {
    Log.e("getBitmap", img_url);
    Bitmap bitmap = null;
    File file = new File(AppConstants.CACHED_IMGS_DIR + getBaseFilename(img_url));

    Log.e("getBitmap", file.getAbsolutePath());
    if (file.exists() && file.length() == 0) {
      file.delete();
      Log.e("getBitmap", "tangina naman");
    }
    if (!file.exists() && !"-".equals(img_url)) {
      throw new FileNotFoundException("Something went wrong");
    }

    // Bitmap bitmap = BitmapFactory.decodeStream(new
    // FileInputStream(file));

    if (reqWidth != null && reqHeight != null) {
      BitmapFactory.Options options = new BitmapFactory.Options();
      options.inJustDecodeBounds = true;
      BitmapFactory.decodeFile(file.getAbsolutePath(), options);
      options.inSampleSize = ImageManager.calculateInSampleSize(options, reqWidth, reqHeight);
      options.inTargetDensity = 160;
      options.inDensity = 160;
      options.inScaled = true;
      options.inJustDecodeBounds = false;
      //            bitmap = BitmapFactory.decodeFile(filePath, options);
      //            bitmap = BitmapFactory.decodeFile(filePath, options);
      bitmap =
          BitmapFactory.decodeFile(
              new File(mContext.getFilesDir(), getBaseFilename(img_url)).getAbsolutePath(),
              options);

      // bitmap = BitmapFactory.decodeResource(context.getResources(),
      // R.drawable.corp_nestle, options);
    } else {
      BitmapFactory.Options options = new BitmapFactory.Options();
      options.inTargetDensity = 160;
      options.inDensity = 160;
      options.inScaled = true;
      bitmap = BitmapFactory.decodeFile(file.getAbsolutePath());
      Log.e("getBitmap", "tangina2");
    }

    return bitmap;
  }
コード例 #6
0
 /**
  * Actually converts the given {@link InputStream} into an Android {@link Bitmap}.
  *
  * <p>The hereby implementation does not perform any scaling.
  *
  * @param inputStream the representation of the {@link Bitmap} to be decoded
  * @return the decoded {@link Bitmap} if the conversion could be performed properly ; {@code
  *     null} otherwise
  * @see #convert(InputStream, String, Object, String)
  */
 protected Bitmap convertInputStreamToBitmap(
     InputStream inputStream, String bitmapUid, Object imageSpecs, String url) {
   final BitmapFactory.Options options = new BitmapFactory.Options();
   options.inScaled = false;
   options.inDither = false;
   options.inDensity = 0;
   return BitmapFactory.decodeStream(inputStream, null, options);
 }
コード例 #7
0
ファイル: ImageHelper.java プロジェクト: bagavi/Saarang2013
 /**
  * Decodes only image size for InputStream.
  *
  * @param in InputStream containing the bitmap
  * @return BitmapFactory.Options with size fields populated.
  */
 public static BitmapFactory.Options decodeImageBounds(InputStream in) {
   BitmapFactory.Options options = new BitmapFactory.Options();
   options.inScaled = false;
   options.inTargetDensity = 0;
   options.inJustDecodeBounds = true;
   BitmapFactory.decodeStream(in, null, options);
   return options;
 }
コード例 #8
0
 /**
  * Convenience method for use in reloading an unscaled {@link Bitmap} without recreating the
  * entire resource.
  *
  * @param bitmapResId The id of the bitmap resource for this crushed sprite.
  * @param resources A {@link Resources} instance to load assets from.
  */
 public static Bitmap loadBitmap(int bitmapResId, Resources resources) {
   TraceEvent.begin("CrushedSpriteResource.loadBitmap");
   BitmapFactory.Options opts = new BitmapFactory.Options();
   opts.inScaled = false;
   Bitmap bitmap = BitmapFactory.decodeResource(resources, bitmapResId, opts);
   TraceEvent.end("CrushedSpriteResource.loadBitmap");
   return bitmap;
 }
コード例 #9
0
ファイル: WidgetTestUtils.java プロジェクト: rcoscali/cts
 /**
  * Retrieve a dithered bitmap that can be used for comparison on any density
  *
  * @param resources
  * @param config the preferred config for the returning bitmap
  * @return the {@link Bitmap} or <code>null</code>
  */
 public static Bitmap getUnscaledAndDitheredBitmap(
     Resources resources, int resId, Bitmap.Config config) {
   BitmapFactory.Options options = new BitmapFactory.Options();
   options.inDither = true;
   options.inScaled = false;
   options.inPreferredConfig = config;
   return BitmapFactory.decodeResource(resources, resId, options);
 }
コード例 #10
0
ファイル: AndroidAssets.java プロジェクト: hatboyzero/playn
 private Bitmap decodeBitmap(InputStream is) {
   BitmapFactory.Options options = new BitmapFactory.Options();
   options.inDither = true;
   // Prefer the bitmap config we computed from the window parameter
   options.inPreferredConfig = graphics.preferredBitmapConfig;
   // Never scale bitmaps based on device parameters
   options.inScaled = false;
   return BitmapFactory.decodeStream(is, null, options);
 }
コード例 #11
0
ファイル: Engine.java プロジェクト: desko27/LittleSpaceships
  public void updateBitmap(int id) {

    // get non-resized bitmap
    BitmapFactory.Options o = new BitmapFactory.Options();
    o.inScaled = false;
    bitmap = BitmapFactory.decodeResource(r.getResources(), id, o);

    // get scaled bitmap
    screen_bitmap =
        Bitmap.createScaledBitmap(
            bitmap, r.room2screen(get_width()), r.room2screen(get_height()), false);
  }
コード例 #12
0
  @Override
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_work_mapping_activity);
    //
    Intent recieve = getIntent();
    buildingImg = recieve.getByteArrayExtra("img");
    z = recieve.getDoubleExtra("z", 0);
    scale = recieve.getDoubleExtra("scale", 0.05);
    savedPoint = new xy();
    curPoint = new xy();
    //
    getWindowSize();
    drawer = (SlidingDrawer) findViewById(R.id.activity_work_mapping_drawer);
    menulayer =
        (LinearLayout) findViewById(R.id.activity_work_mapping_draggable_containmenubuttonlayout);
    map_frame = (FrameLayout) findViewById(R.id.activity_work_mapping_draggable_frame);
    DimageView = (DraggableImageView) findViewById(R.id.activity_work_mapping_draggable_imageview);
    //
    BitmapFactory.Options option = new BitmapFactory.Options();
    option.inScaled = false;
    //

    Bitmap backgroudImage = getMapBitmap(option);
    createOverlayView(backgroudImage.getWidth(), backgroudImage.getHeight(), backgroudImage);
    setImageHandler();
    DimageView.setHandler(handler);
    DimageView.setDmetric(getDispaymetric());
    DimageView.setImageBitmap(backgroudImage);
    arr_button_menu = new Button[8];

    measureCheckBox = (CheckBox) findViewById(R.id.activity_work_mapping_drawer_check_measure);
    measureCheckBox.setOnCheckedChangeListener(checkboxListener);
    measureCheckBox.setTag(1);
    measureCheckBox.setChecked(true);
    poiCheckBox = (CheckBox) findViewById(R.id.activity_work_mapping_drawer_check_poi);
    poiCheckBox.setOnCheckedChangeListener(checkboxListener);
    poiCheckBox.setTag(2);
    poiCheckBox.setChecked(true);
    wayCheckBox = (CheckBox) findViewById(R.id.activity_work_mapping_drawer_check_way);
    wayCheckBox.setOnCheckedChangeListener(checkboxListener);
    wayCheckBox.setTag(3);
    wayCheckBox.setChecked(true);
    UpdateButton = (Button) findViewById(R.id.activity_work_mapping_drawer_button_update);
    UpdateButton.setOnClickListener(l);

    createPOIInputDialog();
    createMeasureDialog();
    setInputHandler();

    init();
  }
コード例 #13
0
 private Bitmap getThumbnail(long id) {
   Bitmap bitmap = null;
   BitmapFactory.Options options = new BitmapFactory.Options();
   options.inDither = false;
   options.inPreferredConfig = Bitmap.Config.ARGB_8888;
   options.inScaled = true;
   options.inJustDecodeBounds = false;
   options.inPurgeable = true;
   options.inInputShareable = true;
   ContentResolver cr = mContext.getContentResolver();
   bitmap = MediaStore.Video.Thumbnails.getThumbnail(cr, id, Images.Thumbnails.MINI_KIND, null);
   return bitmap;
 }
コード例 #14
0
  private int loadTexture(String path) {
    String fullPath = "gfx";
    fullPath += path;
    Bitmap bitmap = null;
    try { // Get reference to AssetManager

      AssetManager mngr = _context.getAssets();
      // Create an input stream to read from the asset folder
      InputStream ins = mngr.open(fullPath);
      // Convert the input stream into a bitmap
      bitmap = BitmapFactory.decodeStream(ins);
    } catch (final IOException e) {
      e.printStackTrace();
      Toast.makeText(_context, "couldn't set image to background", Toast.LENGTH_LONG).show();
    }

    int h = firstBigger2power((float) bitmap.getHeight() / Utils.scaleFactrWidth);
    int w = firstBigger2power((float) bitmap.getWidth() / Utils.scaleFactrWidth);

    final int[] textureHandle = new int[1];

    GLES20.glGenTextures(1, textureHandle, 0);

    if (textureHandle[0] != 0) {
      final BitmapFactory.Options options = new BitmapFactory.Options();
      options.inScaled = false; // No pre-scaling

      // Read in the resource
      // Bind to the texture in OpenGL
      GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, textureHandle[0]);

      // Set filtering
      GLES20.glTexParameteri(GLES20.GL_TEXTURE_2D, GLES20.GL_TEXTURE_MIN_FILTER, GLES20.GL_NEAREST);
      GLES20.glTexParameteri(GLES20.GL_TEXTURE_2D, GLES20.GL_TEXTURE_MAG_FILTER, GLES20.GL_NEAREST);

      // Load the bitmap into the bound texture.
      GLUtils.texImage2D(GLES20.GL_TEXTURE_2D, 0, Bitmap.createScaledBitmap(bitmap, w, h, true), 0);

      // Recycle the bitmap, since its data has been loaded into OpenGL.
      bitmap.recycle();
    }

    if (textureHandle[0] == 0) {
      throw new RuntimeException("Error loading texture.");
    }

    return textureHandle[0];
  }
コード例 #15
0
ファイル: ImageUtility.java プロジェクト: PotatoFa/OneWeek
  public static Bitmap decodeSampledBitmapFromPath(String path, int reqWidth, int reqHeight) {
    final BitmapFactory.Options options = new BitmapFactory.Options();
    options.inJustDecodeBounds = true;
    options.inMutable = true;
    options.inBitmap = BitmapFactory.decodeFile(path, options);

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

    options.inScaled = true;
    options.inDensity = options.outWidth;
    options.inTargetDensity = reqWidth * options.inSampleSize;

    options.inJustDecodeBounds = false;
    options.inPurgeable = true;
    options.inInputShareable = true;

    return BitmapFactory.decodeFile(path, options);
  }
コード例 #16
0
ファイル: Scene.java プロジェクト: hazardland/game.android
  /**
   * We are using decode only in scene.load() which is run in independent thread decode method
   * prepares images for main thread in bitmaps array resource_id => decoded image bitmap and waits
   * until onDrawFrame method binds them (in main thread) --- Why images are decoded in load thread
   * and bind in onDrawFrame method ? because onDrawFrame has gl instance and load thread does not
   *
   * <p>As we are not in main thread we wait as much as onDrawFrame requires to bind previous image
   * Also we could add next decoded image as soon as possible but it is not good to hold onDrawFrame
   * longer because next frames are waiting to be drawn
   *
   * @param resource specify android drawable resource id
   */
  public void decode(int resource) {
    debug("decoding " + resource);
    while (bitmaps.size() > 1) {
      sleep(25);
    }
    BitmapFactory.Options options = new BitmapFactory.Options();
    options.inScaled = false;
    InputStream input = null;

    try {
      input = resources.openRawResource(resource);
    } catch (Resources.NotFoundException error) {
      System.out.println("image: resource not found " + resource);
    }

    if (input == null) {
      fail();
    }

    try {
      bitmaps.put(resource, BitmapFactory.decodeStream(input, null, options));
      System.out.println("image: decoded image " + resource);
    } catch (NullPointerException pointer) {
      System.out.println("image: failed to decode image " + resource);
      fail();
    } catch (OutOfMemoryError error) {
      System.out.println("image: out of memory while decoding image " + resource);
      fail();
    } finally {
      // System.out.println ("image: unknown error while decoding image "+resource);
      try {
        input.close();
      } catch (IOException e) {
        System.out.println("image: io error while closing image stream " + resource);
      }
      // fail ();
    }

    System.out.println("image: textures left to load " + bitmaps.size());

    if (world != null) {
      world.loaded(2);
    }
  }
コード例 #17
0
ファイル: ImageHelper.java プロジェクト: bagavi/Saarang2013
 /**
  * Load a bitmap from InputStream and catch OutOfMemoryErrors.
  *
  * @param in InputStream containing the bitmap
  * @return Bitmap from InputStream, or 'null' in case of errors
  */
 public static Bitmap loadImage(InputStream in) {
   System.gc();
   if (in == null) {
     return null;
   }
   try {
     BitmapFactory.Options bitmapOptions = new BitmapFactory.Options();
     bitmapOptions.inScaled = false;
     bitmapOptions.inTargetDensity = 0;
     bitmapOptions.inPurgeable = true;
     bitmapOptions.inInputShareable = true;
     bitmapOptions.inPreferredConfig = Bitmap.Config.RGB_565;
     return BitmapFactory.decodeStream(in, null, bitmapOptions);
   } catch (OutOfMemoryError err) {
     Log.w(LOG_TAG, "Out of memory loading map image", err);
     System.gc();
   }
   return null;
 }
コード例 #18
0
ファイル: ImageUtility.java プロジェクト: PotatoFa/OneWeek
  /** Decode and sample down a bitmap from a byte stream */
  public static Bitmap decodeSampledBitmapFromByte(Context context, byte[] bitmapBytes) {
    Display display =
        ((WindowManager) context.getSystemService(Context.WINDOW_SERVICE)).getDefaultDisplay();

    int reqWidth, reqHeight;
    Point point = new Point();

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB_MR2) {
      display.getSize(point);
      reqWidth = point.x;
      reqHeight = point.y;
    } else {
      reqWidth = display.getWidth();
      reqHeight = display.getHeight();
    }

    final BitmapFactory.Options options = new BitmapFactory.Options();
    options.inJustDecodeBounds = true;
    options.inMutable = true;
    options.inBitmap = BitmapFactory.decodeByteArray(bitmapBytes, 0, bitmapBytes.length, options);

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

    // Load & resize the image to be 1/inSampleSize dimensions
    // Use when you do not want to scale the image with a inSampleSize that is a power of 2
    options.inScaled = true;
    options.inDensity = options.outWidth;
    options.inTargetDensity = reqWidth * options.inSampleSize;

    // Decode bitmap with inSampleSize set
    options.inJustDecodeBounds =
        false; // If set to true, the decoder will return null (no bitmap), but the out... fields
               // will still be set, allowing the caller to query the bitmap without having to
               // allocate the memory for its pixels.
    options.inPurgeable =
        true; // Tell to gc that whether it needs free memory, the Bitmap can be cleared
    options.inInputShareable =
        true; // Which kind of reference will be used to recover the Bitmap data after being clear,
              // when it will be used in the future

    return BitmapFactory.decodeByteArray(bitmapBytes, 0, bitmapBytes.length, options);
  }
コード例 #19
0
  /**
   * Print an image
   *
   * @param image String (BASE64 encoded image)
   * @param width
   * @param height
   * @param align
   */
  public void printImage(String image, int width, int height, int align) {
    try {
      BitmapFactory.Options options = new BitmapFactory.Options();
      options.inScaled = false;
      byte[] decodedByte = Base64.decode(image, 0);
      Bitmap bitmap = BitmapFactory.decodeByteArray(decodedByte, 0, decodedByte.length);
      final int imgWidth = bitmap.getWidth();
      final int imgHeight = bitmap.getHeight();
      final int[] argb = new int[imgWidth * imgHeight];

      bitmap.getPixels(argb, 0, imgWidth, 0, 0, imgWidth, imgHeight);
      bitmap.recycle();

      mPrinter.printImage(argb, width, height, align, true);
      mPrinter.flush();
      mCallbackContext.success();
    } catch (Exception e) {
      mCallbackContext.error(this.getErrorByCode(11, e));
    }
  }
コード例 #20
0
ファイル: TextureUtil.java プロジェクト: AnberZhou/exp3d
 public static int loadMipMappedTexture(int file) {
   InputStream is = Resource.getResInputStream(file);
   Bitmap bitmap = null;
   try {
     // Log.d(TAG, "ETC1 Support: " + ETC1Util.isETC1Supported());
     BitmapFactory.Options opts = new BitmapFactory.Options();
     opts.inScaled = false;
     // opts.inPreferredConfig = Bitmap.Config.RGB_565;
     bitmap = BitmapFactory.decodeStream(is, null, opts); // decodeStream(is, opts);
     return loadMipMappedTexture(bitmap);
   } catch (Exception e) {
     Log.e(TAG, "Could not read texture file " + file, e);
     return 0;
   } finally {
     try {
       is.close();
     } catch (Exception e) {
       Log.e(TAG, "Error closing stream", e);
     }
   }
 }
コード例 #21
0
  public SpriteFactory(MapView mapView) {
    mMapView = mapView;
    DisplayMetrics realMetrics = null;
    DisplayMetrics metrics = new DisplayMetrics();
    WindowManager wm =
        (WindowManager) mMapView.getContext().getSystemService(Context.WINDOW_SERVICE);

    if (android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {
      realMetrics = new DisplayMetrics();
      wm.getDefaultDisplay().getRealMetrics(realMetrics);
    }
    wm.getDefaultDisplay().getMetrics(metrics);

    mOptions = new BitmapFactory.Options();
    mOptions.inScaled = true;
    mOptions.inDensity = DisplayMetrics.DENSITY_DEFAULT;
    mOptions.inTargetDensity = metrics.densityDpi;
    if (realMetrics != null) {
      mOptions.inScreenDensity = realMetrics.densityDpi;
    }
  }
コード例 #22
0
  private boolean addTile() throws Exception {
    /* Set the options */
    BitmapFactory.Options options = new BitmapFactory.Options();
    options.inScaled = false;
    options.inPreferredConfig = Bitmap.Config.ARGB_8888;
    Bitmap tileIcon =
        BitmapFactory.decodeResource(
            getBaseContext().getResources(), R.raw.tile_icon_large, options);
    Bitmap badgeIcon =
        BitmapFactory.decodeResource(
            getBaseContext().getResources(), R.raw.tile_icon_small, options);

    BandTile tile =
        new BandTile.Builder(tileId, "MessageTile", tileIcon).setTileSmallIcon(badgeIcon).build();
    appendToUI("Message Tile is adding ...\n");
    if (client.getTileManager().addTile(this, tile).await()) {
      appendToUI("Message Tile is added.\n");
      return true;
    } else {
      appendToUI("Unable to add message tile to the band.\n");
      return false;
    }
  }
コード例 #23
0
ファイル: TextureUtil.java プロジェクト: AnberZhou/exp3d
  public static boolean loadTexture(int glId, String filePath) {

    InputStream is = Resource.getResInputStream(filePath);
    if (is == null) return false;
    Bitmap bitmap = null;
    try {
      BitmapFactory.Options opts = new BitmapFactory.Options();
      opts.inScaled = false;
      // opts.inPreferredConfig = Bitmap.Config.RGB_565;
      bitmap = BitmapFactory.decodeStream(is, null, opts);
    } catch (Exception e) {
      Log.e(TAG, "Could not read texture file " + filePath, e);
      return false;
    } finally {
      try {
        is.close();
      } catch (Exception e) {
        Log.e(TAG, "Error closing stream", e);
      }
    }

    return loadTexture(glId, bitmap);
  }
コード例 #24
0
 public LookupFilter(Context context, int id) {
   super(2);
   final BitmapFactory.Options options = new BitmapFactory.Options();
   options.inScaled = false;
   lookupBitmap = BitmapFactory.decodeResource(context.getResources(), id, options);
 }
コード例 #25
0
ファイル: FallRS.java プロジェクト: richardxu/panda-a4
  public FallRS(int width, int height) {
    super(width, height);

    mOptionsARGB.inScaled = false;
    mOptionsARGB.inPreferredConfig = Bitmap.Config.ARGB_8888;
  }
コード例 #26
0
 private Bitmap decodeBmp(int drawable) {
   BitmapFactory.Options options = new BitmapFactory.Options();
   options.inPreferredConfig = Bitmap.Config.ALPHA_8;
   options.inScaled = true;
   return BitmapFactory.decodeResource(getResources(), drawable, options);
 }
コード例 #27
0
  @Override
  public void onCreate() {
    // TODO Auto-generated method stub
    super.onCreate();
    CONTEXT = this.getApplicationContext();
    AM = this.getAssets();

    try {
      PLACEHOLDERBMP = BitmapFactory.decodeStream(AM.open("transparent.png"));
    } catch (IOException e) {
      e.printStackTrace();
    }

    WPM = WallpaperManager.getInstance(this);
    PREFS = PreferenceManager.getDefaultSharedPreferences(OMWPP.CONTEXT);

    BMPQUERYOPTIONS = new BitmapFactory.Options();
    BMPQUERYOPTIONS.inJustDecodeBounds = true;

    BMPVALIDOPTIONS = new BitmapFactory.Options();
    BMPVALIDOPTIONS.inSampleSize = 4;

    BMPAPPLYOPTIONS = new BitmapFactory.Options();
    BMPAPPLYOPTIONS.inSampleSize = 1;
    BMPAPPLYOPTIONS.inScaled = false;
    BMPAPPLYOPTIONS.inDither = false;
    BMPAPPLYOPTIONS.inPreferredConfig = Config.ARGB_8888;

    // Initialize the four queues.
    THUMBNAILQUEUE = new ConcurrentLinkedQueue<File>();
    DOWNLOADQUEUE = new ArrayBlockingQueue<URL>(20, false);
    UNZIPQUEUE = new ArrayBlockingQueue<File>(20, false);

    SCREENWIDTH = getResources().getDisplayMetrics().widthPixels;
    SCREENHEIGHT = getResources().getDisplayMetrics().heightPixels;

    WPWIDTH = WPM.getDesiredMinimumWidth();
    WPHEIGHT = WPM.getDesiredMinimumHeight();
    if (WPWIDTH < SCREENWIDTH * 2) WPWIDTH = SCREENWIDTH * 2;
    if (WPHEIGHT < SCREENHEIGHT) WPHEIGHT = SCREENHEIGHT;
    if (OMWPP.DEBUG) Log.i("OMWPPApp", "Target Width is" + WPWIDTH);
    if (OMWPP.DEBUG) Log.i("OMWPPApp", "Target Height is " + WPHEIGHT);

    try {
      ENDMARKER_URL = new URL("http://localhost");
    } catch (Exception e) {
      e.printStackTrace();
    }

    if (isSDPresent()) {
      // Check and/or create the wallpapers directory.
      SDROOT = new File(Environment.getExternalStorageDirectory().getPath() + "/ubuntuwps/");
      if (OMWPP.DEBUG) Log.i("OMWPPApp", "Checking/Creating " + SDROOT.getAbsoluteFile());
      SDROOT.mkdirs();
      THUMBNAILROOT = getExternalFilesDir(null);
      if (OMWPP.DEBUG) Log.i("OMWPPApp", "Checking/Creating " + THUMBNAILROOT.getAbsoluteFile());
      THUMBNAILROOT.mkdirs();
      File nomedia = new File(THUMBNAILROOT.getAbsolutePath() + "/.nomedia");
      try {
        if (!nomedia.exists()) nomedia.createNewFile();
      } catch (Exception e) {
        e.printStackTrace();
      }
    }
    // First of all, let's load up the latest configuration JSON file.
    try {
      if (isSDPresent()) {
        if (OMWPP.DEBUG) Log.i("OMWPPApp", "Loading config file from TN folder");
        CONFIGJSON =
            streamToJSONObject(
                new FileInputStream(new File(THUMBNAILROOT.getPath() + "/omwpp_config.json")));
      } else {
        if (OMWPP.DEBUG) Log.i("OMWPPApp", "No config file in TN folder");
        throw new Exception();
      }
    } catch (Exception e) {
      try {
        if (OMWPP.DEBUG) Log.i("OMWPPApp", "Copying default files to Wallpaper folder");
        copyAssetToFile("omwpp_config.json", THUMBNAILROOT.getPath() + "/omwpp_config.json");
        CONFIGJSON =
            streamToJSONObject(
                new FileInputStream(new File(THUMBNAILROOT.getPath() + "/omwpp_config.json")));
        CONFIGJSON.putOpt("localpaths", new JSONArray("[\"" + SDROOT.toString() + "\"]"));
        commitJSONChanges();

        try {
          for (String sFile : OMWPP.AM.list("")) {
            copyAssetToFile(sFile, SDROOT.getPath() + "/" + sFile);
          }
        } catch (Exception ee) {
          ee.printStackTrace();
        }
      } catch (Exception ee) {
        e.printStackTrace();
      }
    }

    // Figure out when we last downloaded a new config file.
    LASTCONFIGREFRESH = OMWPP.PREFS.getLong("LASTCONFIGREFRESH", 0l);
  }
コード例 #28
0
    @SuppressWarnings("NewApi")
    @Override
    public void run() {
      if (src_image == null) {
        if (uri == null) {
          ui_handler.post(
              new Runnable() {
                @Override
                public void run() {
                  if (isFinishing()) return;
                  Toast.makeText(
                          SetWallpaperActivity.this,
                          "missing uri in arguments.",
                          Toast.LENGTH_SHORT)
                      .show();
                }
              });
          return;
        }
        log.d("loading image..");

        // Options for image size check
        BitmapFactory.Options check_option = new BitmapFactory.Options();
        check_option.inJustDecodeBounds = true;
        check_option.inDensity = 0;
        check_option.inTargetDensity = 0;
        check_option.inDensity = 0;
        check_option.inScaled = false;

        // Option for image load
        BitmapFactory.Options load_option = new BitmapFactory.Options();
        load_option.inPurgeable = true;
        load_option.inDensity = 0;
        load_option.inTargetDensity = 0;
        load_option.inDensity = 0;
        load_option.inScaled = false;

        // Color at the time of load depth
        int pixel_bytes;
        check_option.inPreferredConfig = Bitmap.Config.ARGB_8888;
        load_option.inPreferredConfig = Bitmap.Config.ARGB_8888;
        pixel_bytes = 4;

        ContentResolver cr = getContentResolver();
        InputStream is;

        // Examine the image size
        try {
          is = cr.openInputStream(uri);
          try {
            check_option.outHeight = 0;
            check_option.outWidth = 0;
            BitmapFactory.decodeStream(is, null, check_option);
          } finally {
            is.close();
          }
        } catch (Throwable ex) {
          // IOException
          // SecurityException: reading com.android.providers.telephony.MmsProvider
          ex.printStackTrace();
        }
        if (check_option.outWidth < 1 || check_option.outHeight < 1) {
          log.e("load failed.");
          ui_handler.post(
              new Runnable() {
                @Override
                public void run() {
                  if (isFinishing()) return;
                  Toast.makeText(SetWallpaperActivity.this, "load failed.", Toast.LENGTH_SHORT)
                      .show();
                }
              });
          return;
        }

        // To change the sample size, if necessary by examining the amount of data
        int data_size = check_option.outWidth * check_option.outHeight * pixel_bytes; // 面積と色深度
        int limit_size = 1024 * 1024 * 10;
        int samplesize = 1;
        while (data_size / (float) (samplesize * samplesize) >= limit_size) {
          samplesize++;
        }
        load_option.inSampleSize = samplesize;

        // load bitmap
        try {
          is = cr.openInputStream(uri);
          try {
            src_image = BitmapFactory.decodeStream(is, null, load_option);
          } finally {
            is.close();
          }
        } catch (IOException ex) {
          ex.printStackTrace();
        }
        if (src_image == null) {
          log.e("load failed.");
          ui_handler.post(
              new Runnable() {
                @Override
                public void run() {
                  if (isFinishing()) return;
                  Toast.makeText(SetWallpaperActivity.this, "load failed.", Toast.LENGTH_SHORT)
                      .show();
                }
              });
          return;
        }
        int row_bytes = src_image.getRowBytes();
        int pixel_bytes2 = row_bytes / src_image.getWidth();

        originalImageWidth = src_image.getWidth();
        originalImageHeight = src_image.getHeight();

        Point size = new Point();
        WindowManager wm = (WindowManager) getSystemService(Context.WINDOW_SERVICE);
        wm.getDefaultDisplay().getRealSize(size);

        float ratioOriginal = originalImageWidth / originalImageHeight;
        float ratioScreen = (float) (size.x) / (float) (size.y);

        imageDimensionCategory =
            originalImageWidth > originalImageHeight
                ? IMAGE_DIMENSION_HORIZONTAL
                : IMAGE_DIMENSION_VERTICAL;
        if (ratioOriginal > ratioScreen && ratioOriginal < 2 * ratioScreen) {
          imageDimensionCategory = IMAGE_DIMENSION_NOT_STANDARD;
        }
        Log.e("DIMENSION", imageDimensionCategory + "");

        float temp = size.y;
        wall_real_w = opt_display_width;
        float scaleTemp = (temp / originalImageHeight);
        wall_real_h = (int) temp;
        opt_display_width = size.x;
        opt_display_height = size.y;
        //                Log.e("COST", "" + temp + " " + scaleTemp + " " + wall_real_w + " " +
        // wall_real_h);
        Log.e(
            "COST",
            temp
                + " ORIGINAL "
                + originalImageWidth
                + " "
                + originalImageHeight
                + " REAL "
                + wall_real_w
                + " "
                + wall_real_h
                + " SCREEN "
                + opt_display_width
                + " "
                + opt_display_height);

        log.d(
            "wallpaper=%dx%d, display=%dx%d, overriding %dx%d",
            wall_real_w,
            wall_real_h,
            opt_display_width,
            opt_display_height,
            opt_output_width,
            opt_output_height);
        if (wall_real_w <= 0) wall_real_w = opt_display_width;
        if (wall_real_h <= 0) wall_real_h = opt_display_height;
        if (opt_output_width > 0) wall_real_w = opt_output_width;
        if (opt_output_height > 0) wall_real_h = opt_output_height;
        if (wall_real_w <= 0) wall_real_w = 1;
        if (wall_real_h <= 0) wall_real_h = 1;

        wall_w = wall_real_w;
        wall_h = wall_real_h;

        if (wall_w < 1) wall_w = 1;
        if (wall_h < 1) wall_h = 1;

        wall_image_aspect = (float) wall_w / (float) wall_h;

        log.d("wall_image=%dx%d", wall_w, wall_h);

        log.d(
            "original size=%dx%dx%d(%.2fMB), factor=%s,resized=%dx%dx%d(%.2fMB)",
            check_option.outWidth,
            check_option.outHeight,
            pixel_bytes,
            data_size / (float) (1024 * 1024),
            samplesize,
            src_image.getWidth(),
            src_image.getHeight(),
            pixel_bytes2,
            (src_image.getHeight() * row_bytes) / (float) (1024 * 1024));
      }

      // レイアウトが完了するのを待つ
      while (!bCancelled) {
        if (flOuter.getWidth() > 0) break;
        waitEx(100);
      }
      if (bCancelled) return;

      // The size of the display frame
      int frame_w = flOuter.getWidth();
      int frame_h = flOuter.getHeight();
      float frame_aspect = frame_w / (float) frame_h;

      // The size of the data
      int src_w = src_image.getWidth();
      int src_h = src_image.getHeight();
      float src_aspect = src_w / (float) src_h;
      src_rect = new Rect(0, 0, src_w, src_h);

      // The size of the display image
      int shown_w;
      int shown_h;
      if (src_w <= frame_w && src_h <= frame_h) {
        // Scaling unnecessary
        shown_w = src_w;
        shown_h = src_h;
      } else if (src_aspect >= frame_aspect) {
        shown_w = frame_w;
        shown_h = (int) (0.5f + (src_h * frame_w) / (float) src_w);
      } else {
        // Image I fit in portrait. Vertical base than the display frame
        shown_h = frame_h;
        shown_w = (int) (0.5f + (src_w * frame_h) / (float) src_h);
      }

      // Position of the display image (display frame criteria)
      int x, y;
      x = (frame_w - shown_w) / 2;
      y = (frame_h - shown_h) / 2;
      shown_image_rect = new RectF(x, y, x + shown_w, y + shown_h);

      // Generate bitmap for display
      shown_image =
          Bitmap.createBitmap(
              frame_w, frame_h, MyApp.getBitmapConfig(src_image, Bitmap.Config.ARGB_8888));
      paint = new Paint();
      paint.setFilterBitmap(true);
      c = new Canvas(shown_image);
      cFrame = new Canvas(shown_image);
      c.drawBitmap(src_image, src_rect, shown_image_rect, paint);

      // Width and height of the selected range
      int selection_w;
      int selection_h;
      if (src_aspect <= wall_image_aspect) {
        // Image portrait than the ratio of wallpaper. It fits in right and left base
        selection_w = (int) shown_image_rect.width();
        selection_h = (int) (0.5 + selection_w / wall_image_aspect);
      } else {
        // Image is long in the transverse than wallpaper. It fits in the vertical base
        selection_h = (int) shown_image_rect.height();
        selection_w = (int) (0.5 + selection_h * wall_image_aspect);
      }

      x = (frame_w - selection_w) / 2;
      y = (frame_h - selection_h) / 2;
      prev_selection.set(x, y, x + selection_w, y + selection_h);

      ui_handler.post(
          new Runnable() {
            @Override
            public void run() {
              if (bCancelled) return;
              // 画像を表示
              ivImage.setImageDrawable(new BitmapDrawable(getResources(), shown_image));

              // Enable button
              //                    tbOverall.setEnabled(true);
              btnOk.setEnabled(true);
              bLoading = false;
              // Set selection
              setSelection(
                  prev_selection.left,
                  prev_selection.top,
                  prev_selection.width(),
                  prev_selection.height());
            }
          });
    }
コード例 #29
0
  public void ApparelData(Context con, int act) {
    context = con;
    action = act;
    Apparel a = Controller.getInstance().getApparel();
    Log.d("in apparel data", a.getApparel_name());
    values = new ContentValues();
    values.put(ApparelDB.ApparelTable.COLUMN_NAME_APPAREL_NAME, a.getApparel_name());
    values.put(ApparelDB.ApparelTable.COLUMN_NAME_APPAREL_TYPE, a.getApparel_type());
    // values.put(ApparelDB.ApparelTable.COLUMN_NAME_DRAWABLE_ID, a.getDrawable_id());
    BitmapFactory.Options opt = new BitmapFactory.Options();
    opt.inScaled = true;
    opt.inMutable = true;

    /*if(a.getBlob_img_apparel()== null) {

        Bitmap imageBitmap1= BitmapFactory.decodeResource(context.getResources(),
                context.getResources().getIdentifier(a.getDrawable_id(), "drawable", context.getPackageName()), opt);
        ByteArrayOutputStream bos1 = new ByteArrayOutputStream();
        imageBitmap1.compress(Bitmap.CompressFormat.PNG, 100, bos1);
        byte[] bArray1 = bos1.toByteArray();
        values.put(ApparelDB.ApparelTable.COLUMN_NAME_APPAREL_IMG, bArray1);
    }
    else
    {
        values.put(ApparelDB.ApparelTable.COLUMN_NAME_APPAREL_IMG,a.getBlob_img_apparel());
    }

    if(a.getBlob_img_all_pieces()== null) {

        Bitmap imageBitmap2 = BitmapFactory.decodeResource(context.getResources(),
                context.getResources().getIdentifier(a.getPieces_Drawable_id(), "drawable", context.getPackageName()), opt);
        ByteArrayOutputStream bos2 = new ByteArrayOutputStream();
        imageBitmap2.compress(Bitmap.CompressFormat.PNG, 100, bos2);
        byte[] bArray2 = bos2.toByteArray();
        values.put(ApparelDB.ApparelTable.COLUMN_NAME_ALL_PIECES_IMG, bArray2);
    }
    else
    {
        values.put(ApparelDB.ApparelTable.COLUMN_NAME_ALL_PIECES_IMG,a.getBlob_img_all_pieces());
    }*/
    values.put(ApparelDB.ApparelTable.COLUMN_NAME_APPAREL_IMG, a.getBlob_img_apparel());
    values.put(ApparelDB.ApparelTable.COLUMN_NAME_ALL_PIECES_IMG, a.getBlob_img_all_pieces());
    values.put(ApparelDB.ApparelTable.COLUMN_NAME_BOLT_WIDTH, a.getBolt_Width());
    values.put(ApparelDB.ApparelTable.COLUMN_NAME_LENGTH, a.getLength());
    values.put(ApparelDB.ApparelTable.COLUMN_NAME_NUM_PIECES, a.getNum_pieces());

    Log.d("in apparel data", String.valueOf(a.getNum_pieces()));
    JSONArray jsonPatternTexts;
    JSONArray jsonPieces = new JSONArray();
    JSONObject jsonPIObject, jsonPTObject;

    for (int i = 0; i < a.getNum_pieces(); i++) {
      Log.d("in apparel loop", String.valueOf(i));
      Piece piece = a.getPieces().get(i);
      try {

        jsonPIObject = new JSONObject();
        jsonPIObject.put("piece_shape", piece.getPiece_shape());
        jsonPIObject.put("piece_fold", piece.getPiece_fold());
        jsonPIObject.put("piece_height", piece.getPiece_height());
        jsonPIObject.put("piece_width", piece.getPiece_width());
        jsonPIObject.put("piece_info", piece.getPiece_info());
        jsonPIObject.put("piece_image_id", piece.getPiece_image_id());

        Bitmap image =
            BitmapFactory.decodeResource(
                context.getResources(),
                context
                    .getResources()
                    .getIdentifier(
                        a.getPieces().get(i).getPiece_image_id(),
                        "drawable",
                        context.getPackageName()),
                opt);
        Log.d("apparel db image id", a.pieces.get(i).getPiece_image_id());
        ByteArrayOutputStream bos1 = new ByteArrayOutputStream();
        image.compress(Bitmap.CompressFormat.PNG, 100, bos1);
        byte[] bArray = bos1.toByteArray();

        String jsonString = Base64.encodeToString(bArray, Base64.DEFAULT);
        jsonPIObject.put("piece_image_blob", jsonString);

        Log.d("LOG", " json str" + jsonString.toString());
        jsonPatternTexts = new JSONArray();
        for (int k = 0; k < piece.getPatternTexts().size(); k++) {
          PatternText pt = piece.getPatternTexts().get(k);
          jsonPTObject = new JSONObject();

          jsonPTObject.put("r", pt.getR());
          jsonPTObject.put("angle", pt.getAngle());
          jsonPTObject.put("x", pt.getX());
          jsonPTObject.put("y", pt.getY());

          jsonPatternTexts.put(jsonPTObject);
          Log.d("jsonPTObject", jsonPTObject.toString());
          Log.d("jsonPatterntexts array", jsonPatternTexts.toString());
        }

        jsonPIObject.put("pattern_texts", jsonPatternTexts);
        jsonPieces.put(jsonPIObject);
        Log.d("jsonPIObject", jsonPIObject.toString());
        Log.d("json Pieces", jsonPieces.toString());

      } catch (JSONException e) {
        e.printStackTrace();
      }
    }

    values.put(ApparelDB.ApparelTable.COLUMN_NAME_PIECES, jsonPieces.toString());

    ConfirmDialog(context, printContentValues(values));
  }
コード例 #30
0
 private Bitmap getDrawable(int resId) {
   BitmapFactory.Options options = new BitmapFactory.Options();
   options.inScaled = false;
   return BitmapUtils.decodeResource(getContext(), resId, options);
 }