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

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

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

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>

再來(lái)看一段代碼

    // 獲取圖片的寬高
    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的寬高比要與原圖相同 否則需要另行計(jì)算
    full_w = imageview.getWidth()
    full_h = getHeight()
 
    // 計(jì)算縮放比例 帶有四舍五入
    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注解,翻譯過(guò)來(lái)就是基于class的條件,它為所標(biāo)注的類(lèi)或方法添加限制條件,當(dāng)該條件的值為true時(shí),其所標(biāo)注的類(lèi)或方法才能生效,需要的朋友可以參考下
    2023-12-12
  • SpringMVC通過(guò)攔截器實(shí)現(xiàn)IP黑名單

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

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

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

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

    使用restTemplate.postForEntity()的問(wèn)題

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

    Java中@JSONField注解用法、場(chǎng)景與實(shí)踐詳解

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

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

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

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

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

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

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

    mybatis plus or and 的合并寫(xiě)法實(shí)例

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

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

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

最新評(píng)論

昭平县| 泸溪县| 湛江市| 滦南县| 随州市| 垦利县| 洪雅县| 黔江区| 遂川县| 临颍县| 珲春市| 汝南县| 赣榆县| 阿勒泰市| 奉贤区| 龙南县| 博罗县| 武城县| 赣榆县| 科技| 天等县| 隆回县| 慈溪市| 梁河县| 绵阳市| 高阳县| 曲靖市| 宜章县| 葵青区| 南靖县| 清涧县| 鹤山市| 海原县| 奉贤区| 石棉县| 乌审旗| 深圳市| 滦平县| 锡林郭勒盟| 锦屏县| 木里|