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

Android圖片轉(zhuǎn)換器代碼分享

 更新時間:2015年10月29日 11:58:43   投稿:hebedich  
本文給大家總結(jié)了下在安卓程序中進(jìn)行圖片轉(zhuǎn)換的方法,非常的實用,小伙伴們可以參考下。

MainActivity.java

package com.zhang.showPhoto;
 
import android.app.ActionBar.LayoutParams;
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.animation.AnimationUtils;
import android.widget.Button;
import android.widget.ImageSwitcher;
import android.widget.ImageView;
import android.widget.ViewSwitcher.ViewFactory;
 
public class MainActivity extends Activity {
   
  private int[] imagId=new int[]{
      R.drawable.img01,R.drawable.img02,R.drawable.img03,R.drawable.img04,
      R.drawable.img05,R.drawable.img06,R.drawable.img07,R.drawable.img08,
      R.drawable.img09,R.drawable.img10
    };
  private int index=0;
  private ImageSwitcher imageSwitcher;
  private Button up,down;
   
 
  @Override
  protected void onCreate(Bundle savedInstanceState) {
   
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);
     
    up=(Button) findViewById(R.id.bt1);
    down=(Button) findViewById(R.id.bt2);
     
   
    imageSwitcher=(ImageSwitcher) findViewById(R.id.imagSw1);
    imageSwitcher.setInAnimation(AnimationUtils.loadAnimation(this, android.R.anim.fade_in));
    imageSwitcher.setOutAnimation(AnimationUtils.loadAnimation(this, android.R.anim.fade_out));
    imageSwitcher.setFactory(new ViewFactory() {
       
     
      public View makeView() {
        ImageView imageView = new ImageView(MainActivity.this);
        imageView.setScaleType(ImageView.ScaleType.FIT_CENTER);
        imageView.setLayoutParams(new ImageSwitcher.LayoutParams(
            LayoutParams.WRAP_CONTENT,LayoutParams.WRAP_CONTENT
            ));
        return imageView;
      }
    });
     
    imageSwitcher.setImageResource(imagId[index]);
     
    up.setOnClickListener(new OnClickListener() {
       
      @Override
      public void onClick(View v) {
        if(index>0){
          index--;
        }else{
          index=imagId.length-1;
        }
        imageSwitcher.setImageResource(imagId[index]);
      }
    });
     
    down.setOnClickListener(new OnClickListener() {
       
      @Override
      public void onClick(View v) {
        if(index<imagId.length-1){
          index++;
        }else{
          index=0;
        }
        imageSwitcher.setImageResource(imagId[index]);
      }
    });
   
  }
   
 
}

main.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
  android:background="@drawable/bg1"
  android:id="@+id/llayout"
  android:layout_width="fill_parent"
  android:layout_height="fill_parent"
  android:gravity="center"
  android:orientation="horizontal" >
 
  <Button
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="上一張"
    android:id="@+id/bt1"
    />
  <ImageSwitcher
     android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:id="@+id/imagSw1"
    android:layout_gravity="center"
    />
   <Button
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="下一張"
    android:id="@+id/bt2"
    />
 
</LinearLayout>

再來看一段代碼

    // 獲取圖片的寬高
    BitmapFactory.Options opt = new BitmapFactory.Options();
    opt.inJustDecodeBounds = true;
    try{
      bitmapIn = BitmapFactory.decodeFile(Puzzle.user.CUSTOM_IMAGE[customImage], opt);
    }catch(Exception e){
      if(D) Log.d(TAG,"error");
      return;
    }
    int in_w=opt.outWidth,in_h=opt.outHeight;
     
    // 獲取imageview的尺寸 注意imageview的寬高比要與原圖相同 否則需要另行計算
    full_w = imageview.getWidth()
    full_h = getHeight()
 
    // 計算縮放比例 帶有四舍五入
    int Size_rate=(in_w*in_h*10)/(full_w*full_h);
    if(Size_rate>10){
      Size_rate+=5; 
      Size_rate/=10;
    }else{
      Size_rate=1;
    }
 
    // 重新設(shè)置opt 讀取圖片文件
    opt.inSampleSize=Size_rate;
    opt.inJustDecodeBounds = false;
    opt.inScaled = false;
 
    opt.outWidth=full_w;
    opt.outHeight=full_h;
    bitmapIn = BitmapFactory.decodeFile(Puzzle.user.CUSTOM_IMAGE[customImage], opt);}

相關(guān)文章

  • Spring條件注解@ConditionnalOnClass的原理分析

    Spring條件注解@ConditionnalOnClass的原理分析

    這篇文章主要介紹了Spring條件注解@ConditionnalOnClass的原理分析,所謂@ConditionalOnClass注解,翻譯過來就是基于class的條件,它為所標(biāo)注的類或方法添加限制條件,當(dāng)該條件的值為true時,其所標(biāo)注的類或方法才能生效,需要的朋友可以參考下
    2023-12-12
  • SpringMVC通過攔截器實現(xiàn)IP黑名單

    SpringMVC通過攔截器實現(xiàn)IP黑名單

    這篇文章主要為大家詳細(xì)介紹了SpringMVC通過攔截器實現(xiàn)IP黑名單,具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2019-08-08
  • java中 == 與 equal 的區(qū)別講解

    java中 == 與 equal 的區(qū)別講解

    這篇文章介紹了java中 == 與 equal 的區(qū)別,有需要的朋友可以參考一下
    2013-10-10
  • 使用restTemplate.postForEntity()的問題

    使用restTemplate.postForEntity()的問題

    這篇文章主要介紹了使用restTemplate.postForEntity()的問題,具有很好的參考價值,希望對大家有所幫助,如有錯誤或未考慮完全的地方,望不吝賜教
    2023-09-09
  • Java中@JSONField注解用法、場景與實踐詳解

    Java中@JSONField注解用法、場景與實踐詳解

    這篇文章主要給大家介紹了關(guān)于Java中@JSONField注解用法、場景與實踐的相關(guān)資料,并結(jié)合實際應(yīng)用場景,幫助開發(fā)者在項目中更高效地處理JSON數(shù)據(jù),文中通過代碼介紹的非常詳細(xì),需要的朋友可以參考下
    2024-12-12
  • Java中使用Thread類和Runnable接口實現(xiàn)多線程的區(qū)別

    Java中使用Thread類和Runnable接口實現(xiàn)多線程的區(qū)別

    這篇文章主要介紹了使用Thread類和Runnable接口實現(xiàn)多線程的區(qū)別,本文給大家介紹了兩種實現(xiàn)方式的步驟,除了以上兩種多線程實現(xiàn)方式,還可以使用 Callable 接口實現(xiàn),本文通過實例代碼給大家介紹的非常詳細(xì),需要的朋友可以參考下
    2022-07-07
  • 在Spring框架下配置Quartz集群的詳細(xì)步驟(MySQL數(shù)據(jù)源)

    在Spring框架下配置Quartz集群的詳細(xì)步驟(MySQL數(shù)據(jù)源)

    Quartz 是一個功能強(qiáng)大的調(diào)度庫,可以在 Java 應(yīng)用中用于執(zhí)行定時任務(wù),本文將介紹如何在 Spring 框架下配置 Quartz 集群,并使用 MySQL 作為數(shù)據(jù)源來存儲調(diào)度信息,文中有詳細(xì)的代碼供大家參考,需要的朋友可以參考下
    2025-01-01
  • java類加載機(jī)制、類加載器、自定義類加載器的案例

    java類加載機(jī)制、類加載器、自定義類加載器的案例

    這篇文章主要介紹了java類加載機(jī)制、類加載器、自定義類加載器的案例,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧
    2021-02-02
  • mybatis plus or and 的合并寫法實例

    mybatis plus or and 的合并寫法實例

    這篇文章主要介紹了mybatis plus or and 的合并寫法實例,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧
    2021-02-02
  • 詳解SpringCloud LoadBalancer 新一代負(fù)載均衡器

    詳解SpringCloud LoadBalancer 新一代負(fù)載均衡器

    這篇文章主要為大家介紹了SpringCloud LoadBalancer新一代負(fù)載均衡器詳解使用詳解,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪
    2023-01-01

最新評論

台中市| 旺苍县| 临江市| 菏泽市| 祥云县| 蒲城县| 房产| 缙云县| 吉水县| 湖南省| 湖南省| 佳木斯市| 湘潭县| 同江市| 沾益县| 两当县| 德阳市| 西贡区| 盈江县| 曲阜市| 甘孜县| 新和县| 安泽县| 砀山县| 大洼县| 德安县| 广水市| 泽普县| 依兰县| 武汉市| 柳江县| 龙州县| 隆子县| 九龙县| 鹤壁市| 余江县| 南开区| 湖口县| 揭西县| 周口市| 南开区|