使用内置的Gallery应用程序选择图形
使用一個預裝的Intent.Action_Pick通知Android選擇一塊數據。android.provider.MediaStore.Images.EXTERNAL_CONETENT_URI.
Intent choosePictureIntent=new Intent(Intent.ACTION_PICK,android.provider.Mediastore.Images.Media.EXTERNAL_CONTENT_URI);
觸發onActivityResult(int requestCode,int resultCode,Intent intent){
? ?super.onActivityResult(requestCode,resultCode,intent);
? if(resultCode==RESULT_OK){
? ? Uri imageFileUri=intent.getData();
? ?
? ?}
}
3.2 在位圖上繪制位圖
? Bitmap bmp=BitmapFactory.decodeStream(getContentResolver().openInputStream(imageFileUri),null,bmpFactoryOptions);
? Bitmap alteredBitmap=Bitmap.createBitmap(bmp.getWidth(),bmp.getheight(),bmp.getConfig());
? 繪制:
? 1.獲得畫布和Paint對象
? ? ? Canvas canvas=new Canvas(alteredBitmap);
? ? ? Paint paint=new Paint();
? 2.繪制
? ? ? canvas.drawBitmap(bmp,0,0,paint);
3.3.1 輸入矩陣
? ? ? ? Matrix matrix=new Matrix();
? ? ? ? matrix.setValues(new float[]{
? ? ? ? ?1,0,0,
? ? ? ? ?0,1,0,
? ? ? ? ?0,0,1});
? ? ? ?canvas.drawBitmap(bmp,matrix,paint);
3.3.2 Matix類的方法
? ? Mtrix matrix=new Matrix();
? ?matrix.setRotate(15);
? ?canvas.drawBitmap(bmp,matrix,paint);
2.縮放
? ?Matix有用的方法是setscale方法,第一個參數是x軸的縮放比例,第二個參數是y軸的縮放比例
matrix.setScale(1.5f,1);
3.平移
? ?Matrix類中setTranslate方法,平移setTranslate(1.5f,-10);
5.鏡像
matrix.setScale(-1,1);
matrix.postTranslate(bmp.getWidth(),0);
繪圖設置字體
Typeface serif_italic=Typeface.create(Typeface.SERIF,Typeface.ITALIC);
paint.setTypeface(serif_italic);
Typeface chops=Typeface.createFromAsset(getAssets(),"chopinScript.ttf");
paint.setTypeface(chops);
4.路徑上的文本
Paint paint=new Paint();
paint.setColor(Color.Green);
paint.setTextSize(20);
paint.setTypeface(Typeface.DEFAULT);
canvas.drawTextOnPath("Hello this is text on a path",p,0,0,paint);
4.2 手指繪圖
4.2.1 觸摸事件
SimpleFingerDraw extends Activity implements OnTouchListener{
? ?boolean onTouch(View v,MotionEvent event){
? ? ? ? ? int action=event.getAction();
? ? ? ? ? switch(action){
? ? ? ? ? ? ? ? ?case MotionEvent.Action_down:
? ? ? ? ? ? ? ? ? ? ? ? ? downx=evnent.getX();
? ? ? ? ? ? ? ? ? ? ? ? ? downy=event.getY();
? ? ? ? ?}
}
}
總結
以上是生活随笔為你收集整理的使用内置的Gallery应用程序选择图形的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: ExitInterface
- 下一篇: 画布绘图