【问题标题】:Android - Cut bitmap starting from some pointAndroid - 从某个点开始剪切位图
【发布时间】:2014-09-03 06:22:10
【问题描述】:

我一直在这里搜索有关 android 中剪切位图的信息,但是我无法让它为我工作。 我想切断一个特定位图的某些部分,但我想从图像的中心到底部开始。

我已经试过了:

createBitmap(android.graphics.Bitmap source, int x, int y, int width, int height)

但是,它总是开始从顶部剪切我的图像,甚至更改 x 和 y 值。 我想将我的位图切割为蓝色方块下方。

有人知道如何剪切我的位图吗?

【问题讨论】:

    标签: android bitmap


    【解决方案1】:

    你应该看看这个:

    private Bitmap cropBitmap1()
    {
       Bitmap bmp2 = BitmapFactory.decodeResource(this.getResources(), R.drawable.image1); 
       Bitmap bmOverlay = Bitmap.createBitmap(320, 480, Bitmap.Config.ARGB_8888);
    
       Paint p = new Paint();
       p.setXfermode(new PorterDuffXfermode(Mode.CLEAR));              
       Canvas c = new Canvas(bmOverlay); 
       c.drawBitmap(bmp2, 0, 0, null); 
       c.drawRect(30, 30, 100, 100, p);
    
    return bmOverlay;
    }
    

    链接:Source

    【讨论】:

      【解决方案2】:

      试试这个:

      Bitmap source = BitmapFactory.decodeResource(getResources(),
                  R.drawable.ic_launcher);
          int width = source.getWidth();
          int height = source.getHeight();
          int required = 25;// 25 pixels width and height
          int startX = (width - required) / 2;
          int startY = (height - required) / 2;
          Bitmap resized = Bitmap.createBitmap(source, startX, startY, required,
                  required);
      

      唯一相关的部分是 startX 和 startY 计算。代码假设您需要一张 25*25 像素的图片。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2012-07-30
        • 2015-11-23
        • 2013-04-05
        • 1970-01-01
        • 1970-01-01
        • 2013-09-17
        • 2019-01-13
        • 1970-01-01
        相关资源
        最近更新 更多