Please note that as of October 24, 2014, the Nokia Developer Wiki will no longer be accepting user contributions, including new entries, edits and comments, as we begin transitioning to our new home, in the Windows Phone Development Wiki. We plan to move over the majority of the existing entries. Thanks for all your past and future contributions.

البدء في استخدام الكاميرا داخل تطبيقاتك

From Wiki
Jump to: navigation, search

هذا المثال يوضح كيفية التعامل مع واجهة الكاميرا داخل تطبيقاتك بإستخدام بيئة تطوير ويندوز فون 8.

WP Metro Icon Multimedia.png
WP Metro Icon DirectX.png
WP Metro Icon WP8.png
WP Metro Icon Baby.png
Article Metadata
Code ExampleCompatibility
Windows Phone 8
By bintk
Last edited: hamishwillee (17 Jul 2013)



  • إن واجهات البرمجة المتوفرة لويندوز فون 8 توفر كل المستويات العالية، المتوسطة والمنخفضة
  • المستويات العليا تستخدم AudioVideoCaptureDevice لتسجيل ملفات الفيديو
  • او لسلاسل الصور بواسطة PhotoCaptureDevice
  • المستوي المتوسط ويستخدم لإستعراض المحتوي قبل إلتقاطة AudioVideoCaptureDevice, using the method AudioVideoCaptureDevice.GetPreviewBufferArgb

سوف تساعدك هذه المقالة علي تحقيق كل هذه المستويات

التطوير بواسطة الواجهة البرمجية لتطوير الكاميرا

الواجهات الأصلية كما هي مذكورة في Camera APIs for native code (Windows Phone 8), كل ماهو مطلوب للوصول إلي واجهات برمجة الكاميرا المتقدمة بواسطة الكود الأصلي . بعض الواجهات يتم إنشائها بواسطة ويندوز فون 8 و البعض الأخر يجب إنشائة داخل التطبيق

The interfaces implemented by the OS are ICameraCaptureDeviceNative and IAudioVideoCaptureDeviceNative, and the application-implemented interfaces are ICameraCapturePreviewSink and ICameraCaptureSampleSink.

To retrieve an instance of one of the OS implemented interfaces, the procedure starts with either an instance of AudioVideoCaptureDevice or PhotoCaptureDevice.

مثال لتحقيق ذلك أنظر أدناه:

AudioVideoCaptureDevice captureDevice;
// ...
// Retrieve the native ICameraCaptureDeviceNative interface from the managed video capture device
ICameraCaptureDeviceNative *iCameraCaptureDeviceNative = NULL;
HRESULT hr = reinterpret_cast<IUnknown*>(captureDevice)->QueryInterface(__uuidof(ICameraCaptureDeviceNative), (void**) &iCameraCaptureDeviceNative);

The ICameraCaptureDeviceNative interface is of interest to both photo- and audio/video-applications, as it provides access to a number of interesting methods. The first method of interest is SetPreviewSink. This method takes a pointer to an instance of the ICameraCapturePreviewSink interface. This means that the application will receive the preview frames and can process them in any way wanted. Related to this method is SetPreviewFormat, which sets the format of the preview-frames delivered (i.e. ARGB, NV12, etc.). The other two methods in this interface, SetDevice (used to set the DirectX 11 device and context) and GetPreviewBufferTexture (used to fill a DirectX 11 texture with the preview frames). Please note that the DirectX-related part of the interface is not demonstrated in this example.

The IAudioVideoCaptureDeviceNative-interface provides access to methods geared towards video- and audio-applications. The method SetAudioSampleSink sets the sink to receive audio samples, and the method SetVideoSampleSink sets the sink to receive video samples. Please note that both methods take a pointer to an instance of the ICameraCaptureSampleSink interface and that the ICameraCaptureSampleSink interface itself does not contain any way to identify whether the sample received is audio or video, so therefore I would recommend to implement it as two seperate sinks, one to handle audio and the other to handle video samples.

القيود علي ابعاد الصور و المعاينة

الجود التالي يبين بعض مقاسات الإلتقاط و المعاينة (لقد تم إختبارها علي جهاز نوكيا لوميا 920).ا

Type Aspect ratio Capturing resolution Preview resolution
Photo 4:3 3264x2448, 2592x1936, 2048x1536, 640x480 1024x768, 640x480
Photo 16:9 3552x2000, 2592x1456 1280x720, 800x448
Video 4:3 640x480, 320x240, 160x120 1024x768, 640x480
Video 16:9 1920x1080, 1280x720 1280x720, 800x448


لتنفيذ الواجهات داخل التطبيق , يجب تضمين الملفات التالية في التطبيق

#include <implements.h>
#include <Windows.Phone.Media.Capture.h>
#include <Windows.Phone.Media.Capture.Native.h> // This file contains the interface definitions for the native interfaces
class CameraCapturePreviewSink :
public Microsoft::WRL::RuntimeClass<
IFACEMETHODIMP_(void) OnFrameAvailable(
UINT width,
UINT height,
BYTE* pixels);
class CameraCaptureSampleSink :
public Microsoft::WRL::RuntimeClass<
IFACEMETHODIMP_(void) OnSampleAvailable(
ULONGLONG hnsPresentationTime,
ULONGLONG hnsSampleDuration,
DWORD cbSample,
BYTE* pSample);

الكود المصدري

يرجي الإطلاع علي هذا الكود المصدري لتنفيذ كامل التطبيق بنجاح

This page was last modified on 17 July 2013, at 05:33.
66 page views in the last 30 days.