android之豆瓣項目開發(fā)教程源碼圖片處理_第1頁
android之豆瓣項目開發(fā)教程源碼圖片處理_第2頁
android之豆瓣項目開發(fā)教程源碼圖片處理_第3頁
android之豆瓣項目開發(fā)教程源碼圖片處理_第4頁
android之豆瓣項目開發(fā)教程源碼圖片處理_第5頁
已閱讀5頁,還剩14頁未讀, 繼續(xù)免費閱讀

下載本文檔

版權說明:本文檔由用戶提供并上傳,收益歸屬內容提供方,若內容存在侵權,請進行舉報或認領

文檔簡介

Android圖形處理專題Load圖形到內存1.數碼相機照片特別大3m以上,內存吃不消,只顯示原圖的1/8通過BitmapFactory.Options來實現(xiàn)BitmapFactory.OptionsbmpFactoryOptions=newBitmapFactory.Options();bmpFactoryOptions.inSampleSize=8;Bitmapbmp=BitmapFactory.decodeFile(imageFilePath,bmpFactoryOptions);imv.setImageBitmap(bmp);Load圖形到內存2.根據當前屏幕分辨率的大小,加載圖片DisplaycurrentDisplay=getWindowManager().getDefaultDisplay();intdw=currentDisplay.getWidth();intdh=currentDisplay.getHeight();BitmapFactory.OptionsbmpFactoryOptions=newBitmapFactory.Options();bmpFactoryOptions.inJustDecodeBounds=true;Bitmapbmp=BitmapFactory.decodeFile(imageFilePath,bmpFactoryOptions);intheightRatio=(int)Math.ceil(bmpFactoryOptions.outHeight/(float)dh);intwidthRatio=(int)Math.ceil(bmpFactoryOptions.outWidth/(float)dw);Log.v("HEIGHTRATIO",""+heightRatio);Log.v("WIDTHRATIO",""+widthRatio);Load圖形到內存2//判斷是否要進行縮放if(heightRatio>1&&widthRatio>1){if(heightRatio>widthRatio){//高度變化大,按高度縮放bmpFactoryOptions.inSampleSize=heightRatio;}else{//寬度變化大,按寬度縮放bmpFactoryOptions.inSampleSize=widthRatio;}}bmpFactoryOptions.inJustDecodeBounds=false;bmp=BitmapFactory.decodeFile(imageFilePath,bmpFactoryOptions);獲取Exif圖片信息//從文件獲取exif信息ExifInterfaceei=newExifInterface(imageFilePath);StringimageDescription=ei.getAttribute("ImageDescription");if(imageDescription!=null){Log.v("EXIF",imageDescription);}//把exif信息寫到文件:ExifInterfaceei=newExifInterface(imageFilePath);ei.setAttribute("ImageDescription","SomethingNew");從gallery獲取一個圖片Intentintent=newIntent(Intent.ACTION_PICK);intent.setType(“image/*”);intent.getData()獲取image的uriBitmapbmp=BitmapFactory.decodeStream(getContentResolver().openInputStream(imageFileUri),null,bmpFactoryOptions);創(chuàng)建bitmap拷貝Bitmapbmp=BitmapFactory.decodeStream(getContentResolver().openInputStream(imageFileUri),null,bmpFactoryOptions);BitmapalteredBitmap=Bitmap.createBitmap(bmp.getWidth(),bmp.getHeight(),bmp.getConfig());Canvascanvas=newCanvas(alteredBitmap);Paintpaint=newPaint();canvas.drawBitmap(bmp,0,0,paint);圖形縮放Matrixmatrix=newMatrix();matrix.setValues(newfloat[]{ 1,0,0, 0,1,0, 0,0,1});x=1x+0y+0zy=0x+1y+0zz=0x+0y+1z通過canvas.drawBitmap(bmp,matrix,paint);創(chuàng)建bitmap1.水平縮放0.52.垂直拉扯2倍matrix.setScale(1.5f,1);//水平點放大到1.5f,垂直1圖形旋轉Matrixmatrix=newMatrix();matrix.setRotate(15);canvas.drawBitmap(bmp,matrix,paint);消除鋸齒paint.setAntiAlias(true);指定圓心的旋轉matrix.setRotate(15,bmp.getWidth()/2,bmp.getHeight()/2);Matrixmatrix=newMatrix();matrix.setRotate(15,bmp.getWidth()/2,bmp.getHeight()/2);alteredBitmap=Bitmap.createBitmap(bmp,0,0,bmp.getWidth(),bmp.getHeight(),matrix,false);alteredImageView.setImageBitmap(alteredBitmap);圖形平移setTranslate(1.5f,-10);鏡子效果matrix.setScale(-1,1);matrix.postTranslate(bmp.getWidth(),0);倒影效果matrix.setScale(1,-1);matrix.postTranslate(0,bmp.getHeight());圖像顏色處理顏色矩陣ColorMatrixcm=newColorMatrix();paint.setColorFilter(newColorMatrixColorFilter(cm));10000010000010000010NewRedValue=1*128+0*128+0*128+0*0+0NewBlueValue=0*128+1*128+0*128+0*0+0NewGreenValue=0*128+0*128+1*128+0*0+0NewAlphaValue=0*128+0*128+0*128+1*0+0ColorMatrixcm=newColorMatrix();cm.set(newfloat[]{2,0,0,0,0,0,1,0,0,0,0,0,1,0,0,0,0,0,1,0});paint.setColorFilter(newColorMatrixColorFilter(cm));變換圖像的亮度ColorMatrixcm=newColorMatrix();floatcontrast=2;cm.set(newfloat[]{contrast,0,0,0,0,0,contrast,0,0,0,0,0,contrast,0,0,0,0,0,1,0});paint.setColorFilter(newColorMatrixColorFilter(cm));更改圖片飽和度ColorMatrixcm=newColorMatrix();cm.setSaturation(.5f);paint.setColorFilter(newColorMatrixColorFilter(cm));圖片合成BitmapdrawingBitmap=Bitmap.createBitmap(bmp1.getWidth(),bmp1.getHeight(),bmp1.getConfig());canvas=newCanvas(drawingBitmap);paint=newPaint();canvas.drawBitmap(bmp1,0,0,paint);paint.setXfermode(newPorterDuffXfermode(android.graphics.PorterDuff.Mode.MULTIPLY));canvas.drawBitmap(bmp2,0,0,paint);按指定path上繪制文字Paintpaint=newPaint();paint.setColor(Color.GREEN);paint.setTextSize(20);paint.setTypeface(Typeface.DEFAULT);Pathp=newPath();p.moveTo(20,20);p.lineTo(100,150);p.lineTo(200,220);canvas.drawTextOnPath("Hellothisistextonapath",p,0,0,paint);圖片編輯畫畫板人臉識別FaceDetectordetector=newFaceDetector(faceBitmap.getWidth(),faceBitmap.getHeight(),3);//創(chuàng)建識別器mNumFaces

溫馨提示

  • 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
  • 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權益歸上傳用戶所有。
  • 3. 本站RAR壓縮包中若帶圖紙,網頁內容里面會有圖紙預覽,若沒有圖紙預覽就沒有圖紙。
  • 4. 未經權益所有人同意不得將文件中的內容挪作商業(yè)或盈利用途。
  • 5. 人人文庫網僅提供信息存儲空間,僅對用戶上傳內容的表現(xiàn)方式做保護處理,對用戶上傳分享的文檔內容本身不做任何修改或編輯,并不能對任何下載內容負責。
  • 6. 下載文件中如有侵權或不適當內容,請與我們聯(lián)系,我們立即糾正。
  • 7. 本站不保證下載資源的準確性、安全性和完整性, 同時也不承擔用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。

最新文檔

評論

0/150

提交評論