你到画图面版里把你的BMP图打开,另存为的时候改成JPG格式,或者在你的电脑中打开文件夹选项把带有后缀的文件名的勾去掉,在BMP的图片后面更改成你需要的格式
10余年的临潭网站建设经验,针对设计、前端、开发、售后、文案、推广等六对一服务,响应快,48小时及时工作处理。成都全网营销推广的优势是能够根据用户设备显示端的尺寸不同,自动调整临潭建站的显示方式,使网站能够适用不同显示终端,在浏览器中调整网站的宽度,无论在任何一种浏览器上浏览网站,都能展现优雅布局与设计,从而大程度地提升浏览体验。创新互联从事“临潭网站设计”,“临潭网站推广”以来,每个客户项目都认真落实执行。
去git上面看看源码
//先说一下这个函数吧
//cvNamedWindow
CV_IMPL int cvNamedWindow(const char* name, int flags){
CV_FUNCNAME("cvNamedWindow");
if (!name)CV_ERROR(CV_StsNullPtr, "NULL name");
HighguiBridge::getInstance().namedWindow(name);
return CV_OK;
}
//而它又需要HighhuiBridge这个类,它有个单例工厂方法
HighguiBridge HighguiBridge::getInstance(){
static HighguiBridge instance;
return instance;
}
//上面2个函数实际调用这2个成员函数
CvWindow* HighguiBridge::namedWindow(cv::String name) {
CvWindow* window = HighguiBridge::getInstance().findWindowByName(name.c_str());
if (!window)window = createWindow(name);
return window;
}
//创建窗口先是查找有没有已有窗口
CvWindow* HighguiBridge::findWindowByName(cv::String name){
auto search = windowsMap-find(name);
if (search != windowsMap-end())return search-second;
return nullptr;
}
//如果没有会用这个函数创建
CvWindow* HighguiBridge::createWindow(cv::String name){
CvWindow* window = new CvWindow(name);
windowsMap-insert(std::paircv::String, CvWindow*(name, window));
return window;
}
//创建窗口是CvWindow类
class CvWindow{
public:
CvWindow(cv::String name, int flag = CV_WINDOW_NORMAL);
~CvWindow();
/** @brief NOTE: prototype.
Should create button if there is no button with this name already.
*/
void createButton(cv::String name);
/** @brief Creates slider if there is no slider with this name already.
The function creates slider if there is no slider with this name already OR resets
provided values for the existing one.
*/
void createSlider(cv::String name, int* val, int count, CvTrackbarCallback2 on_notify, void* userdata);
/** @brief Updates window image.
@param src Image data object reference.
The function updates window image. If argument is null or image control is not found - does nothing.
*/
void updateImage(CvMat* arr);
/** @brief Returns reference to the trackbar(slider) registered within provided window.
@param name Name of the window.
The function returns reference to the trackbar(slider) registered within provided window.
Returns nullptr if trackbar with specified name is not found or window reference is nullptr.
*/
CvTrackbar* findTrackbarByName(cv::String name);
Page^ getPage();
private:
cv::String name;
// Holds image data in CV format
CvMat* imageData;
// Map of all sliders assigned to this window
std::mapcv::String, CvTrackbar** sliderMap;
// Window contents holder
Page^ page;
// Image control displayed by this window
Image^ imageControl;
// Container for sliders
Panel^ sliderPanel;
// Container for buttons
// TODO: prototype, not available via API
Panel^ buttonPanel;
// Holds image width to arrange other UI elements.
// Required since imageData-width value gets recalculated when processing
int imageWidth;
// Default markup for the container content allowing for proper components placement
static const Platform::String^ markupContent;
// Default Slider size, fallback solution for unexpected edge cases
static const double sliderDefaultWidth;
};
//CvWindwo构造函数为
CvWindow::CvWindow(cv::String name, int flags) : name(name){
this-page = (Page^)Windows::UI::Xaml::Markup::XamlReader::Load(const_castPlatform::String^(markupContent));
this-sliderMap = new std::mapcv::String, CvTrackbar*();
sliderPanel = (Panel^)page-FindName("cvTrackbar");
imageControl = (Image^)page-FindName("cvImage");
buttonPanel = (Panel^)page-FindName("cvButton");
// Required to adapt controls to the size of the image.
// System calculates image control width first, after that we can
// update other controls
imageControl-Loaded += ref new Windows::UI::Xaml::RoutedEventHandler(
[=](Platform::Object^ sender,
Windows::UI::Xaml::RoutedEventArgs^ e){
// Need to update sliders with appropriate width
for(auto iter=sliderMap-begin();iter!=sliderMap-end();++iter){
iter-second-getSlider()-Width = imageControl-ActualWidth;
}
// Need to update buttons with appropriate width
// TODO: implement when adding buttons
});
}
android 中实现网页调用摄像头功能方法·如下:
1/apk/res/android"
xmlns:tools="schemas/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context=".CameraWebviewActivity"
Button
android:id="@+id/bt"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Camera"
android:layout_alignParentTop="true"
/
WebView
android:id="@+id/wv"
android:layout_width="fill_parent"
android:layout_height="match_parent"
android:layout_below="@+id/bt"
/
/RelativeLayout
4.、编写activity:
public class CameraWebviewActivity extends Activity {
private final static String TAG = "CameraWebviewActivity";
private Button bt;
private WebView wv;
public String fileFullName;//照相后的照片的全整路径
private boolean fromTakePhoto; //是否是从摄像界面返回的webview
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_camera_webview);
initViews();
}
private void initViews() {
bt = (Button) findViewById(R.id.bt);
bt.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
System.out.println("----------------");
takePhoto( Math.random()*1000+1 + ".jpg");
}
});
wv = (WebView) findViewById(R.id.wv);
WebSettings setting = wv.getSettings();
setting.setJavaScriptEnabled(true);
wv.setWebViewClient(new WebViewClient(){
@Override
public void onPageStarted(WebView view, String url, Bitmap favicon) {
super.onPageStarted(view, url, favicon);
}
@Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
return super.shouldOverrideUrlLoading(view, url);
}
@Override
public void onPageFinished(WebView view, String url) {
super.onPageFinished(view, url);
}
});
wv.setWebChromeClient(new WebChromeClient(){
@Override//实现js中的alert弹窗在Activity中显示
public boolean onJsAlert(WebView view, String url, String message, JsResult result) {
Log.d(TAG, message);
result.confirm();
return true;
}
});
wv.loadUrl("");
final Handler mHandler = new Handler();
//webview增加javascript接口,监听html页面中的js点击事件
wv.addJavascriptInterface(new Object(){
public String clickOnAndroid() {//将被js调用
mHandler.post(new Runnable() {
public void run() {
fromTakePhoto = true;
//调用 启用摄像头的自定义方法
takePhoto("testimg" + Math.random()*1000+1 + ".jpg");
System.out.println("========fileFullName: " + fileFullName);
}
});
return fileFullName;
}
}, "demo");
}
/*
* 调用摄像头的方法
*/
public void takePhoto(String filename) {
System.out.println("----start to take photo2 ----");
Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
intent.putExtra(MediaStore.EXTRA_MEDIA_TITLE, "TakePhoto");
//判断是否有SD卡
String sdDir = null;
boolean isSDcardExist = Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED);
if(isSDcardExist) {
sdDir = Environment.getExternalStorageDirectory().getAbsolutePath();
} else {
sdDir = Environment.getRootDirectory().getAbsolutePath();
}
//确定相片保存路径
String targetDir = sdDir + "/" + "webview_camera";
File file = new File(targetDir);
if (!file.exists()) {
file.mkdirs();
}
fileFullName = targetDir + "/" + filename;
System.out.println("----taking photo fileFullName: " + fileFullName);
//初始化并调用摄像头
intent.putExtra(MediaStore.Images.Media.MIME_TYPE, "image/jpeg");
intent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(new File(fileFullName)));
startActivityForResult(intent, 1);
}
/*
* (non-Javadoc)
* @see android.app.Activity#onActivityResult(int, int, android.content.Intent)
* 重写些方法,判断是否从摄像Activity返回的webview activity
*/
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
System.out.println("----requestCode: " + requestCode + "; resultCode " + resultCode + "; fileFullName: " + fileFullName);
if (fromTakePhoto requestCode ==1 resultCode ==-1) {
wv.loadUrl("javascript:wave2('" + fileFullName + "')");
} else {
wv.loadUrl("javascript:wave2('Please take your photo')");
}
fromTakePhoto = false;
super.onActivityResult(requestCode, resultCode, data);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.camera_webview, menu);
return true;
}
}
C语言本身是无法直接控制外设的。但可以通过各种应用编程接口(api),间接调用外部设备。例如opencv库。
OpenCV的全称是:Open Source Computer Vision Library。OpenCV是一个基于(开源)发行的跨平台计算机视觉库,可以运行在Linux、Windows和Mac OS操作系统上。它轻量级而且高效——由一系列 C 函数和少量 C++ 类构成,同时提供了Python、Ruby、MATLAB等语言的接口,实现了图像处理和计算机视觉方面的很多通用算法。
OpenCV用C++语言编写,它的主要接口也是C++语言,但是依然保留了大量的C语言接口。该库也有大量的Python, Java and MATLAB/OCTAVE (版本2.5)的接口。这些语言的API接口函数可以通过在线文档获得。如今也提供对于C#,Ch, Ruby的支持。
例程:
#include "cv.h"
#include "highgui.h"
int main(int argc, char** argv) {
cvNamedWindow("win");
CvCapture* capture = cvCreateCameraCapture(0); //创建并获取摄像设备
IplImage* frame;
while(1) {
frame = cvQueryFrame(capture); //创建并获取一张摄像截图
if(!frame) break; //如果失败终止循环
cvShowImage("win", frame); //在一个"win"窗口,并当中显示该截图
char c = cvWaitKey(50);
if(c==27) break;
}
cvReleaseCapture(capture); //释放摄像设备
cvDestroyWindow("win"); //释放窗口"win"
return 0;
}