如何从ARGB_8888位图绘制位图 [英] How to draw Bitmap from ARGB_8888 Bitmap

查看:599
本文介绍了如何从ARGB_8888位图绘制位图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我画在画布上的路径和创建透明位图,同时节省和创造的透明位图裁剪位图。

I am drawing paths on canvas and creating Transparent bitmap while saving and creating cropping bitmap from transparent bitmap.

请参阅图片:

See Images :

在此我的法师,我根据运行startx,lowestY和highestX,highestY画在画布上的路径和我创建透明位图和

In this I mage I am drawing path on canvas and I am creating transparent bitmap and according to startX,lowestY and highestX,highestY

Bitmap cropBitmap =Bitmap.createBitmap(sourceBitmap,startX,lowestY,highestX,highestY);

当我裁剪位图我想只有测试引作物bitmap.But它给空位图。像这样

When I am cropping Bitmap I want Only "Test" drawing crop bitmap.But it's giving empty bitmap. Like this

里面的红色框我想从透明位图裁剪位图不管我在画布上画画。

Inside red box I want cropped bitmap from transparent bitmap whatever I draw on canvas.

推荐答案

您不能简单地创建一个透明位图,并承担,无论是位图的范围内已经成为它意味着像素是相同的一部分。有两个问题与假设,数字1,透明位图将没有帮助,因为透明度作为通过位图,其中仅将具有α值,数2看到的,被吸入的路径的数据,具有对没有关联您的位图数据,最初创建位图没有颜色的,但它是完全透明的。

You cannot simply create a transparent bitmap, and assume that whatever is within the bounds of the bitmap has become a part of it meaning that the pixels are identical. There are two problems with your assumption, number 1, a transparent bitmap won't help because transparency serves as a see through bitmap which only will have alpha value, number 2, the data that is drawn with the path, has no correlation to the data of your bitmap, you initially created a bitmap with no color, except that it's completely transparent.

下面是一般code为正确的方式如何实现这样的任务:

Here's the general code for the correct way how to achieve such a task:

 class myDrawingView extends View() {
      // all your class members you initialize here
      @Override
      public void onDraw(Canvas canvas) {
          // get your width and height using startx, starty, highestx, highesty, lowesty
          Bitmap buffer = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
          canvas.setBitmap(buffer);
          canvas.drawPath(//draw your path here);
          invalidate();

      }

位图缓存叫,现在是所有的图纸,因此您可以绘制路径,这将在您定义的缓冲渲染的帧缓冲区。你可以看到,没有透明度,我们使用的只是简单的创建,没有在第一次分配给它的像素的位图,一旦你通过画布绘制到它,你的位图的像素将是你画什么的。

The Bitmap called buffer, now is the frame buffer for all your drawing so you can draw a path and that will be rendered on the buffer you defined. And you see that no transparency was used we just simply created a bitmap with no pixels assigned to it at first, once you draw to it via the canvas, your bitmaps pixels will be whatever you drew.

这篇关于如何从ARGB_8888位图绘制位图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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