/** @Method: packData @Description: ���Ҫ���͵���� */
  private void packData() {

    currentBitmap = BitmapList[firstView];
    ByteArrayOutputStream stream1 = new ByteArrayOutputStream(); // stream1
    currentBitmap.compress(
        Bitmap.CompressFormat.PNG, 1, stream1); // compress to which format you want
    byte[] byte_arr = stream1.toByteArray(); // stream1 to byte
    try {
      stream1.close();
      stream1 = null;
    } catch (IOException e1) {
      e1.printStackTrace();
    }
    String image_str = Base64.encodeBytes(byte_arr); // byte to string

    Bitmap smallcurrentBitmap;
    float wRatio = (float) (currentBitmap.getWidth() / 100.0);
    float hRatio = (float) (currentBitmap.getHeight() / 100.0);
    if (wRatio > 1 && hRatio > 1) // ����ָ����С������С��Ӧ�ı���
    {
      float scaleTemp;
      if (wRatio > hRatio) scaleTemp = hRatio;
      else scaleTemp = wRatio;
      wRatio = currentBitmap.getWidth() / scaleTemp;
      hRatio = currentBitmap.getHeight() / scaleTemp;
      int h = (int) wRatio;
      int w = (int) hRatio;
      smallcurrentBitmap = Bitmap.createScaledBitmap(currentBitmap, h, w, false);
    } else smallcurrentBitmap = currentBitmap;

    ByteArrayOutputStream stream2 = new ByteArrayOutputStream(); // stream2
    smallcurrentBitmap.compress(
        Bitmap.CompressFormat.PNG, 50, stream2); // compress to which format you want
    smallcurrentBitmap.recycle();
    byte_arr = stream2.toByteArray(); // stream2 to byte
    try {
      stream2.close();
      stream2 = null;

    } catch (IOException e) {
      e.printStackTrace();
    }
    String smallimage_str = Base64.encodeBytes(byte_arr); // byte to string

    nameValuePairs.add(new BasicNameValuePair("protocol", "upload")); // ��װ��ֵ��
    nameValuePairs.add(new BasicNameValuePair("id", LoginActivity.mineID));
    nameValuePairs.add(new BasicNameValuePair("albumName", choosedAlbum));
    nameValuePairs.add(
        new BasicNameValuePair(
            "imageName", PhotoAlbumActivity.AlbumsFloderName.get(AlbumName).get(currentNum)));
    Log.d("debug", PhotoAlbumActivity.AlbumsFloderName.get(AlbumName).get(currentNum));
    nameValuePairs.add(new BasicNameValuePair("image", image_str));
    nameValuePairs.add(new BasicNameValuePair("smallImage", smallimage_str));

    System.gc();
  }
Beispiel #2
0
    public byte[] getTileImageData(int x, int y, int zoom) {
      mStream.reset();

      Matrix matrix = new Matrix(mBaseMatrix);
      float scale = (float) (Math.pow(2, zoom) * mScale);
      matrix.postScale(scale, scale);
      matrix.postTranslate(-x * mDimension, -y * mDimension);

      mBitmap.eraseColor(Color.TRANSPARENT);
      Canvas c = new Canvas(mBitmap);
      c.setMatrix(matrix);

      // NOTE: Picture is not thread-safe.
      synchronized (mSvgPicture) {
        mSvgPicture.draw(c);
      }

      BufferedOutputStream stream = new BufferedOutputStream(mStream);
      mBitmap.compress(Bitmap.CompressFormat.PNG, 0, stream);
      try {
        stream.close();
      } catch (IOException e) {
        Log.e(TAG, "Error while closing tile byte stream.");
        e.printStackTrace();
      }
      return mStream.toByteArray();
    }
 public byte[] compressBitmapToBytes(String filePath, int reqWidth, int reqHeight, int quality) {
   Bitmap bitmap = getSmallBitmap(filePath, reqWidth, reqHeight);
   ByteArrayOutputStream baos = new ByteArrayOutputStream();
   bitmap.compress(Bitmap.CompressFormat.JPEG, quality, baos);
   byte[] bytes = baos.toByteArray();
   bitmap.recycle();
   Log.i(TAG, "Bitmap compressed success, size: " + bytes.length);
   return bytes;
 }
Beispiel #4
0
  public static void saveBitmapToFile(Bitmap bmp, String fileName, CompressFormat format) {
    try {
      File f = new File(fileName);
      f.createNewFile();
      FileOutputStream fOut = null;
      fOut = new FileOutputStream(f);
      bmp.compress(format, 100, fOut);
      fOut.flush();
      fOut.close();
    } catch (Exception e) {

    }
  }
 public static boolean saveBitmap(Bitmap bitmap, File file) {
   if (bitmap == null) return false;
   FileOutputStream fos = null;
   try {
     fos = new FileOutputStream(file);
     bitmap.compress(Bitmap.CompressFormat.PNG, 100, fos);
     fos.flush();
     return true;
   } catch (Exception e) {
     e.printStackTrace();
   } finally {
     if (fos != null) {
       try {
         fos.close();
       } catch (IOException e) {
         e.printStackTrace();
       }
     }
   }
   return false;
 }
 /** convert Bitmap to byte array */
 public static byte[] bitmapToByte(Bitmap b) {
   ByteArrayOutputStream o = new ByteArrayOutputStream();
   b.compress(Bitmap.CompressFormat.PNG, 100, o);
   return o.toByteArray();
 }
	public Uri saveImageUri(Context context, Bitmap bitmap) {
		ByteArrayOutputStream bytes = new ByteArrayOutputStream();
		bitmap.compress(Bitmap.CompressFormat.PNG, 100, bytes);
		String path = MediaStore.Images.Media.insertImage(context.getContentResolver(), bitmap, "ImageTitle", null);
		return Uri.parse(path);
	}