当前位置: 首页>>代码示例>>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;未经允许,请勿转载。