最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

Android中幾種圖片特效的處理的實(shí)現(xiàn)方法

 更新時(shí)間:2017年08月04日 11:51:39   投稿:lqh  
這篇文章主要介紹了 Android中幾種圖片特效的處理的實(shí)現(xiàn)方法的相關(guān)資料,這里有放大縮小圖片,獲得圓角圖片,獲得帶倒影圖片的幾種方法,需要的朋友可以參考下

 Android中幾種圖片特效的處理

這里有放大縮小圖片,獲得圓角圖片,獲得帶倒影圖片的幾種方法及實(shí)現(xiàn)代碼,

package com.android.tutor; 
import android.graphics.Bitmap; 
import android.graphics.Canvas; 
import android.graphics.LinearGradient; 
import android.graphics.Matrix; 
import android.graphics.Paint; 
import android.graphics.PixelFormat; 
import android.graphics.PorterDuffXfermode; 
import android.graphics.Rect; 
import android.graphics.RectF; 
import android.graphics.Bitmap.Config; 
import android.graphics.PorterDuff.Mode; 
import android.graphics.Shader.TileMode; 
import android.graphics.drawable.Drawable; 
public class ImageUtil { 
   
  //放大縮小圖片 
  public static Bitmap zoomBitmap(Bitmap bitmap,int w,int h){ 
    int width = bitmap.getWidth(); 
    int height = bitmap.getHeight(); 
    Matrix matrix = new Matrix(); 
    float scaleWidht = ((float)w / width); 
    float scaleHeight = ((float)h / height); 
    matrix.postScale(scaleWidht, scaleHeight); 
    Bitmap newbmp = Bitmap.createBitmap(bitmap, 0, 0, width, height, matrix, true); 
    return newbmp; 
  } 
  //將Drawable轉(zhuǎn)化為Bitmap 
   public static Bitmap drawableToBitmap(Drawable drawable){ 
      int width = drawable.getIntrinsicWidth(); 
      int height = drawable.getIntrinsicHeight(); 
      Bitmap bitmap = Bitmap.createBitmap(width, height, 
          drawable.getOpacity() != PixelFormat.OPAQUE ? Bitmap.Config.ARGB_8888 
              : Bitmap.Config.RGB_565); 
      Canvas canvas = new Canvas(bitmap); 
      drawable.setBounds(0,0,width,height); 
      drawable.draw(canvas); 
      return bitmap; 
       
    } 
    
   //獲得圓角圖片的方法 
  public static Bitmap getRoundedCornerBitmap(Bitmap bitmap,float roundPx){ 
     
    Bitmap output = Bitmap.createBitmap(bitmap.getWidth(), bitmap 
        .getHeight(), Config.ARGB_8888); 
    Canvas canvas = new Canvas(output); 
  
    final int color = 0xff424242; 
    final Paint paint = new Paint(); 
    final Rect rect = new Rect(0, 0, bitmap.getWidth(), bitmap.getHeight()); 
    final RectF rectF = new RectF(rect); 
  
    paint.setAntiAlias(true); 
    canvas.drawARGB(0, 0, 0, 0); 
    paint.setColor(color); 
    canvas.drawRoundRect(rectF, roundPx, roundPx, paint); 
  
    paint.setXfermode(new PorterDuffXfermode(Mode.SRC_IN)); 
    canvas.drawBitmap(bitmap, rect, rect, paint); 
  
    return output; 
  } 
  //獲得帶倒影的圖片方法 
  public static Bitmap createReflectionImageWithOrigin(Bitmap bitmap){ 
    final int reflectionGap = 4; 
    int width = bitmap.getWidth(); 
    int height = bitmap.getHeight(); 
     
    Matrix matrix = new Matrix(); 
    matrix.preScale(1, -1); 
     
    Bitmap reflectionImage = Bitmap.createBitmap(bitmap,  
        0, height/2, width, height/2, matrix, false); 
     
    Bitmap bitmapWithReflection = Bitmap.createBitmap(width, (height + height/2), Config.ARGB_8888); 
     
    Canvas canvas = new Canvas(bitmapWithReflection); 
    canvas.drawBitmap(bitmap, 0, 0, null); 
    Paint deafalutPaint = new Paint(); 
    canvas.drawRect(0, height,width,height + reflectionGap, 
        deafalutPaint); 
     
    canvas.drawBitmap(reflectionImage, 0, height + reflectionGap, null); 
     
    Paint paint = new Paint(); 
    LinearGradient shader = new LinearGradient(0, 
        bitmap.getHeight(), 0, bitmapWithReflection.getHeight() 
        + reflectionGap, 0x70ffffff, 0x00ffffff, TileMode.CLAMP); 
    paint.setShader(shader); 
    // Set the Transfer mode to be porter duff and destination in 
    paint.setXfermode(new PorterDuffXfermode(Mode.DST_IN)); 
    // Draw a rectangle using the paint with our linear gradient 
    canvas.drawRect(0, height, width, bitmapWithReflection.getHeight() 
        + reflectionGap, paint); 
  
    return bitmapWithReflection; 
  } 
   
} 

修改main.xml布局文件,主要放了兩個(gè)ImageView控件,代碼如下:

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
  android:orientation="vertical" 
  android:layout_width="fill_parent" 
  android:layout_height="fill_parent" 
  > 
  <ImageView  
    android:id="@+id/image01"  
    android:layout_width="wrap_content"  
    android:layout_height="wrap_content"  
    android:padding="10px" 
    /> 
  <ImageView 
    android:id="@+id/image02" 
    android:layout_width="wrap_content"  
    android:layout_height="wrap_content"  
    android:padding="10px" 
  /> 
</LinearLayout> 

修改主核心程序,ImageDemo.Java,代碼如下:

package com.android.tutor; 
import android.app.Activity; 
import android.graphics.Bitmap; 
import android.graphics.drawable.Drawable; 
import android.os.Bundle; 
import android.widget.ImageView; 
public class Imagedemo extends Activity { 
  private ImageView mImageView01,mImageView02; 
   
  public void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.main); 
    setupViews(); 
  } 
   
  private void setupViews(){ 
    mImageView01 = (ImageView)findViewById(R.id.image01); 
    mImageView02 = (ImageView)findViewById(R.id.image02); 
     
    //獲取壁紙返回值是Drawable 
    Drawable drawable = getWallpaper(); 
    //將Drawable轉(zhuǎn)化為Bitmap 
    Bitmap bitmap = ImageUtil.drawableToBitmap(drawable); 
    //縮放圖片 
    Bitmap zoomBitmap = ImageUtil.zoomBitmap(bitmap, 100, 100); 
    //獲取圓角圖片 
    Bitmap roundBitmap = ImageUtil.getRoundedCornerBitmap(zoomBitmap, 10.0f); 
    //獲取倒影圖片 
    Bitmap reflectBitmap = ImageUtil.createReflectionImageWithOrigin(zoomBitmap); 
    //這里可以讓Bitmap再轉(zhuǎn)化為Drawable 
//   Drawable roundDrawable = new BitmapDrawable(roundBitmap);     
//   Drawable reflectDrawable = new BitmapDrawable(reflectBitmap);     
//   mImageView01.setBackgroundDrawable(roundDrawable); 
//   mImageView02.setBackgroundDrawable(reflectDrawable); 
         
    mImageView01.setImageBitmap(roundBitmap); 
    mImageView02.setImageBitmap(reflectBitmap); 
  } 
    
     
} 

以上就是Android中幾種圖片特效的方法整理,如有疑問請留言或者到本站社區(qū)交流討論,感謝閱讀,希望能幫助到大家,謝謝大家對本站的支持!

相關(guān)文章

  • Java中的IO讀寫原理詳解

    Java中的IO讀寫原理詳解

    這篇文章主要介紹了Java中的IO讀寫原理,IO是指輸入和輸出操作的技術(shù),它提供了一組用于讀取和寫入數(shù)據(jù)的類,以及用于處理字符和字節(jié)數(shù)據(jù)的接口,這些類和接口可以用于讀取和寫入文件、網(wǎng)絡(luò)流、內(nèi)存緩沖區(qū)等各種數(shù)據(jù)源和目標(biāo),需要的朋友可以參考下
    2023-08-08
  • Mybatis調(diào)用MySQL存儲過程的簡單實(shí)現(xiàn)

    Mybatis調(diào)用MySQL存儲過程的簡單實(shí)現(xiàn)

    本篇文章主要介紹了Mybatis調(diào)用MySQL存儲過程的簡單實(shí)現(xiàn),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下。
    2017-04-04
  • IDEA新建JAVA項(xiàng)目簡單圖文教程

    IDEA新建JAVA項(xiàng)目簡單圖文教程

    這篇文章主要給大家介紹了關(guān)于IDEA新建JAVA項(xiàng)目的相關(guān)資料,IDEA是現(xiàn)在java中最為常用的編譯器,所以如何使用IDEA來創(chuàng)建java項(xiàng)目呢,這里給大家總結(jié)下,需要的朋友可以參考下
    2023-08-08
  • SpringBoot注解梳理(小結(jié))

    SpringBoot注解梳理(小結(jié))

    這篇文章主要介紹了SpringBoot注解梳理(小結(jié)),文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧
    2019-10-10
  • Spring Boot中如何使用Swagger詳解

    Spring Boot中如何使用Swagger詳解

    Swagger是一個(gè)規(guī)范和完整的框架,用于生成、描述、調(diào)用和可視化 RESTful風(fēng)格的Web服務(wù),這篇文章主要給大家介紹了關(guān)于Spring Boot中如何使用Swagger的相關(guān)資料,需要的朋友可以參考下
    2021-08-08
  • java Clone接口和深拷貝詳解

    java Clone接口和深拷貝詳解

    今天小編就為大家分享一篇關(guān)于Java Clonable接口和深拷貝詳解上的深入了解,小編覺得內(nèi)容挺不錯(cuò)的,現(xiàn)在分享給大家,具有很好的參考價(jià)值,需要的朋友一起跟隨小編來看看吧
    2021-08-08
  • Jpa數(shù)據(jù)操作以及@Query和@Modifying注解使用方式

    Jpa數(shù)據(jù)操作以及@Query和@Modifying注解使用方式

    這篇文章主要介紹了Jpa數(shù)據(jù)操作以及@Query和@Modifying注解使用方式,具有很好的參考價(jià)值,希望對大家有所幫助,如有錯(cuò)誤或未考慮完全的地方,望不吝賜教
    2024-07-07
  • Sublime Text 打開Java文檔中文亂碼的解決方案

    Sublime Text 打開Java文檔中文亂碼的解決方案

    這篇文章主要介紹了Sublime Text 中文亂碼的解決方案,幫助大家更好的理解和使用Java,感興趣的朋友可以了解下
    2020-12-12
  • Java中的SpringAOP、代理模式、常用AspectJ注解詳解

    Java中的SpringAOP、代理模式、常用AspectJ注解詳解

    這篇文章主要介紹了Java中的SpringAOP、代理模式、常用AspectJ注解詳解,Spring提供了面向切面編程的豐富支持,允許通過分離應(yīng)用的業(yè)務(wù)邏輯與系統(tǒng)級服務(wù),例如審計(jì)和事務(wù)管理進(jìn)行內(nèi)聚性的開發(fā),需要的朋友可以參考下
    2023-09-09
  • IDEA新手必備之各種快捷鍵詳解

    IDEA新手必備之各種快捷鍵詳解

    這篇文章主要介紹了IDEA新手必備之各種快捷鍵詳解,文中有非常詳細(xì)的快捷鍵介紹,對正在使用IDEA的小伙伴們有非常好的幫助,需要的朋友可以參考下
    2021-04-04

最新評論

包头市| 阿瓦提县| 城市| 山东| 长顺县| 巫溪县| 青海省| 交口县| 云和县| 新野县| 黄梅县| 永宁县| 喜德县| 湖口县| 上虞市| 靖远县| 五寨县| 韶山市| 金溪县| 高青县| 获嘉县| 大新县| 张北县| 云安县| 铁岭市| 巨鹿县| 湘乡市| 长武县| 大埔区| 元谋县| 巢湖市| 静宁县| 龙泉市| 平顶山市| 邹城市| 吕梁市| 长海县| 都江堰市| 长汀县| 出国| 嵊州市|