當前位置: 首頁>>代碼示例>>Java>>正文


Java BitmapFactory.decodeByteArray方法代碼示例

本文整理匯總了Java中android.graphics.BitmapFactory.decodeByteArray方法的典型用法代碼示例。如果您正苦於以下問題:Java BitmapFactory.decodeByteArray方法的具體用法?Java BitmapFactory.decodeByteArray怎麽用?Java BitmapFactory.decodeByteArray使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在android.graphics.BitmapFactory的用法示例。


在下文中一共展示了BitmapFactory.decodeByteArray方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: proccessData

import android.graphics.BitmapFactory; //導入方法依賴的package包/類
private byte[] proccessData(byte[] data) {

        SurfaceOverlay overlay = (SurfaceOverlay) findViewById(R.id.overlay);
        int width = overlay.getWidth()/2;
        int indicatorOffset = 200;

        int leftCornerX = width-indicatorOffset;
        int leftCornerY = indicatorOffset;
        int indicatorHeight = width;
        int indicatorWidth = width;

        Bitmap bmp= BitmapFactory.decodeByteArray(data,0,data.length);
        ByteArrayOutputStream stream = new ByteArrayOutputStream();
        Bitmap dst = Bitmap.createBitmap(bmp, leftCornerX, leftCornerY, indicatorWidth, indicatorHeight);
        dst = Bitmap.createScaledBitmap(dst, 28, 28, false);
        dst.compress(Bitmap.CompressFormat.PNG, 100, stream);
        return stream.toByteArray();

    }
 
開發者ID:Guaschman,項目名稱:Graphrec,代碼行數:20,代碼來源:CameraActivity.java

示例2: onPictureTaken

import android.graphics.BitmapFactory; //導入方法依賴的package包/類
@Override
public void onPictureTaken(byte[] data, Camera camera) {
    Log.i(TAG, "Saving a bitmap to file");
    // The camera preview was automatically stopped. Start it again.
    mCamera.startPreview();
    mCamera.setPreviewCallback(this);

    // Write the image in a file (in jpeg format)
    try {
        /*FileOutputStream fos = new FileOutputStream(mPictureFileName);

        fos.write(data);
        fos.close();*/

        Bitmap bmp = BitmapFactory.decodeByteArray(data , 0, data.length);
        Mat orig = new Mat(bmp.getHeight(),bmp.getWidth(),CvType.CV_8UC3);
        Bitmap myBitmap32 = bmp.copy(Bitmap.Config.ARGB_8888, true);
        Utils.bitmapToMat(myBitmap32, orig);
        mImage = new Mat();
        Imgproc.cvtColor(orig,mImage,Imgproc.COLOR_RGB2GRAY);
        /*Imgproc.cvtColor(orig, orig, Imgproc.COLOR_BGR2RGB,4);
        Mat frame = new Mat(mFrameHeight+mFrameHeight/2,mFrameWidth, CvType.CV_8UC1);
        frame.put(0,0,data);
        //Imgcodecs.imdecode(frame,0);
        Imgproc.cvtColor(frame,mImage,Imgproc.COLOR_YUV2RGBA_NV21);//frame.submat(0, mFrameHeight, 0, mFrameWidth);*/

    } catch (Exception e) {
        Log.e("PictureDemo", "Exception in photoCallback", e);
    }

}
 
開發者ID:Sanahm,項目名稱:SudoCAM-Ku,代碼行數:32,代碼來源:CameraView.java

示例3: getPicFromBytes

import android.graphics.BitmapFactory; //導入方法依賴的package包/類
/**
 * @param "將字節數組轉換為ImageView可調用的Bitmap對象"
 * @param bytes
 * @param opts
 * @return Bitmap
 */
public static Bitmap getPicFromBytes(byte[] bytes,
                                     BitmapFactory.Options opts) {
    if (bytes != null)
        if (opts != null)
            return BitmapFactory.decodeByteArray(bytes, 0, bytes.length,
                                                 opts);
        else
            return BitmapFactory.decodeByteArray(bytes, 0, bytes.length);
    return null;
}
 
開發者ID:zqHero,項目名稱:rongyunDemo,代碼行數:17,代碼來源:BitmapUtils.java

示例4: testBytes

import android.graphics.BitmapFactory; //導入方法依賴的package包/類
private void testBytes() {
    try {
        final InputStream is = getResources().getAssets()
                .open("test-3.jpg");

        long fileSize = is.available();

        ByteArrayOutputStream os = new ByteArrayOutputStream();
        byte[] buffer = new byte[4096];
        int len = -1;
        while ((len = is.read(buffer)) != -1) {
            os.write(buffer, 0, len);
        }
        os.close();
        is.close();
        byte[] bitmapBytes = os.toByteArray();

        final BitmapFactory.Options options = new BitmapFactory.Options();
        options.inPreferredConfig = mConfig;
        Bitmap originBitmap = BitmapFactory.decodeByteArray(bitmapBytes, 0, bitmapBytes.length, options);

        setupOriginInfo(originBitmap, fileSize);

        Tiny.FileCompressOptions compressOptions = new Tiny.FileCompressOptions();
        compressOptions.config = mConfig;
        Tiny.getInstance().source(bitmapBytes).asFile().withOptions(compressOptions).compress(new FileCallback() {
            @Override
            public void callback(boolean isSuccess, String outfile) {
                if (!isSuccess) {
                    mCompressTv.setText("compress file failed!");
                    return;
                }
                File file = new File(outfile);
                setupCompressInfo(outfile, file.length());
            }
        });
    } catch (Exception e) {
        e.printStackTrace();
    }
}
 
開發者ID:tangqipeng,項目名稱:tiny,代碼行數:41,代碼來源:FileCompressTestActivity.java

示例5: Bytes2Bimap

import android.graphics.BitmapFactory; //導入方法依賴的package包/類
/**
 * byte[] → Bitmap
 */
private static Bitmap Bytes2Bimap(byte[] b) {
    if (b.length == 0) {
        return null;
    }
    return BitmapFactory.decodeByteArray(b, 0, b.length);
}
 
開發者ID:Jusenr,項目名稱:androidtools,代碼行數:10,代碼來源:DiskFileCacheHelper.java

示例6: createBitMap

import android.graphics.BitmapFactory; //導入方法依賴的package包/類
public Bitmap createBitMap() {
    if( this.imageBitmap == null ){
        if( this.imageData == null ) return null;
        byte[] data = Base64.decode( this.imageData, Base64.DEFAULT);
        this.imageBitmap = BitmapFactory.decodeByteArray( data, 0, data.length);
    }
    return this.imageBitmap;
}
 
開發者ID:tec-ustp,項目名稱:SIIEScanner,代碼行數:9,代碼來源:Header.java

示例7: onPictureTaken

import android.graphics.BitmapFactory; //導入方法依賴的package包/類
@Override
public void onPictureTaken(CameraView cameraView, final byte[] data) {
    Log.d(TAG, "onPictureTaken " + data.length);
    Bitmap bitmap = null;
    if (data != null) {
        bitmap = BitmapFactory.decodeByteArray(data, 0, data.length);//data是字節數據,將其解析成類圖
    }
    //保存圖片到sdcard
    if (bitmap != null) {
        if (rectPictureSize == null) {
            rectPictureSize = DisplayUtils.createCenterPictureRect(ratio, cameraRatio, bitmap.getWidth(), bitmap.getHeight());
        }
        int x = bitmap.getWidth() / 2 - rectPictureSize.x / 2;
        int y = bitmap.getHeight() / 2 - rectPictureSize.y / 2;
        Bitmap rectBitmap = Bitmap.createBitmap(bitmap, x, y, rectPictureSize.x, rectPictureSize.y);
        int imageWidth = rectBitmap.getWidth();
        int imageHeight = rectBitmap.getHeight();
        FileUtils.saveBitmap(rectBitmap,imagePath);
        setResultUri(imageUri,imageWidth,imageHeight);

        if (bitmap.isRecycled()) {
            bitmap.recycle();
        }
        if (rectBitmap.isRecycled()) {
            rectBitmap.recycle();
        }

        finish();

    }
}
 
開發者ID:fengzhizi715,項目名稱:Tess-TwoDemo,代碼行數:32,代碼來源:CameraActivity.java

示例8: decodeMuilt

import android.graphics.BitmapFactory; //導入方法依賴的package包/類
/**
 *
 * @param options
 * @param data
 * @param path
 * @param uri
 * @param resource
 * @return
 */
public static Bitmap decodeMuilt(BitmapFactory.Options options , byte[] data , String path , Uri uri , int resource) {
    try {

        if(!checkByteArray(data) && TextUtils.isEmpty(path) && uri == null && resource <= 0) {
            return null;
        }

        if(checkByteArray(data)) {
            return BitmapFactory.decodeByteArray(data, 0, data.length);
        }

        if (uri != null){
            InputStream inputStream = MainApp.getContext().getContentResolver().openInputStream(uri);
            Bitmap localBitmap = BitmapFactory.decodeStream(inputStream,null, options);
            inputStream.close();
            return localBitmap;
        }

        if(resource > 0) {
            return BitmapFactory.decodeResource(MainApp.getContext().getResources(), resource);
        }
        return BitmapFactory.decodeFile(path);
    } catch (Exception e) {
        e.printStackTrace();
    }
    return null;
}
 
開發者ID:NewCasino,項目名稱:browser,代碼行數:37,代碼來源:HelpUtils.java

示例9: decode

import android.graphics.BitmapFactory; //導入方法依賴的package包/類
private static PendingInstallShortcutInfo decode(String encoded, Context context) {
    try {
        JSONObject object = (JSONObject) new JSONTokener(encoded).nextValue();
        Intent launcherIntent = Intent.parseUri(object.getString(LAUNCH_INTENT_KEY), 0);

        if (object.optBoolean(APP_SHORTCUT_TYPE_KEY)) {
            // The is an internal launcher target shortcut.
            UserHandleCompat user = UserManagerCompat.getInstance(context)
                    .getUserForSerialNumber(object.getLong(USER_HANDLE_KEY));
            if (user == null) {
                return null;
            }

            LauncherActivityInfoCompat info = LauncherAppsCompat.getInstance(context)
                    .resolveActivity(launcherIntent, user);
            return info == null ? null : new PendingInstallShortcutInfo(info, context);
        }

        Intent data = new Intent();
        data.putExtra(Intent.EXTRA_SHORTCUT_INTENT, launcherIntent);
        data.putExtra(Intent.EXTRA_SHORTCUT_NAME, object.getString(NAME_KEY));

        String iconBase64 = object.optString(ICON_KEY);
        String iconResourceName = object.optString(ICON_RESOURCE_NAME_KEY);
        String iconResourcePackageName = object.optString(ICON_RESOURCE_PACKAGE_NAME_KEY);
        if (iconBase64 != null && !iconBase64.isEmpty()) {
            byte[] iconArray = Base64.decode(iconBase64, Base64.DEFAULT);
            Bitmap b = BitmapFactory.decodeByteArray(iconArray, 0, iconArray.length);
            data.putExtra(Intent.EXTRA_SHORTCUT_ICON, b);
        } else if (iconResourceName != null && !iconResourceName.isEmpty()) {
            Intent.ShortcutIconResource iconResource =
                new Intent.ShortcutIconResource();
            iconResource.resourceName = iconResourceName;
            iconResource.packageName = iconResourcePackageName;
            data.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE, iconResource);
        }

        return new PendingInstallShortcutInfo(data, context);
    } catch (JSONException | URISyntaxException e) {
        Log.d(TAG, "Exception reading shortcut to add: " + e);
    }
    return null;
}
 
開發者ID:michelelacorte,項目名稱:FlickLauncher,代碼行數:44,代碼來源:InstallShortcutReceiver.java

示例10: bytes2Bitmap

import android.graphics.BitmapFactory; //導入方法依賴的package包/類
/**
 * byte[]轉換成Bitmap
 *
 * @param bytes
 * @return
 */
public static Bitmap bytes2Bitmap(byte[] bytes) {
    if (bytes.length != 0) {
        return BitmapFactory.decodeByteArray(bytes, 0, bytes.length);
    }
    return null;
}
 
開發者ID:liying2008,項目名稱:Simpler,代碼行數:13,代碼來源:DrawableUtil.java

示例11: createBitMap

import android.graphics.BitmapFactory; //導入方法依賴的package包/類
public Bitmap createBitMap(Context context) {
    if( this.bitmap == null ){
        this.photoData = loadPhotoData( context );
        if( this.photoData == null ) return null;
        byte [ ] data = Base64.decode( this.photoData, Base64.DEFAULT);
        this.bitmap = BitmapFactory.decodeByteArray( data, 0, data.length);
    }
    return this.bitmap;
}
 
開發者ID:tec-ustp,項目名稱:SIIEScanner,代碼行數:10,代碼來源:User.java

示例12: decodeImage

import android.graphics.BitmapFactory; //導入方法依賴的package包/類
public static Bitmap decodeImage(String imageString) {
    try {
        byte[] encodeByte = Base64.decode(imageString, Base64.DEFAULT);
        Bitmap bitmap = BitmapFactory.decodeByteArray(encodeByte, 0, encodeByte.length);
        return bitmap;
    } catch (Exception e) {
        e.getMessage();
        return null;
    }
}
 
開發者ID:CMPUT301W17T08,項目名稱:Moodr,代碼行數:11,代碼來源:AddMoodActivity.java

示例13: checkForImageDataURL

import android.graphics.BitmapFactory; //導入方法依賴的package包/類
private Bitmap checkForImageDataURL(String url) {
	if (!url.startsWith("data:"))
		return null;
	if (url.length() < 14)
		return null;

	int comma = url.indexOf(',');
	if (comma == -1 || comma < 12)
		return null;
	if (!";base64".equals(url.substring(comma - 7, comma)))
		return null;
	byte[] imageData = Base64.decode(url.substring(comma + 1),
			Base64.DEFAULT);
	return BitmapFactory.decodeByteArray(imageData, 0, imageData.length);
}
 
開發者ID:mkulesh,項目名稱:microMathematics,代碼行數:16,代碼來源:SVGAndroidRenderer.java

示例14: compressByQuality

import android.graphics.BitmapFactory; //導入方法依賴的package包/類
/**
 * 按質量壓縮
 *
 * @param src 源圖片
 * @param quality 質量
 * @param recycle 是否回收
 * @return 質量壓縮後的圖片
 */
public static Bitmap compressByQuality(Bitmap src, @IntRange(from = 0, to = 100) int quality, boolean recycle) {
    if (isEmptyBitmap(src)) {
        return null;
    }
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    src.compress(Bitmap.CompressFormat.JPEG, quality, baos);
    byte[] bytes = baos.toByteArray();
    if (recycle && !src.isRecycled()) {
        src.recycle();
    }
    return BitmapFactory.decodeByteArray(bytes, 0, bytes.length);
}
 
開發者ID:imliujun,項目名稱:LJFramework,代碼行數:21,代碼來源:ImageUtils.java

示例15: Bytes2Bimap

import android.graphics.BitmapFactory; //導入方法依賴的package包/類
private static Bitmap Bytes2Bimap(byte[] b) {
	if (b.length == 0) {
		return null;
	}
	return BitmapFactory.decodeByteArray(b, 0, b.length);
}
 
開發者ID:newDeepLearing,項目名稱:decoy,代碼行數:7,代碼來源:ACache.java


注:本文中的android.graphics.BitmapFactory.decodeByteArray方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。