本文整理匯總了Java中android.graphics.Bitmap.Config.ARGB_8888屬性的典型用法代碼示例。如果您正苦於以下問題:Java Config.ARGB_8888屬性的具體用法?Java Config.ARGB_8888怎麽用?Java Config.ARGB_8888使用的例子?那麽, 這裏精選的屬性代碼示例或許可以為您提供幫助。您也可以進一步了解該屬性所在類android.graphics.Bitmap.Config
的用法示例。
在下文中一共展示了Config.ARGB_8888屬性的8個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: writePixel
/**
* The reverse function of {@link #readPixel(DataInput)}
*
* @param src the bitmap
* @param dst the sink
* @throws IOException
*/
public static void writePixel(@Nullable Bitmap src, DataOutput dst) throws IOException {
if (src != null && src.getConfig() != Config.ARGB_8888) {
throw new Panic("only bitmaps of the type ARGB_8888 are supported");
}
dst.writeBoolean(src != null);
if (src == null) {
return;
}
dst.writeInt(src.getWidth());
dst.writeInt(src.getHeight());
int bytes = src.getWidth() * src.getHeight() * 4;
dst.writeByte(src.getConfig().ordinal());
synchronized (BitmapPoolFactory.class) {
if (sTmp.capacity() < bytes) {
sTmp = ByteBuffer.allocate(bytes);
}
sTmp.clear();
sTmp.limit(bytes);
src.copyPixelsToBuffer(sTmp);
dst.write(sTmp.array(), 0, bytes);
}
}
示例2: getBitmapFromNative
private static Bitmap getBitmapFromNative(Bitmap bitmap) {
int width = nativeGetBitmapWidth();
int height = nativeGetBitmapHeight();
if (bitmap == null || width != bitmap.getWidth()
|| height != bitmap.getHeight() || !bitmap.isMutable()) { // in
Config config = Config.ARGB_8888;
if (bitmap != null) {
config = bitmap.getConfig();
bitmap.recycle();
}
bitmap = Bitmap.createBitmap(width, height, config);
}
int[] pixels = new int[width];
for (int y = 0; y < height; y++) {
nativeGetBitmapRow(y, pixels);
bitmap.setPixels(pixels, 0, width, 0, y, width, 1);
}
return bitmap;
}
示例3: getBytesPerPixel
/**
* Return the byte usage per pixel of a bitmap based on its configuration.
* @param config The bitmap configuration.
* @return The byte usage per pixel.
*/
private static int getBytesPerPixel(Config config) {
if (config == Config.ARGB_8888) {
return 4;
} else if (config == Config.RGB_565) {
return 2;
} else if (config == Config.ARGB_4444) {
return 2;
} else if (config == Config.ALPHA_8) {
return 1;
}
return 1;
}
示例4: compressImageByPixel
/**
* 按比例縮小圖片的像素以達到壓縮的目的
* @author JPH
* @param imgPath
* @return
* @date 2014-12-5下午11:30:59
*/
private void compressImageByPixel(String imgPath,CompressListener listener) throws FileNotFoundException {
if(imgPath==null){
sendMsg(false,imgPath,"要壓縮的文件不存在",listener);
return;
}
BitmapFactory.Options newOpts = new BitmapFactory.Options();
newOpts.inJustDecodeBounds = true;//隻讀邊,不讀內容
BitmapFactory.decodeFile(imgPath, newOpts);
newOpts.inJustDecodeBounds = false;
int width = newOpts.outWidth;
int height = newOpts.outHeight;
float maxSize =config.getMaxPixel();
int be = 1;
if (width >= height && width > maxSize) {//縮放比,用高或者寬其中較大的一個數據進行計算
be = (int) (newOpts.outWidth / maxSize);
be++;
} else if (width < height && height > maxSize) {
be = (int) (newOpts.outHeight / maxSize);
be++;
}
newOpts.inSampleSize =be;//設置采樣率
newOpts.inPreferredConfig = Config.ARGB_8888;//該模式是默認的,可不設
newOpts.inPurgeable = true;// 同時設置才會有效
newOpts.inInputShareable = true;//。當係統內存不夠時候圖片自動被回收
Bitmap bitmap = BitmapFactory.decodeFile(imgPath, newOpts);
if (config.isEnableQualityCompress()){
compressImageByQuality(bitmap,imgPath,listener);//壓縮好比例大小後再進行質量壓縮
}else {
File thumbnailFile=getThumbnailFile(new File(imgPath));
bitmap.compress(Bitmap.CompressFormat.JPEG,100,new FileOutputStream(thumbnailFile));
listener.onCompressSuccess(thumbnailFile.getPath());
}
}
示例5: getBytesPerPixel
/**
* Return the byte usage per pixel of a bitmap based on its configuration.
*
* @param config
* The bitmap configuration.
* @return The byte usage per pixel.
*/
private static int getBytesPerPixel(Config config) {
if (config == Config.ARGB_8888) {
return 4;
} else if (config == Config.RGB_565) {
return 2;
} else if (config == Config.ARGB_4444) {
return 2;
} else if (config == Config.ALPHA_8) {
return 1;
}
return 1;
}
示例6: playAnimatedLogo
/**
* Starts playing the given animated GIF logo.
*/
public void playAnimatedLogo(BaseGifImage gifImage) {
mLoadingView.hideLoadingUI();
mAnimatedLogoDrawable = new BaseGifDrawable(gifImage, Config.ARGB_8888);
mAnimatedLogoMatrix = new Matrix();
setMatrix(mAnimatedLogoDrawable.getIntrinsicWidth(),
mAnimatedLogoDrawable.getIntrinsicHeight(), mAnimatedLogoMatrix, false);
// Set callback here to ensure #invalidateDrawable() is called.
mAnimatedLogoDrawable.setCallback(this);
mAnimatedLogoDrawable.start();
}
示例7: getBitmap
/**
* Get bitmap from specified image path
*
* @param imgPath
* @return
*/
public static Bitmap getBitmap(String imgPath) {
// Get bitmap through image path
BitmapFactory.Options newOpts = new BitmapFactory.Options();
newOpts.inJustDecodeBounds = false;
newOpts.inPurgeable = true;
newOpts.inInputShareable = true;
// Do not compress
newOpts.inSampleSize = 1;
newOpts.inPreferredConfig = Config.ARGB_8888;
return BitmapFactory.decodeFile(imgPath, newOpts);
}
示例8: loadScaleFile2
public static Bitmap loadScaleFile2(String filename) {
// return loadFromFile(filename);
BitmapFactory.Options newOpts = new BitmapFactory.Options();
// 開始讀入圖片,此時把options.inJustDecodeBounds 設回true了
newOpts.inJustDecodeBounds = true;
Bitmap bitmap = BitmapFactory.decodeFile(filename, newOpts);// 此時返回bm為空
newOpts.inJustDecodeBounds = false;
int w = newOpts.outWidth;
int h = newOpts.outHeight;
float hh = MainApp.getInstance().getScreenHeight();
float ww = MainApp.getInstance().getScreenWidth();
if (w > h) {
hh = MainApp.getInstance().getScreenWidth();//
ww = MainApp.getInstance().getScreenHeight();//
}
if (w <= ww || h <= hh) {
return bitmap;
}
int be = 1;
if (w > h && w > ww) {
be = (int) (newOpts.outWidth / ww);
} else if (w < h && h > hh) {
be = (int) (newOpts.outHeight / hh);
}
if (be <= 0) {
be = 1;
}
newOpts.inSampleSize = be;// 設置采樣率
newOpts.inPreferredConfig = Config.ARGB_8888;// 該模式是默認的,可不設
newOpts.inPurgeable = true;// 同時設置才會有效
newOpts.inInputShareable = true;// 。當係統內存不夠時候圖片自動被回收
// newOpts.inSampleSize = calculateInSampleSize(newOpts, 480, 800);
bitmap = BitmapFactory.decodeFile(filename, newOpts);
return scaleBitmap(bitmap, ww, hh);
// */
}