2022年4月19日 星期二

Delphi VFW 操作Web Cam影像輸出,出現黑屏的解決方式


VFW 操作Web Cam影像輸出,換了不同型號的Web Cam出現黑屏,原來是「視訊格式」不同造成。

Code:
    hCapWnd := THandle;

    hCapWnd := capCreateCaptureWindow('Cam. Window',WS_VISIBLE or WS_CHILD, 
      0, 0, Panel1.Width, Panel1.Height, Panel1.Handle, 0);

    capDriverConnect(hCapWnd, 0); 

    capDlgVideoFormat(hCapWnd); //會出現「視訊各式」的視窗




將「像素深度(位元)及壓縮」設置成 YUY2 即可

2022年4月12日 星期二

Excel 操作出現 "外部資料表不是預期的格式"

 




用程式操作開啟Excel文件,出現 "外部資料表不是預期的格式" 


或是用Excel開啟文件,出現檔案格式不相符的訊息



存檔時將文件格式指定為 "一般活頁簿",可以排除這類的狀況。

excel := CreateOleObject('Excel.Application');
excel.Visible := False;
excel.Workbooks.Add;
workbook := excel.Workbooks[1];
...
...
workbook.SaveAs(OleVariat(filename), -4143);



XlFileFormat 列舉 (Excel)

會指定儲存工作表時的檔案格式。

名稱描述副檔名
xlAddIn18Microsoft Excel 97-2003 增益集*.xla
xlAddIn818Microsoft Excel 97-2003 增益集*.xla
xlCSV6CSV*.csv
xlCSVMac22Macintosh CSV*.csv
xlCSVMSDOS24MSDOS CSV*.csv
xlCSVUTF862UTF8 CSV*.csv
xlCSVWindowsWindows CSV*.csv
xlCurrentPlatformText-4158目前平台文字*.txt
xlDBF27Dbase 2 格式*.dbf
xlDBF38Dbase 3 格式*.dbf
xlDBF411Dbase 4 格式*.dbf
xlDIF9資料交換格式*.dif
xlExcel1250Excel 二進位活頁簿*.xlsb
xlExcel216Excel 2.0 版 (1987)*.xls
xlExcel2FarEast7Excel 2.0 遠東版 (1987)*.xls
xlExcel329Excel 3.0 版 (1990)*.xls
xlExcel433Excel 4.0 版 (1992)*.xls
xlExcel4Workbook35Excel 4.0 版 活頁簿格式 (1992)*.xlw
xlExcel539Excel 5.0 版 (1994)*.xls
xlExcel739Excel 95 (7.0 版)*.xls
xlExcel856Excel 97-2003 活頁簿*.xls
xlExcel979543Excel 95 與 97 版*.xls
xlHtml44HTML 格式.htm;.html
xlIntlAddIn得到國際增益集沒有副檔名
xlIntlMacro0.25國際巨集沒有副檔名
xlOpenDocumentSpreadsheet60OpenDocument 試算表*.ods
xlOpenXMLAddIn55開啟 XML 增益集*.xlam
xlOpenXMLStrictWorkbook61 (&H3D)Strict Open XML 檔案*.xlsx
xlOpenXMLTemplate54開啟 XML 範本*.xltx
xlOpenXMLTemplateMacroEnabled53開啟 Open XML 範本巨集啟用*.xltm
xlOpenXMLWorkbook51開啟 XML 活頁簿*.xlsx
xlOpenXMLWorkbookMacroEnabled52開啟 XML 活頁簿巨集啟用*.xlsm
xlSYLK符號連結格式*.slk
xlTemplate17Excel 範本格式*.xlt
xlTemplate817範本 8*.xlt
xlTextMac19Macintosh 文字*.txt
xlTextMSDOS21MSDOS 文字*.txt
xlTextPrinter36印表機文字*.prn
xlTextWindowsWindows 文字*.txt
xlUnicodeText42Unicode 文字沒有副檔名;*.txt
xlWebArchive45Web 封存.mht;.mhtml
xlWJ2WD114日文 1-2-3*.wj2
xlWJ340日文 1-2-3*.wj3
xlWJ3FJ341日文 1-2-3 格式*.wj3
xlWK15Lotus 1-2-3 格式*.wk1
xlWK1ALLLotus 1-2-3 格式*.wk1
xlWK1FMT大約Lotus 1-2-3 格式*.wk1
xlWK315Lotus 1-2-3 格式*.wk3
xlWK3FM332Lotus 1-2-3 格式*.wk3
xlWK438Lotus 1-2-3 格式*.wk4
xlWKS4Lotus 1-2-3 格式*.wks
xlWorkbookDefault51預設活頁簿*.xlsx
xlWorkbookNormal-4143一般活頁簿*.xls
xlWorks2FarEastMicrosoft Works 2.0 遠東格式*.wks
xlWQ134Quattro Pro 格式*.wq1
xlXMLSpreadsheet46XML 試算表*.xml


2022年1月19日 星期三

在Delphi中打印各种已知类型的文件

  uses shellapi, printers;
 
  procedure PrintDocument(const documentToPrint : string) ;
  var
    printCommand : string;
    printerInfo : string;
    Device, Driver, Port: array[0..255] of Char;
    hDeviceMode: THandle;
  begin
    if Printer.PrinterIndex = cboPrinter.ItemIndex then
    begin
      printCommand := 'print';
      printerInfo := '';
    end
    else
    begin
      printCommand := 'printto';
      Printer.PrinterIndex := cboPrinter.ItemIndex;
      Printer.GetPrinter(Device, Driver, Port, hDeviceMode) ;
      printerInfo := Format('"%s" "%s" "%s"', [Device, Driver, Port]) ;
    end;
 
    ShellExecute(Application.Handle, 
      PChar(printCommand), 
      PChar(documentToPrint), 
      PChar(printerInfo), 
      nil, 
      SW_HIDE) ;
  end;

2021年12月29日 星期三

Flutter DropdownButton / DropdownButtonFormField 下拉選單

 

DropdownButton


import 'package:flutter/material.dart';

class dropdownButton extends StatefulWidget {
@override
_dropdownButtonState createState() => _dropdownButtonState();
}

class _dropdownButtonState extends State<dropdownButton> {
List<DropdownMenuItem<String>> listDrop = [];
String selected = "1";

void loadData() {
listDrop = [];
listDrop.add(DropdownMenuItem(child: Text("item 1"), value: "1"));
listDrop.add(DropdownMenuItem(child: Text("item 2"), value: "2"));
listDrop.add(DropdownMenuItem(child: Text("item 3"), value: "3"));
listDrop.add(DropdownMenuItem(child: Text("item 4"), value: "4"));
listDrop.add(DropdownMenuItem(child: Text("item 5"), value: "5"));
}

@override
Widget build(BuildContext context) {
loadData();

return Scaffold(
body: Center(
child: Column(children: [
DropdownButton(
dropdownColor: Colors.amber,
style: TextStyle(color: Colors.white,),
icon: Icon(Icons.arrow_drop_down_circle),
elevation: 36,
items: listDrop,
value: selected,
hint: Text("Select item..."),
onChanged: (String? newValue) {
setState(() {
selected = newValue!;
});
},
),
]),
));
}
}


DropdownButtonFormField


import 'package:flutter/material.dart';
import 'package:untitled/Constants.dart';

class dropdownButton extends StatefulWidget {
@override
_dropdownButtonState createState() => _dropdownButtonState();
}

class _dropdownButtonState extends State<dropdownButton> {
List<DropdownMenuItem<String>> listDrop = [];
String selected = "1";

void loadData() {
listDrop = [];
listDrop.add(DropdownMenuItem(child: Text("item 1"), value: "1"));
listDrop.add(DropdownMenuItem(child: Text("item 2"), value: "2"));
listDrop.add(DropdownMenuItem(child: Text("item 3"), value: "3"));
listDrop.add(DropdownMenuItem(child: Text("item 4"), value: "4"));
listDrop.add(DropdownMenuItem(child: Text("item 5"), value: "5"));
}

@override
Widget build(BuildContext context) {
loadData();

void Function() Button_OnClick = () {
Navigator.pop(context);
};

return Scaffold(
backgroundColor: appGreyColor,
body: Center(
child: Column(children: [
DropdownButtonFormField(
decoration: InputDecoration(
icon: Icon(Icons.bug_report),
labelText: "Select item...",
labelStyle: TextStyle(
color: Colors.black,
),
contentPadding: EdgeInsets.fromLTRB(20.0, 10.0, 20.0, 10.0),
border: OutlineInputBorder(
borderRadius: BorderRadius.circular(32.0),
),
hintStyle: TextStyle(
color: Colors.white,
),
),
style: TextStyle(
color: Colors.white,
),
items: listDrop,
onChanged: (String? newValue) {
setState(() {
selected = newValue!;
});
},
dropdownColor: appBackgroundGreyColor,
icon: Icon(Icons.arrow_drop_down_circle, color: Colors.white,),
),
]),
));
}
}



2021年12月16日 星期四

Flutter warning: [deprecation] get(int,int) in CamcorderProfile has been deprecated 排除

 

warning: [deprecation] get(int,int) in CamcorderProfile has been deprecated 排除

compileSdkVersion = 31
targetSdkVersion = 31

image



截錄:


Flutter Error: Cannot run with sound null safety, because the following dependencies 排除


Error: Cannot run with sound null safety, because the following dependencies 


Copy: --no-sound-null-safety

enter image description here


enter image description here



截錄


Flutter 拍照

 

添加相關依賴套件 (dependencies)

在調用照相機前,我們會需要將下列三個相關依賴添加於 pubspec.yaml 當中。
camera: 提供與設備照相機相關工具
path_provider: 查詢正確路徑儲存照片
path: 建立在任何平台上都可運作的路徑
dependencies:
flutter:
sdk: flutter
camera:
path_provider:
path:


根據 Flutter 官方教學文件

Tip:

  • For android, You must have to update minSdkVersion to 21 (or higher).
  • On iOS, lines below have to be added inside ios/Runner/Info.plist in order the access the camera.
  • <key>NSCameraUsageDescription</key>
    <string>Explanation on why the camera access is needed.</string>


minSdkVersion 必須在21以上

為了解決這個問題,我們必須修改 Flutter 專案中 Android 的最低 SDK 版本。

在 Flutter 專案中,我們要修改的文件路徑為 PROJECT_NAME/android/app/build.gradle

def localProperties = new Properties()
def localPropertiesFile = rootProject.file('local.properties')
if (localPropertiesFile.exists()) {
localPropertiesFile.withReader(
'UTF-8') { reader ->
localProperties.load(reader)
}
}

def flutterRoot = localProperties.getProperty('flutter.sdk')
if (flutterRoot == null) {
throw new GradleException("Flutter SDK not found. Define location with flutter.sdk in the local.properties file.")
}

def flutterVersionCode = localProperties.getProperty('flutter.versionCode')
if (flutterVersionCode == null) {
flutterVersionCode =
'1'
}

def flutterVersionName = localProperties.getProperty('flutter.versionName')
if (flutterVersionName == null) {
flutterVersionName =
'1.0'
}

apply
plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply from: "$flutterRoot/packages/flutter_tools/gradle/flutter.gradle"

android {
compileSdkVersion flutter.compileSdkVersion

compileOptions
{
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}

kotlinOptions {
jvmTarget = '1.8'
}

sourceSets {
main.java.srcDirs += 'src/main/kotlin'
}

defaultConfig {
// TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html).
applicationId "com.example.untitled"
minSdkVersion 21 //flutter.minSdkVersion
targetSdkVersion 30 //flutter.targetSdkVersion
versionCode flutterVersionCode.toInteger()
versionName flutterVersionName
}

buildTypes {
release {
// TODO: Add your own signing config for the release build.
// Signing with the debug keys for now, so `flutter run --release` works.
signingConfig signingConfigs.debug
}
}
}

flutter {
source '../..'
}

dependencies {
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
}

將minSdkVersion 修改為 21(或任何你需要的版本號)


main.dart

import 'package:flutter/material.dart';
import 'package:untitled1/TakePictureScreen.dart';

void main() {
runApp(MyApp());
}

class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(
body: _mainbody(),
),
);
}
}

class _mainbody extends StatelessWidget {
@override
Widget build(BuildContext context) {
return Center(
child: RaisedButton(
child: Text("Camera"),
onPressed: () {
takePictureScreen_main();
},
),
);
}
}


TakePictureScreen.dart

import 'dart:async';
import 'dart:io';
import 'package:camera/camera.dart';
import 'package:flutter/material.dart';

Future<void> takePictureScreen_main() async {
// Ensure that plugin services are initialized so that `availableCameras()`
// can be called before `runApp()`
WidgetsFlutterBinding.ensureInitialized();

// Obtain a list of the available cameras on the device.
final cameras = await availableCameras();

// Get a specific camera from the list of available cameras.
final firstCamera = cameras.first;

runApp(
MaterialApp(
theme: ThemeData.dark(),
home: TakePictureScreen(
// Pass the appropriate camera to the TakePictureScreen widget.
camera: firstCamera,
),
),
);
}

// A screen that allows users to take a picture using a given camera.
class TakePictureScreen extends StatefulWidget {
const TakePictureScreen({
Key? key,
required this.camera,
}) : super(key: key);

final CameraDescription camera;

@override
TakePictureScreenState createState() => TakePictureScreenState();
}

class TakePictureScreenState extends State<TakePictureScreen> {
late CameraController _controller;
late Future<void> _initializeControllerFuture;

@override
void initState() {
super.initState();
// To display the current output from the Camera,
// create a CameraController.
_controller = CameraController(
// Get a specific camera from the list of available cameras.
widget.camera,
// Define the resolution to use.
ResolutionPreset.medium,
);

// Next, initialize the controller. This returns a Future.
_initializeControllerFuture = _controller.initialize();
}

@override
void dispose() {
// Dispose of the controller when the widget is disposed.
_controller.dispose();
super.dispose();
}

@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(title: const Text('Take a picture')),
// You must wait until the controller is initialized before displaying the
// camera preview. Use a FutureBuilder to display a loading spinner until the
// controller has finished initializing.
body: FutureBuilder<void>(
future: _initializeControllerFuture,
builder: (context, snapshot) {
if (snapshot.connectionState == ConnectionState.done) {
// If the Future is complete, display the preview.
return CameraPreview(_controller);
} else {
// Otherwise, display a loading indicator.
return const Center(child: CircularProgressIndicator());
}
},
),
floatingActionButton: FloatingActionButton(
// Provide an onPressed callback.
onPressed: () async {
// Take the Picture in a try / catch block. If anything goes wrong,
// catch the error.
try {
// Ensure that the camera is initialized.
await _initializeControllerFuture;

// Attempt to take a picture and get the file `image`
// where it was saved.
final image = await _controller.takePicture();

// If the picture was taken, display it on a new screen.
await Navigator.of(context).push(
MaterialPageRoute(
builder: (context) => DisplayPictureScreen(
// Pass the automatically generated path to
// the DisplayPictureScreen widget.
imagePath: image.path,
),
),
);
} catch (e) {
// If an error occurs, log the error to the console.
print(e);
}
},
child: const Icon(Icons.camera_alt),
),
);
}
}

// A widget that displays the picture taken by the user.
class DisplayPictureScreen extends StatelessWidget {
final String imagePath;

const DisplayPictureScreen({Key? key, required this.imagePath})
: super(key: key);

@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(title: const Text('Display the Picture')),
// The image is stored as a file on the device. Use the `Image.file`
// constructor with the given path to display the image.
body: Image.file(File(imagePath)),
);
}
}


參考:

截錄 :