安卓节省3位图作为1 [英] android saving 3 bitmaps as 1

查看:120
本文介绍了安卓节省3位图作为1的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个应用程序,需要的图片。它创建2子集位图,用失真处理这些位图,然后在原来的重叠放置的子集。有没有一种方法来保存所有三个位图作为一(因为它出现在手机屏幕上)?我想保存用户在屏幕上看到的东西对SD卡的第四位图?我有一种感觉,我这样做是错误的。

感谢

[UPDATE1]

  @覆盖
    公共无效的OnDraw(帆布油画){
        super.onDraw(画布);

        Log.e(TAG,******要绘制BGR);
        canvas.drawBitmap(BGR,0,0,NULL);

        如果(isLocked ==真&功放;&安培; bothCirclesInPlace ==真){
            如果(OVERLAY!= NULL)
             canvas.drawBitmap(叠加,CENTREX半径,centreY半径,NULL);
            如果(overLay2!= NULL)
             canvas.drawBitmap(overLay2,centreA半径,centreB半径,NULL);
        }
 

解决方案

是的,它可以覆盖多个位图,并保存为一个图像文件(PNG / JPEG / ..)。

的一种方法是使用画布类。随着涂料Canvas类定义了位图叠加的方式。

随着code将展示多个位图覆盖到一个单一的图像文件。

 尝试{
        //字符串mFilePath:文件的绝对路径保存

        //位图mBitmap1:第一个位图。这正好为背景。
        //位图mCBitmap:与帆布相关的位图。所有绘制在画布上绘制这个位图。
        //位图mBitmap2:第二位。如此状态下的第一的顶部(在该例子作为前景。

        //涂料mPaint1:油漆绘制第一个位图
        //涂料mPaint2:油漆绘制第二位的第一个位图的顶部

        位图mCBitmap = Bitmap.createBitmap(mBitmap1.getWidth(),mBitmap1.getHeight(),mBitmap1.getConfig());

        帆布的TCanvas =新的Canvas(mCBitmap);

        tCanvas.drawBitmap(mBitmap1,0,0,mPaint1);

        mPaint2.setXfermode(新PorterDuffXfermode(PorterDuff.Mode.DARKEN));
        // XFER模式定义叠加特性

        tCanvas.drawBitmap(mBitmap2,0,0,mPaint2);

        的FileOutputStream流=新的FileOutputStream(mFilePath);
        mCBitmap.com preSS(比较pressFormat.JPEG,100,流);

        stream.flush();
        stream.close();
    }赶上(例外五){
        Log.e(无法保存,e.toString());
}
 

词shash

I've an app that takes a picture. It creates 2 subset bitmaps, processes these bitmaps with a distortion, then places the subsets over the original as overlays. Is there a way to save all three bitmaps as one (as it appears on the phone's screen)? I'd like to save what the user sees on the screen as a fourth bitmap on the sdcard? I've a feeling I've done this wrong.

Thanks

[update1]

@Override
    public void onDraw(Canvas canvas){
        super.onDraw(canvas);

        Log.e(TAG, "******about to draw bgr ");
        canvas.drawBitmap(bgr, 0, 0, null);

        if (isLocked == true && bothCirclesInPlace == true){
            if(overLay != null)
             canvas.drawBitmap(overLay, centreX-radius, centreY-radius, null);
            if(overLay2 != null)
             canvas.drawBitmap(overLay2, centreA-radius, centreB-radius, null);
        }

解决方案

Yes it is possible to overlay multiple bitmaps and save as a single image file (PNG / JPEG / ..).

One way is to use Canvas class. Canvas along with Paint class defines the way in which bitmaps are overlayed.

Following code will demonstrate multiple bitmap overlay into a single image file.

try {
        // String mFilePath  : Absolute Path of the file to be saved 

        // Bitmap mBitmap1   : First bitmap. This goes as background.
        // Bitmap mCBitmap   : Bitmap associated with the Canvas. All draws on the canvas are drawn into this bitmap.
        // Bitmap mBitmap2   : Second bitmap. This goes on top of first (in this example serves as foreground.

        // Paint mPaint1     : Paint to draw first bitmap
        // Paint mPaint2     : Paint to draw second bitmap on top of first bitmap

        Bitmap mCBitmap = Bitmap.createBitmap(mBitmap1.getWidth(), mBitmap1.getHeight(), mBitmap1.getConfig());

        Canvas tCanvas = new Canvas(mCBitmap);

        tCanvas.drawBitmap(mBitmap1, 0, 0, mPaint1);

        mPaint2.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.DARKEN));
        // XFer modes define the overlay characteristic

        tCanvas.drawBitmap(mBitmap2, 0, 0, mPaint2);

        FileOutputStream stream = new FileOutputStream(mFilePath);
        mCBitmap.compress(CompressFormat.JPEG, 100, stream);

        stream.flush();
        stream.close();
    } catch(Exception e) {
        Log.e("Could not save", e.toString());
}

Shash

这篇关于安卓节省3位图作为1的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆