android:layout_width="fill_parent"android:layout_height="wrap_content"androi..._android 把layout转成bitmap放大">
当前位置:   article > 正文

android 画板生成bitmap,Android 在放大Bitmap画布并在Bitmap上绘制矩形

android 把layout转成bitmap放大

首先是显示 ImageView的xml文件

android:orientation="vertical"

android:layout_width="fill_parent"

android:layout_height="fill_parent"

>

android:layout_width="fill_parent"

android:layout_height="wrap_content"

android:text="@string/hello"

/>

android:id="@+id/image"

android:layout_height="wrap_content"

android:layout_width="wrap_content"

android:background="#999999"

>

android:id="@+id/image1"

android:layout_height="wrap_content"

android:layout_width="wrap_content"

android:background="#999999"

>

二:

public class IconActivity extends Activity {

/** Called when the activity is first created. */

@Override

public void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

setContentView(R.layout.main);

ImageView image=(ImageView) this.findViewById(R.id.image);

Bitmap bm=readBitMap(this,R.drawable.test_launcher);

Bitmap delete=readBitMap(this,R.drawable.delete);

image.setImageBitmap(bm);

ImageView image1=(ImageView) this.findViewById(R.id.image1);

Bitmap bm1=createBitmap(bm);

image1.setImageBitmap(createBitmapNew(bm1));

}

public  Bitmap readBitMap(Context context, int resId){

BitmapFactory.Options opt = new BitmapFactory.Options();

opt.inPreferredConfig = Bitmap.Config.RGB_565;

opt.inPurgeable = true;

opt.inInputShareable = true;

//获取资源图片

InputStream is = context.getResources().openRawResource(resId);

return BitmapFactory.decodeStream(is,null,opt);

}

//将画布放大

// private Bitmap createBitmap(Bitmap src, Bitmap watermark )

private Bitmap createBitmap(Bitmap src)

{

if( src == null )

{

return null;

}

int w = src.getWidth();

int h = src.getHeight();

//int ww = watermark.getWidth();

//int wh = watermark.getHeight();

//create the new blank bitmap

Bitmap newb = Bitmap.createBitmap(w*3/2, h*3/2, Config.ARGB_8888 );//创建一个新的和SRC长度宽度一样的位图

Canvas cv = new Canvas(newb );

//draw src into

cv.drawBitmap(src, w/6, h/4, null );//在 0,0坐标开始画入src

//draw watermark into

//cv.drawBitmap( watermark, w - ww + 5, h - wh + 5, null );//在src的右下角画入水印

//save all clip

cv.save( Canvas.ALL_SAVE_FLAG );//保存

//store

cv.restore();//存储

return newb;

}

//在Bitmap 上绘制矩形块

private Bitmap createBitmapNew(Bitmap src)

{

if( src == null )

{

return null;

}

int w = src.getWidth();

int h = src.getHeight();

Paint mPaint = new Paint();

;

Bitmap newb = Bitmap.createBitmap(w, h, Config.ARGB_8888 );//创建一个新的和SRC长度宽度一样的位图

Canvas cv = new Canvas(newb);

//Canvas cv1=

// cv.drawBitmap(src, w/6, h/4, null );//在 0,0坐标开始画入src

mPaint.setColor(Color.GREEN);

cv.drawRect(new Rect(w*2/3, 0,  w, h/2), mPaint);

//draw watermark into

//cv.drawBitmap( watermark, w - ww + 5, h - wh + 5, null );//在src的右下角画入水印

//save all clip

cv.save(Canvas.ALL_SAVE_FLAG );//保存

//store

cv.restore();//存储

return newb;

}     }

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/你好赵伟/article/detail/262118
推荐阅读
相关标签
  

闽ICP备14008679号