当前位置: 首页>>代码示例>>Java>>正文


Java CompressFormat类代码示例

本文整理汇总了Java中android.graphics.Bitmap.CompressFormat的典型用法代码示例。如果您正苦于以下问题:Java CompressFormat类的具体用法?Java CompressFormat怎么用?Java CompressFormat使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


CompressFormat类属于android.graphics.Bitmap包,在下文中一共展示了CompressFormat类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: a

import android.graphics.Bitmap.CompressFormat; //导入依赖的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

示例2: onPostExecute

import android.graphics.Bitmap.CompressFormat; //导入依赖的package包/类
protected void onPostExecute(Drawable d) {
    if (d != null) {
        if (imgView != null)
            imgView.setImageDrawable(d);
        BitmapDrawable bd = (BitmapDrawable) d;
        Bitmap bmp = bd.getBitmap();
        ByteArrayOutputStream s = new ByteArrayOutputStream();
        bmp.compress(Bitmap.CompressFormat.JPEG, 100, s);
        if (mFIsThumbnail)
            m_imgThumb = s.toByteArray();
        else
            m_imgData = s.toByteArray();

        if (m_icc != null)
            m_icc.imgCompleted(MFBImageInfo.this);
    }
}
 
开发者ID:ericberman,项目名称:MyFlightbookAndroid,代码行数:18,代码来源:MFBImageInfo.java

示例3: bmpToByteArray

import android.graphics.Bitmap.CompressFormat; //导入依赖的package包/类
public static byte[] bmpToByteArray(final Bitmap bmp, final boolean needRecycle) {
	ByteArrayOutputStream output = new ByteArrayOutputStream();
	bmp.compress(CompressFormat.PNG, 100, output);
	if (needRecycle) {
		bmp.recycle();
	}
	
	byte[] result = output.toByteArray();
	try {
		output.close();
	} catch (Exception e) {
		e.printStackTrace();
	}
	
	return result;
}
 
开发者ID:LingjuAI,项目名称:AssistantBySDK,代码行数:17,代码来源:Util.java

示例4: shareDataToShareParams

import android.graphics.Bitmap.CompressFormat; //导入依赖的package包/类
final ShareParams shareDataToShareParams(Platform plat) {
	if (plat == null || shareParamsMap == null) {
		toast("ssdk_oks_share_failed");
		return null;
	}

	try {
		String imagePath = ResHelper.forceCast(shareParamsMap.get("imagePath"));
		Bitmap viewToShare = ResHelper.forceCast(shareParamsMap.get("viewToShare"));
		if (TextUtils.isEmpty(imagePath) && viewToShare != null && !viewToShare.isRecycled()) {
			String path = ResHelper.getCachePath(plat.getContext(), "screenshot");
			File ss = new File(path, String.valueOf(System.currentTimeMillis()) + ".jpg");
			FileOutputStream fos = new FileOutputStream(ss);
			viewToShare.compress(CompressFormat.JPEG, 100, fos);
			fos.flush();
			fos.close();
			shareParamsMap.put("imagePath", ss.getAbsolutePath());
		}
	} catch (Throwable t) {
		t.printStackTrace();
		toast("ssdk_oks_share_failed");
		return null;
	}

	return new ShareParams(shareParamsMap);
}
 
开发者ID:ittianyu,项目名称:POCenter,代码行数:27,代码来源:OnekeyShareThemeImpl.java

示例5: shareDataToShareParams

import android.graphics.Bitmap.CompressFormat; //导入依赖的package包/类
final ShareParams shareDataToShareParams(Platform plat) {
	if (plat == null || shareParamsMap == null) {
		toast("ssdk_oks_share_failed");
		return null;
	}

	try {
		String imagePath = ResHelper.forceCast(shareParamsMap.get("imagePath"));
		Bitmap viewToShare = ResHelper.forceCast(shareParamsMap.get("viewToShare"));
		if (TextUtils.isEmpty(imagePath) && viewToShare != null && !viewToShare.isRecycled()) {
			String path = ResHelper.getCachePath(MobSDK.getContext(), "screenshot");
			File ss = new File(path, String.valueOf(System.currentTimeMillis()) + ".jpg");
			FileOutputStream fos = new FileOutputStream(ss);
			viewToShare.compress(CompressFormat.JPEG, 100, fos);
			fos.flush();
			fos.close();
			shareParamsMap.put("imagePath", ss.getAbsolutePath());
		}
	} catch (Throwable t) {
		t.printStackTrace();
		toast("ssdk_oks_share_failed");
		return null;
	}

	return new ShareParams(shareParamsMap);
}
 
开发者ID:AndroidBoySC,项目名称:Mybilibili,代码行数:27,代码来源:OnekeyShareThemeImpl.java

示例6: bmpToByteArray

import android.graphics.Bitmap.CompressFormat; //导入依赖的package包/类
/**
    * 将bitmap对象转换成byte数组
    * @param bmp
    * @param needRecycle
    * @return
    */
public static byte[] bmpToByteArray(final Bitmap bmp, final boolean needRecycle) {
	ByteArrayOutputStream output = new ByteArrayOutputStream();
	bmp.compress(CompressFormat.PNG, 100, output);
	if (needRecycle) {
		bmp.recycle();
	}
	
	byte[] result = output.toByteArray();
	try {
		output.close();
	} catch (Exception e) {
		e.printStackTrace();
	}
	
	return result;
}
 
开发者ID:SavorGit,项目名称:Hotspot-master-devp,代码行数:23,代码来源:BitmapCommonUtils.java

示例7: compressByQuality

import android.graphics.Bitmap.CompressFormat; //导入依赖的package包/类
/**
 * 按质量压缩
 *
 * @param src 源图片
 * @param maxByteSize 允许最大值字节数
 * @param recycle 是否回收
 * @return 质量压缩压缩过的图片
 */
public static Bitmap compressByQuality(Bitmap src, long maxByteSize, boolean recycle) {
    if (isEmptyBitmap(src) || maxByteSize <= 0) {
        return null;
    }
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    int quality = 100;
    src.compress(CompressFormat.JPEG, quality, baos);
    while (baos.toByteArray().length > maxByteSize && quality > 0) {
        baos.reset();
        src.compress(CompressFormat.JPEG, quality -= 5, baos);
    }
    if (quality < 0) {
        return null;
    }
    byte[] bytes = baos.toByteArray();
    if (recycle && !src.isRecycled()) {
        src.recycle();
    }
    return BitmapFactory.decodeByteArray(bytes, 0, bytes.length);
}
 
开发者ID:imliujun,项目名称:LJFramework,代码行数:29,代码来源:ImageUtils.java

示例8: saveBitmap

import android.graphics.Bitmap.CompressFormat; //导入依赖的package包/类
/**
 * 将图片保存在指定路径中
 *
 * @param bitmap
 * @param descPath
 */
public static void saveBitmap(Bitmap bitmap, String descPath) {
    File file = new File(descPath);
    if (!file.getParentFile().exists()) {
        file.getParentFile().mkdirs();
    }
    if (!file.exists()) {
        try {
            bitmap.compress(CompressFormat.JPEG, 30, new FileOutputStream(
                                file));
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        }
    }

    if (null != bitmap) {
        bitmap.recycle();
        bitmap = null;
    }
}
 
开发者ID:zqHero,项目名称:rongyunDemo,代码行数:26,代码来源:BitmapUtils.java

示例9: getStreamFromContent

import android.graphics.Bitmap.CompressFormat; //导入依赖的package包/类
/**
 * Retrieves {@link InputStream} of image by URI (image is accessed using {@link ContentResolver}).
 *
 * @param imageUri Image URI
 * @param extra    Auxiliary object which was passed to {@link DisplayImageOptions.Builder#extraForDownloader(Object)
 *                 DisplayImageOptions.extraForDownloader(Object)}; can be null
 * @return {@link InputStream} of image
 * @throws FileNotFoundException if the provided URI could not be opened
 */
protected InputStream getStreamFromContent(String imageUri, Object extra) throws FileNotFoundException {
	ContentResolver res = context.getContentResolver();

	Uri uri = Uri.parse(imageUri);
	if (isVideoContentUri(uri)) { // video thumbnail
		Long origId = Long.valueOf(uri.getLastPathSegment());
		Bitmap bitmap = MediaStore.Video.Thumbnails
				.getThumbnail(res, origId, MediaStore.Images.Thumbnails.MINI_KIND, null);
		if (bitmap != null) {
			ByteArrayOutputStream bos = new ByteArrayOutputStream();
			bitmap.compress(CompressFormat.PNG, 0, bos);
			return new ByteArrayInputStream(bos.toByteArray());
		}
	} else if (imageUri.startsWith(CONTENT_CONTACTS_URI_PREFIX)) { // contacts photo
		return getContactPhotoStream(uri);
	}

	return res.openInputStream(uri);
}
 
开发者ID:Spencer231,项目名称:GifImageLoader,代码行数:29,代码来源:BaseImageDownloader.java

示例10: getScaledImageFileWithMD5

import android.graphics.Bitmap.CompressFormat; //导入依赖的package包/类
public static File getScaledImageFileWithMD5(File imageFile, String mimeType) {
    String filePath = imageFile.getPath();

    if (!isInvalidPictureFile(mimeType)) {
        return null;
    }

    String tempFilePath = getTempFilePath(FileUtil.getExtensionName(filePath));
    File tempImageFile = AttachmentStore.create(tempFilePath);
    if (tempImageFile == null) {
        return null;
    }

    CompressFormat compressFormat = CompressFormat.JPEG;
    // 压缩数值由第三方开发者自行决定
    int maxWidth = 720;
    int quality = 60;

    if (ImageUtil.scaleImage(imageFile, tempImageFile, maxWidth, compressFormat, quality)) {
        return tempImageFile;
    } else {
        return null;
    }
}
 
开发者ID:angcyo,项目名称:RLibrary,代码行数:25,代码来源:ImageUtil.java

示例11: bmpToByteArray

import android.graphics.Bitmap.CompressFormat; //导入依赖的package包/类
public static byte[] bmpToByteArray(final Bitmap bmp, final boolean needRecycle) {
	ByteArrayOutputStream output = new ByteArrayOutputStream();
	bmp.compress(CompressFormat.JPEG, 50, output);
	if (needRecycle) {
		bmp.recycle();
	}
	
	byte[] result = output.toByteArray();
	try {
		output.close();
	} catch (Exception e) {
		e.printStackTrace();
	}
	
	return result;
}
 
开发者ID:junchenChow,项目名称:exciting-app,代码行数:17,代码来源:Util.java

示例12: saveImage

import android.graphics.Bitmap.CompressFormat; //导入依赖的package包/类
public static void saveImage(Context context, String fileName,
                             Bitmap bitmap, int quality) throws IOException {
    if (bitmap == null || fileName == null || context == null)
        return;

    FileOutputStream fos = context.openFileOutput(fileName,
            Context.MODE_PRIVATE);
    ByteArrayOutputStream stream = new ByteArrayOutputStream();
    bitmap.compress(CompressFormat.JPEG, quality, stream);
    byte[] bytes = stream.toByteArray();
    fos.write(bytes);
    fos.close();
}
 
开发者ID:hsj-xiaokang,项目名称:OSchina_resources_android,代码行数:14,代码来源:ImageUtils.java

示例13: a

import android.graphics.Bitmap.CompressFormat; //导入依赖的package包/类
protected static final String a(Bitmap bitmap, String str, String str2) {
    File file = new File(str);
    if (!file.exists()) {
        file.mkdirs();
    }
    String stringBuffer = new StringBuffer(str).append(str2).toString();
    File file2 = new File(stringBuffer);
    if (file2.exists()) {
        file2.delete();
    }
    if (bitmap != null) {
        try {
            OutputStream fileOutputStream = new FileOutputStream(file2);
            bitmap.compress(CompressFormat.JPEG, 80, fileOutputStream);
            fileOutputStream.flush();
            fileOutputStream.close();
            bitmap.recycle();
            return stringBuffer;
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        } catch (IOException e2) {
            e2.printStackTrace();
        }
    }
    return null;
}
 
开发者ID:JackChan1999,项目名称:letv,代码行数:27,代码来源:a.java

示例14: convertBitmapToBytes

import android.graphics.Bitmap.CompressFormat; //导入依赖的package包/类
@TargetApi(Build.VERSION_CODES.ICE_CREAM_SANDWICH)
public static byte[] convertBitmapToBytes(Bitmap bitmap)
{
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH)
    {
        ByteBuffer buffer = ByteBuffer.allocate(bitmap.getByteCount());
        bitmap.copyPixelsToBuffer(buffer);
        return buffer.array();
    }
    else
    {
        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        bitmap.compress(Bitmap.CompressFormat.JPEG, 100, baos);
        byte[] data = baos.toByteArray();
        return data;
    }
}
 
开发者ID:zhuyu1022,项目名称:amap,代码行数:18,代码来源:MIP_BitmapUtils.java

示例15: getScaledImageFileWithMD5

import android.graphics.Bitmap.CompressFormat; //导入依赖的package包/类
public static File getScaledImageFileWithMD5(File imageFile, String mimeType) {
    String filePath = imageFile.getPath();

    if (!isInvalidPictureFile(mimeType)) {
        LogUtil.i("ImageUtil", "is invalid picture file");
        return null;
    }

    String tempFilePath = getTempFilePath(FileUtil.getExtensionName(filePath));
    File tempImageFile = AttachmentStore.create(tempFilePath);
    if (tempImageFile == null) {
        return null;
    }

    CompressFormat compressFormat = CompressFormat.JPEG;
    // 压缩数值由第三方开发者自行决定
    int maxWidth = 720;
    int quality = 60;

    if (ImageUtil.scaleImage(imageFile, tempImageFile, maxWidth, compressFormat, quality)) {
        return tempImageFile;
    } else {
        return null;
    }
}
 
开发者ID:newDeepLearing,项目名称:decoy,代码行数:26,代码来源:ImageUtil.java


注:本文中的android.graphics.Bitmap.CompressFormat类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。