SlideShare a Scribd company logo
Android
  カメラアプリ
   実装のコツ                                          id:TAC


この資料の内容の一部は、Google が作成、提供しているコンテンツをベースに変更したもので、
クリエイティブ・コモンズの表示 3.0 ライセンスに記載の条件に従って使用しています。
自己紹介

 id: TAC, tac0x2a
 Twitter: @tac0x2a
 Androidアプリ作ってます.
 求職中の院生です
Droid Jammer
●   画像中の顔を認識して
    アイコンで隠す

●   簡単な編集ができる

●   インテント連携

●   おまけでカメラ機能を付けた
    おまけで
投稿者: holybible(2010年7月21日)
   Funny idea and easy to use However,
   always got Force to Close on my Froyo device


                         投稿者: Faheem(2010年8月29日)
                         Force closes on taking a pic. Cliq


投稿者: Daniel(2010年9月10日)
Doesn't function. Force close. Eris


              投稿者: Diego(2010年9月27日)
              It keeps on chrashing each time i open it. G1


    投稿者: Eduardo(2010年5月8日)
      Does not work on HTC hero
投稿者: holybible(2010年7月21日)
   Funny idea and easy to use However,
   always got Force to Close on my Froyo device


                         投稿者: Faheem(2010年8月29日)
                         Force closes on taking a pic. Cliq


投稿者: Daniel(2010年9月10日)
Doesn't function. Force close. Eris


              投稿者: Diego(2010年9月27日)
              It keeps on chrashing each time i open it. G1


    投稿者: Eduardo(2010年5月8日)
      Does not work on HTC hero
2つのコツ+α

OutOfMemoryError対策

   takePictureによる
   コールバック
コツその1




OutOfMemoryError
      対策
撮影した画像データを取得する
@Override
public void onPictureTaken(
  byte[] data, Camera camera) {

Bitmap picture =
BitmapFactory.decodeByteArray(
      data,0,data.length,option);

 撮影したデータ( byte[] data ) を Bitmapオブジェクトに変換
@Override
    OutOfMemoryError
public void onPictureTaken(
  byte[] data, Camera camera) {

Bitmap picture =
BitmapFactory.decodeByteArray(
      data,0,data.length,option);

 撮影したデータ( byte[] data ) を Bitmapオブジェクトに変換
OutOfMemoryError
●
    巨大な画像を扱うにはメモリ(ヒープ)が足りない
    ●
        →端末によって異なるが大体16〜32MB程度
●


●
    撮影したデータをBitmapオブジェクトへ変換
    ●
        →メモリ不足で強制終了
読み込みサイズを制限
Bitmap loadSavedSizeBitmap(int maxSize, byte[] data) {

    BitmapFactory.Options opt = new BitmapFactory.Options();
    opt.inJustDecodeBounds = true;

    BitmapFactory.decodeByteArray(data, 0, data.length, opt);
    int srcSize = Math.max(opt.outWidth,opt.outHeight);

    opt.inSampleSize
            = maxSize < srcSize ? (srcSize / maxSize) : 1;

    option.inJustDecodeBounds = false;
    return BitmapFactory.decodeByteArray(
                             data, 0,data.length, opt));
}
読み込みサイズを制限
Bitmap loadSavedSizeBitmap(int maxSize, byte[] data) {

    BitmapFactory.Options opt = new BitmapFactory.Options();
    opt.inJustDecodeBounds = true;

    BitmapFactory.decodeByteArray(data, 0, data.length, opt);
    int srcSize = Math.max(opt.outWidth,opt.outHeight);

    opt.inSampleSize
            = maxSize < srcSize ? (srcSize / maxSize) : 1;
                                    サイズを先読み
    option.inJustDecodeBounds = false;
    return BitmapFactory.decodeByteArray(
                             data, 0,data.length, opt));
}
読み込みサイズを制限
 何倍でロードするか
Bitmap loadSavedSizeBitmap(int maxSize, byte[] data) {
      計算して設定
    (1/inSampleSize)
    BitmapFactory.Options opt = new BitmapFactory.Options();
    opt.inJustDecodeBounds = true;

    BitmapFactory.decodeByteArray(data, 0, data.length, opt);
    int srcSize = Math.max(opt.outWidth,opt.outHeight);

    opt.inSampleSize
            = maxSize < srcSize ? (srcSize / maxSize) : 1;

    option.inJustDecodeBounds = false;
    return BitmapFactory.decodeByteArray(
                             data, 0,data.length, opt));
}
読み込みサイズを制限
Bitmap loadSavedSizeBitmap(int maxSize, byte[] data) {

    BitmapFactory.Options opt = new BitmapFactory.Options();
    opt.inJustDecodeBounds = true;

                               設定した倍率で
    BitmapFactory.decodeByteArray(data, 0, data.length, opt);
    int srcSize = Math.max(opt.outWidth,opt.outHeight);
                                  ロードする
    opt.inSampleSize
            = maxSize < srcSize ? (srcSize / maxSize) : 1;

    option.inJustDecodeBounds = false;
    return BitmapFactory.decodeByteArray(
                             data, 0,data.length, opt));
}
コツその2




takePictureによる
   コールバック
撮影するメソッド
public final void takePicture(
  ShutterCallback shutter,
  PictureCallback raw,
  PictureCallback postview,
  PictureCallback jpeg
)
 4つのコールバックを設定.
 Android1.xでは引数は3つで, postviewをnullにした場合と同じ
takePictureから
どのコールバックが
   呼ばれるかは
   端末依存です
端末依存なコールバック
public final void takePicture(
  ShutterCallback shutter,
  PictureCallback raw,
  PictureCallback postview,
  PictureCallback jpeg
)
私のx06htではrawは呼ばれたがshutterとpostviewが呼ばれなかった
takePicture
によるコールバックは
   非同期です
takePictureの流れ
 takePicture(
    shutter,
    raw,
    postview,
    jpeg
 );
                shutter


                  raw


                 jpeg
jpeg saved
                                  jpeg
SDK 2.2 emu(1.6) 320x240          raw
                                  shutter
                                  takePicture()




x06ht(2.2.1) 1024x768




ht03a (2.2.1) 1024x768


0        500       1000    1500    2000           2500
takePictureの流れ
       takePicture(
          shutter,
          raw,
          postview,
          jpeg
       );
                            shutter

 まだBitmapが
作られていない!                      raw
                                       ここで
                      約2秒             Bitmapが
                                      作られる
                             jpeg
Bitmapへのアクセスは
jpegのコールバックで
保存されたのを確認し
      てから!
+α
●
    setPictureSize()とsetPreviewSize()を適切に
    設定する.
    ●
        getSupported{Picture|Preview}Sizes()で取得した
        リストからそれぞれ設定.
    ●
        端末によっては特定の組み合わせで落ちる(多分).
    ●


●
    IntentでBitmapオブジェクトを投げない
    ●
        大きなデータをIntentで投げると落ちます
    ●
        とりあえずSDとかに保存、ファイルへのパスのみを
        Intentに乗せて、受ける側でファイルから読み出す
まとめ
●
    メモリやGCを意識して書く
●
    カメラアプリは端末による差が出やすい
●


●
    デバッグに協力してくれる人を増やす
    ●
        →Androidを布教しt(ry
最後に
Android2.2以降をお使いの皆様




  バグレポートを
  送ってください
哀れみをこめて押す
願いを込めて書く
ね?簡単でしょ?
Androidカメラアプリ実装のコツ




             おしまい
                     Twitter: @tac0x2a
                     Mail: tac@tac42.net
                     野良: http://goo.gl/k2wk
                     AndroidMarket:

More Related Content

Similar to カメラアプリ実装のコツ

Android - Displaying images
Android - Displaying imagesAndroid - Displaying images
Android - Displaying images
Matteo Bonifazi
 
Naive application development
Naive application developmentNaive application development
Naive application development
Shaka Huang
 
Work With Images
Work With ImagesWork With Images
Work With Images
Sergey Tarasevich
 
Static analysis of C++ source code
Static analysis of C++ source codeStatic analysis of C++ source code
Static analysis of C++ source code
PVS-Studio
 
Static analysis of C++ source code
Static analysis of C++ source codeStatic analysis of C++ source code
Static analysis of C++ source code
Andrey Karpov
 
XebiCon'17 : Faites chauffer les neurones de votre Smartphone avec du Deep Le...
XebiCon'17 : Faites chauffer les neurones de votre Smartphone avec du Deep Le...XebiCon'17 : Faites chauffer les neurones de votre Smartphone avec du Deep Le...
XebiCon'17 : Faites chauffer les neurones de votre Smartphone avec du Deep Le...
Publicis Sapient Engineering
 
426 lecture 4: AR Developer Tools
426 lecture 4: AR Developer Tools426 lecture 4: AR Developer Tools
426 lecture 4: AR Developer Tools
Mark Billinghurst
 
Analyzing the Performance of Mobile Web
Analyzing the Performance of Mobile WebAnalyzing the Performance of Mobile Web
Analyzing the Performance of Mobile Web
Ariya Hidayat
 
Real_World_0days.pdf
Real_World_0days.pdfReal_World_0days.pdf
Real_World_0days.pdf
distortdistort
 
FLAR Workflow
FLAR WorkflowFLAR Workflow
FLAR Workflow
Jesse Freeman
 
Hunting Performance Problems in Node.js and beyond
Hunting Performance Problems in Node.js and beyondHunting Performance Problems in Node.js and beyond
Hunting Performance Problems in Node.js and beyond
Daniel Khan
 
Who moved my pixels?!
Who moved my pixels?!Who moved my pixels?!
Who moved my pixels?!
Mikhail Sosonkin
 
Back To The Future.Key 2
Back To The Future.Key 2Back To The Future.Key 2
Back To The Future.Key 2gueste8cc560
 
Power ai image-pipeline
Power ai image-pipelinePower ai image-pipeline
Power ai image-pipeline
Paulo Sergio Lemes Queiroz
 
Welcome to Mordor - Daniel Kahn - Codemotion Amsterdam 2016
Welcome to Mordor - Daniel Kahn - Codemotion Amsterdam 2016Welcome to Mordor - Daniel Kahn - Codemotion Amsterdam 2016
Welcome to Mordor - Daniel Kahn - Codemotion Amsterdam 2016
Codemotion
 
Full Body 3D Scan System Kit with Raspberry Pi Zero W
Full Body 3D Scan System Kit with Raspberry Pi Zero WFull Body 3D Scan System Kit with Raspberry Pi Zero W
Full Body 3D Scan System Kit with Raspberry Pi Zero W
リアリアバター株式会社 岩山幸洋
 
[html5tx] Adaptive Images in Responsive Web Design
[html5tx] Adaptive Images in Responsive Web Design[html5tx] Adaptive Images in Responsive Web Design
[html5tx] Adaptive Images in Responsive Web Design
Christopher Schmitt
 
COSC 426 Lect. 3 -AR Developer Tools
COSC 426 Lect. 3 -AR Developer ToolsCOSC 426 Lect. 3 -AR Developer Tools
COSC 426 Lect. 3 -AR Developer Tools
Mark Billinghurst
 
PVS-Studio and Continuous Integration: TeamCity. Analysis of the Open RollerC...
PVS-Studio and Continuous Integration: TeamCity. Analysis of the Open RollerC...PVS-Studio and Continuous Integration: TeamCity. Analysis of the Open RollerC...
PVS-Studio and Continuous Integration: TeamCity. Analysis of the Open RollerC...
Andrey Karpov
 
[cssdevconf] Adaptive Images in RWD
[cssdevconf] Adaptive Images in RWD[cssdevconf] Adaptive Images in RWD
[cssdevconf] Adaptive Images in RWDChristopher Schmitt
 

Similar to カメラアプリ実装のコツ (20)

Android - Displaying images
Android - Displaying imagesAndroid - Displaying images
Android - Displaying images
 
Naive application development
Naive application developmentNaive application development
Naive application development
 
Work With Images
Work With ImagesWork With Images
Work With Images
 
Static analysis of C++ source code
Static analysis of C++ source codeStatic analysis of C++ source code
Static analysis of C++ source code
 
Static analysis of C++ source code
Static analysis of C++ source codeStatic analysis of C++ source code
Static analysis of C++ source code
 
XebiCon'17 : Faites chauffer les neurones de votre Smartphone avec du Deep Le...
XebiCon'17 : Faites chauffer les neurones de votre Smartphone avec du Deep Le...XebiCon'17 : Faites chauffer les neurones de votre Smartphone avec du Deep Le...
XebiCon'17 : Faites chauffer les neurones de votre Smartphone avec du Deep Le...
 
426 lecture 4: AR Developer Tools
426 lecture 4: AR Developer Tools426 lecture 4: AR Developer Tools
426 lecture 4: AR Developer Tools
 
Analyzing the Performance of Mobile Web
Analyzing the Performance of Mobile WebAnalyzing the Performance of Mobile Web
Analyzing the Performance of Mobile Web
 
Real_World_0days.pdf
Real_World_0days.pdfReal_World_0days.pdf
Real_World_0days.pdf
 
FLAR Workflow
FLAR WorkflowFLAR Workflow
FLAR Workflow
 
Hunting Performance Problems in Node.js and beyond
Hunting Performance Problems in Node.js and beyondHunting Performance Problems in Node.js and beyond
Hunting Performance Problems in Node.js and beyond
 
Who moved my pixels?!
Who moved my pixels?!Who moved my pixels?!
Who moved my pixels?!
 
Back To The Future.Key 2
Back To The Future.Key 2Back To The Future.Key 2
Back To The Future.Key 2
 
Power ai image-pipeline
Power ai image-pipelinePower ai image-pipeline
Power ai image-pipeline
 
Welcome to Mordor - Daniel Kahn - Codemotion Amsterdam 2016
Welcome to Mordor - Daniel Kahn - Codemotion Amsterdam 2016Welcome to Mordor - Daniel Kahn - Codemotion Amsterdam 2016
Welcome to Mordor - Daniel Kahn - Codemotion Amsterdam 2016
 
Full Body 3D Scan System Kit with Raspberry Pi Zero W
Full Body 3D Scan System Kit with Raspberry Pi Zero WFull Body 3D Scan System Kit with Raspberry Pi Zero W
Full Body 3D Scan System Kit with Raspberry Pi Zero W
 
[html5tx] Adaptive Images in Responsive Web Design
[html5tx] Adaptive Images in Responsive Web Design[html5tx] Adaptive Images in Responsive Web Design
[html5tx] Adaptive Images in Responsive Web Design
 
COSC 426 Lect. 3 -AR Developer Tools
COSC 426 Lect. 3 -AR Developer ToolsCOSC 426 Lect. 3 -AR Developer Tools
COSC 426 Lect. 3 -AR Developer Tools
 
PVS-Studio and Continuous Integration: TeamCity. Analysis of the Open RollerC...
PVS-Studio and Continuous Integration: TeamCity. Analysis of the Open RollerC...PVS-Studio and Continuous Integration: TeamCity. Analysis of the Open RollerC...
PVS-Studio and Continuous Integration: TeamCity. Analysis of the Open RollerC...
 
[cssdevconf] Adaptive Images in RWD
[cssdevconf] Adaptive Images in RWD[cssdevconf] Adaptive Images in RWD
[cssdevconf] Adaptive Images in RWD
 

Recently uploaded

The Art of the Pitch: WordPress Relationships and Sales
The Art of the Pitch: WordPress Relationships and SalesThe Art of the Pitch: WordPress Relationships and Sales
The Art of the Pitch: WordPress Relationships and Sales
Laura Byrne
 
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdfFIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
FIDO Alliance
 
PCI PIN Basics Webinar from the Controlcase Team
PCI PIN Basics Webinar from the Controlcase TeamPCI PIN Basics Webinar from the Controlcase Team
PCI PIN Basics Webinar from the Controlcase Team
ControlCase
 
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdf
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdfSmart TV Buyer Insights Survey 2024 by 91mobiles.pdf
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdf
91mobiles
 
GraphRAG is All You need? LLM & Knowledge Graph
GraphRAG is All You need? LLM & Knowledge GraphGraphRAG is All You need? LLM & Knowledge Graph
GraphRAG is All You need? LLM & Knowledge Graph
Guy Korland
 
Generative AI Deep Dive: Advancing from Proof of Concept to Production
Generative AI Deep Dive: Advancing from Proof of Concept to ProductionGenerative AI Deep Dive: Advancing from Proof of Concept to Production
Generative AI Deep Dive: Advancing from Proof of Concept to Production
Aggregage
 
Monitoring Java Application Security with JDK Tools and JFR Events
Monitoring Java Application Security with JDK Tools and JFR EventsMonitoring Java Application Security with JDK Tools and JFR Events
Monitoring Java Application Security with JDK Tools and JFR Events
Ana-Maria Mihalceanu
 
Securing your Kubernetes cluster_ a step-by-step guide to success !
Securing your Kubernetes cluster_ a step-by-step guide to success !Securing your Kubernetes cluster_ a step-by-step guide to success !
Securing your Kubernetes cluster_ a step-by-step guide to success !
KatiaHIMEUR1
 
Epistemic Interaction - tuning interfaces to provide information for AI support
Epistemic Interaction - tuning interfaces to provide information for AI supportEpistemic Interaction - tuning interfaces to provide information for AI support
Epistemic Interaction - tuning interfaces to provide information for AI support
Alan Dix
 
Quantum Computing: Current Landscape and the Future Role of APIs
Quantum Computing: Current Landscape and the Future Role of APIsQuantum Computing: Current Landscape and the Future Role of APIs
Quantum Computing: Current Landscape and the Future Role of APIs
Vlad Stirbu
 
Leading Change strategies and insights for effective change management pdf 1.pdf
Leading Change strategies and insights for effective change management pdf 1.pdfLeading Change strategies and insights for effective change management pdf 1.pdf
Leading Change strategies and insights for effective change management pdf 1.pdf
OnBoard
 
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdfFIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
FIDO Alliance
 
zkStudyClub - Reef: Fast Succinct Non-Interactive Zero-Knowledge Regex Proofs
zkStudyClub - Reef: Fast Succinct Non-Interactive Zero-Knowledge Regex ProofszkStudyClub - Reef: Fast Succinct Non-Interactive Zero-Knowledge Regex Proofs
zkStudyClub - Reef: Fast Succinct Non-Interactive Zero-Knowledge Regex Proofs
Alex Pruden
 
Secstrike : Reverse Engineering & Pwnable tools for CTF.pptx
Secstrike : Reverse Engineering & Pwnable tools for CTF.pptxSecstrike : Reverse Engineering & Pwnable tools for CTF.pptx
Secstrike : Reverse Engineering & Pwnable tools for CTF.pptx
nkrafacyberclub
 
Alt. GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using ...
Alt. GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using ...Alt. GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using ...
Alt. GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using ...
James Anderson
 
Essentials of Automations: The Art of Triggers and Actions in FME
Essentials of Automations: The Art of Triggers and Actions in FMEEssentials of Automations: The Art of Triggers and Actions in FME
Essentials of Automations: The Art of Triggers and Actions in FME
Safe Software
 
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
DanBrown980551
 
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
Albert Hoitingh
 
Removing Uninteresting Bytes in Software Fuzzing
Removing Uninteresting Bytes in Software FuzzingRemoving Uninteresting Bytes in Software Fuzzing
Removing Uninteresting Bytes in Software Fuzzing
Aftab Hussain
 
Video Streaming: Then, Now, and in the Future
Video Streaming: Then, Now, and in the FutureVideo Streaming: Then, Now, and in the Future
Video Streaming: Then, Now, and in the Future
Alpen-Adria-Universität
 

Recently uploaded (20)

The Art of the Pitch: WordPress Relationships and Sales
The Art of the Pitch: WordPress Relationships and SalesThe Art of the Pitch: WordPress Relationships and Sales
The Art of the Pitch: WordPress Relationships and Sales
 
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdfFIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
 
PCI PIN Basics Webinar from the Controlcase Team
PCI PIN Basics Webinar from the Controlcase TeamPCI PIN Basics Webinar from the Controlcase Team
PCI PIN Basics Webinar from the Controlcase Team
 
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdf
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdfSmart TV Buyer Insights Survey 2024 by 91mobiles.pdf
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdf
 
GraphRAG is All You need? LLM & Knowledge Graph
GraphRAG is All You need? LLM & Knowledge GraphGraphRAG is All You need? LLM & Knowledge Graph
GraphRAG is All You need? LLM & Knowledge Graph
 
Generative AI Deep Dive: Advancing from Proof of Concept to Production
Generative AI Deep Dive: Advancing from Proof of Concept to ProductionGenerative AI Deep Dive: Advancing from Proof of Concept to Production
Generative AI Deep Dive: Advancing from Proof of Concept to Production
 
Monitoring Java Application Security with JDK Tools and JFR Events
Monitoring Java Application Security with JDK Tools and JFR EventsMonitoring Java Application Security with JDK Tools and JFR Events
Monitoring Java Application Security with JDK Tools and JFR Events
 
Securing your Kubernetes cluster_ a step-by-step guide to success !
Securing your Kubernetes cluster_ a step-by-step guide to success !Securing your Kubernetes cluster_ a step-by-step guide to success !
Securing your Kubernetes cluster_ a step-by-step guide to success !
 
Epistemic Interaction - tuning interfaces to provide information for AI support
Epistemic Interaction - tuning interfaces to provide information for AI supportEpistemic Interaction - tuning interfaces to provide information for AI support
Epistemic Interaction - tuning interfaces to provide information for AI support
 
Quantum Computing: Current Landscape and the Future Role of APIs
Quantum Computing: Current Landscape and the Future Role of APIsQuantum Computing: Current Landscape and the Future Role of APIs
Quantum Computing: Current Landscape and the Future Role of APIs
 
Leading Change strategies and insights for effective change management pdf 1.pdf
Leading Change strategies and insights for effective change management pdf 1.pdfLeading Change strategies and insights for effective change management pdf 1.pdf
Leading Change strategies and insights for effective change management pdf 1.pdf
 
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdfFIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
 
zkStudyClub - Reef: Fast Succinct Non-Interactive Zero-Knowledge Regex Proofs
zkStudyClub - Reef: Fast Succinct Non-Interactive Zero-Knowledge Regex ProofszkStudyClub - Reef: Fast Succinct Non-Interactive Zero-Knowledge Regex Proofs
zkStudyClub - Reef: Fast Succinct Non-Interactive Zero-Knowledge Regex Proofs
 
Secstrike : Reverse Engineering & Pwnable tools for CTF.pptx
Secstrike : Reverse Engineering & Pwnable tools for CTF.pptxSecstrike : Reverse Engineering & Pwnable tools for CTF.pptx
Secstrike : Reverse Engineering & Pwnable tools for CTF.pptx
 
Alt. GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using ...
Alt. GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using ...Alt. GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using ...
Alt. GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using ...
 
Essentials of Automations: The Art of Triggers and Actions in FME
Essentials of Automations: The Art of Triggers and Actions in FMEEssentials of Automations: The Art of Triggers and Actions in FME
Essentials of Automations: The Art of Triggers and Actions in FME
 
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
 
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
 
Removing Uninteresting Bytes in Software Fuzzing
Removing Uninteresting Bytes in Software FuzzingRemoving Uninteresting Bytes in Software Fuzzing
Removing Uninteresting Bytes in Software Fuzzing
 
Video Streaming: Then, Now, and in the Future
Video Streaming: Then, Now, and in the FutureVideo Streaming: Then, Now, and in the Future
Video Streaming: Then, Now, and in the Future
 

カメラアプリ実装のコツ

  • 1. Android カメラアプリ 実装のコツ id:TAC この資料の内容の一部は、Google が作成、提供しているコンテンツをベースに変更したもので、 クリエイティブ・コモンズの表示 3.0 ライセンスに記載の条件に従って使用しています。
  • 2. 自己紹介 id: TAC, tac0x2a Twitter: @tac0x2a Androidアプリ作ってます. 求職中の院生です
  • 3. Droid Jammer ● 画像中の顔を認識して アイコンで隠す ● 簡単な編集ができる ● インテント連携 ● おまけでカメラ機能を付けた おまけで
  • 4. 投稿者: holybible(2010年7月21日) Funny idea and easy to use However, always got Force to Close on my Froyo device 投稿者: Faheem(2010年8月29日) Force closes on taking a pic. Cliq 投稿者: Daniel(2010年9月10日) Doesn't function. Force close. Eris 投稿者: Diego(2010年9月27日) It keeps on chrashing each time i open it. G1 投稿者: Eduardo(2010年5月8日) Does not work on HTC hero
  • 5. 投稿者: holybible(2010年7月21日) Funny idea and easy to use However, always got Force to Close on my Froyo device 投稿者: Faheem(2010年8月29日) Force closes on taking a pic. Cliq 投稿者: Daniel(2010年9月10日) Doesn't function. Force close. Eris 投稿者: Diego(2010年9月27日) It keeps on chrashing each time i open it. G1 投稿者: Eduardo(2010年5月8日) Does not work on HTC hero
  • 6. 2つのコツ+α OutOfMemoryError対策 takePictureによる コールバック
  • 9. @Override public void onPictureTaken( byte[] data, Camera camera) { Bitmap picture = BitmapFactory.decodeByteArray( data,0,data.length,option); 撮影したデータ( byte[] data ) を Bitmapオブジェクトに変換
  • 10. @Override OutOfMemoryError public void onPictureTaken( byte[] data, Camera camera) { Bitmap picture = BitmapFactory.decodeByteArray( data,0,data.length,option); 撮影したデータ( byte[] data ) を Bitmapオブジェクトに変換
  • 11. OutOfMemoryError ● 巨大な画像を扱うにはメモリ(ヒープ)が足りない ● →端末によって異なるが大体16〜32MB程度 ● ● 撮影したデータをBitmapオブジェクトへ変換 ● →メモリ不足で強制終了
  • 12. 読み込みサイズを制限 Bitmap loadSavedSizeBitmap(int maxSize, byte[] data) { BitmapFactory.Options opt = new BitmapFactory.Options(); opt.inJustDecodeBounds = true; BitmapFactory.decodeByteArray(data, 0, data.length, opt); int srcSize = Math.max(opt.outWidth,opt.outHeight); opt.inSampleSize = maxSize < srcSize ? (srcSize / maxSize) : 1; option.inJustDecodeBounds = false; return BitmapFactory.decodeByteArray( data, 0,data.length, opt)); }
  • 13. 読み込みサイズを制限 Bitmap loadSavedSizeBitmap(int maxSize, byte[] data) { BitmapFactory.Options opt = new BitmapFactory.Options(); opt.inJustDecodeBounds = true; BitmapFactory.decodeByteArray(data, 0, data.length, opt); int srcSize = Math.max(opt.outWidth,opt.outHeight); opt.inSampleSize = maxSize < srcSize ? (srcSize / maxSize) : 1; サイズを先読み option.inJustDecodeBounds = false; return BitmapFactory.decodeByteArray( data, 0,data.length, opt)); }
  • 14. 読み込みサイズを制限 何倍でロードするか Bitmap loadSavedSizeBitmap(int maxSize, byte[] data) { 計算して設定 (1/inSampleSize) BitmapFactory.Options opt = new BitmapFactory.Options(); opt.inJustDecodeBounds = true; BitmapFactory.decodeByteArray(data, 0, data.length, opt); int srcSize = Math.max(opt.outWidth,opt.outHeight); opt.inSampleSize = maxSize < srcSize ? (srcSize / maxSize) : 1; option.inJustDecodeBounds = false; return BitmapFactory.decodeByteArray( data, 0,data.length, opt)); }
  • 15. 読み込みサイズを制限 Bitmap loadSavedSizeBitmap(int maxSize, byte[] data) { BitmapFactory.Options opt = new BitmapFactory.Options(); opt.inJustDecodeBounds = true; 設定した倍率で BitmapFactory.decodeByteArray(data, 0, data.length, opt); int srcSize = Math.max(opt.outWidth,opt.outHeight); ロードする opt.inSampleSize = maxSize < srcSize ? (srcSize / maxSize) : 1; option.inJustDecodeBounds = false; return BitmapFactory.decodeByteArray( data, 0,data.length, opt)); }
  • 17. 撮影するメソッド public final void takePicture( ShutterCallback shutter, PictureCallback raw, PictureCallback postview, PictureCallback jpeg ) 4つのコールバックを設定. Android1.xでは引数は3つで, postviewをnullにした場合と同じ
  • 18. takePictureから どのコールバックが 呼ばれるかは 端末依存です
  • 19. 端末依存なコールバック public final void takePicture( ShutterCallback shutter, PictureCallback raw, PictureCallback postview, PictureCallback jpeg ) 私のx06htではrawは呼ばれたがshutterとpostviewが呼ばれなかった
  • 21. takePictureの流れ takePicture( shutter, raw, postview, jpeg ); shutter raw jpeg
  • 22. jpeg saved jpeg SDK 2.2 emu(1.6) 320x240 raw shutter takePicture() x06ht(2.2.1) 1024x768 ht03a (2.2.1) 1024x768 0 500 1000 1500 2000 2500
  • 23. takePictureの流れ takePicture( shutter, raw, postview, jpeg ); shutter まだBitmapが 作られていない! raw ここで 約2秒 Bitmapが 作られる jpeg
  • 25. +α ● setPictureSize()とsetPreviewSize()を適切に 設定する. ● getSupported{Picture|Preview}Sizes()で取得した リストからそれぞれ設定. ● 端末によっては特定の組み合わせで落ちる(多分). ● ● IntentでBitmapオブジェクトを投げない ● 大きなデータをIntentで投げると落ちます ● とりあえずSDとかに保存、ファイルへのパスのみを Intentに乗せて、受ける側でファイルから読み出す
  • 26. まとめ ● メモリやGCを意識して書く ● カメラアプリは端末による差が出やすい ● ● デバッグに協力してくれる人を増やす ● →Androidを布教しt(ry
  • 32. Androidカメラアプリ実装のコツ おしまい Twitter: @tac0x2a Mail: tac@tac42.net 野良: http://goo.gl/k2wk AndroidMarket: