我正在尝试使用带有CF的WinForm上的应用程序使用SQLite保存和加载图像.我找到了一种方法将图像保存到数据库中,但我不知道它是否正确,因为我找不到加载存储在数据库中的图像的方法.
我有一个代码将我的图像转换为Base64:
public void ImageToBase64(Image image, System.Drawing.Imaging.ImageFormat format){
using (MemoryStream ms = new MemoryStream()){
// Convert Image to byte[]
image.Save(ms, format);
byte[] imageBytes = ms.ToArray();
// Convert byte[] to Base64 String
string base64String = Convert.ToBase64String(imageBytes);
SaveImage(base64String);
}
}
Run Code Online (Sandbox Code Playgroud)
这是我将图像保存到db中的代码:
void SaveImage(string pic){
string query = "insert into Table (Photo) values (@pic);";
string conString = @" Data Source = \Program Files\Users.s3db ";
SQLiteConnection con = new SQLiteConnection(conString);
SQLiteCommand cmd = new SQLiteCommand(query, con);
cmd.Parameters.Add("@pic",DbType.String);
con.Open();
try{
cmd.ExecuteNonQuery();
}
catch (Exception exc1){ …Run Code Online (Sandbox Code Playgroud) 我在Windows应用程序中使用SQLite,现在我在Xamarin开发一个便携式应用程序,所以我使用插件sqlite net pcl,我很难理解它是如何工作的.
我有一个由以下te创建的表:
public class Config
{
public string IP { get; set; }
[SQLite.Net.Attributes.Default(true, "Client 2")]
public string ID { get; set; }
}
Run Code Online (Sandbox Code Playgroud)
并创建表:
db.CreateTable<Model.Config>();
Run Code Online (Sandbox Code Playgroud)
问题:现在我想在ID列中选择值,然后执行以下操作:
List<string> hhid = db.Query<string>("select ID from Config",null);
Run Code Online (Sandbox Code Playgroud)
我得到这个例外: "Object reference not set to an instance of an object"
如何进行简单的选择以找到此字段?
谢谢你的提示
我有我的应用程序,并希望它以全屏模式运行,没有任务栏.我发现了如何隐藏窗口栏,但是当我启动我的应用程序时,它不会覆盖Windows任务栏的空间,尽管最后一个是隐藏的.
我发现了这个,但它没有用.我无法找到关于wince的例子.我有FormBorderStyle = None,而WindowsState =最大化
解:
我找到了一种方法.一个重要的提示是让WindowState = Normal(我花了一些时间才发现这个问题).如果您有WindowState = Maximized,则无法将Form的高度设置为最大显示高度.
我写了这段代码来探测它,它工作正常.是一个带有两个按钮的表单:button1(全屏)和button2(恢复默认屏幕)
public partial class Form1 : Form
{
public Form1(){
InitializeComponent();
}
[DllImport("Coredll")]
internal static extern IntPtr FindWindow(String lpClassName, String lpWindowName);
[DllImport("coredll.dll")]
internal static extern bool EnableWindow(IntPtr hwnd, Boolean bEnable);
[DllImport("coredll.dll")]
private static extern bool MoveWindow(IntPtr hWnd, int x, int y, int cx, int cy, bool repaint);
public static bool EnableTaskBar(Boolean enable)
{
IntPtr hwnd;
hwnd = FindWindow("HHTaskBar", "");
if (enable) …Run Code Online (Sandbox Code Playgroud) 如果我的字符串中是否有反斜杠,我如何比较?
我不知道如何编写反斜杠符号来比较它.我尝试这个但不起作用:
码:
s = r"\""
print s
Run Code Online (Sandbox Code Playgroud)
输出: \"
如果我尝试s = "\""它"作为输出
我不知道如何实现这一点.
谢谢你的帮助.
我在方法中动态创建标签"label1".然后,当我单击一个按钮时,我想删除创建的标签,但是如果我编写Controls.Remove(label1),则表示该控件在上下文中不存在.我怎么能做到这一点?
编辑:按照Jon的建议,我实现了foreach循环,但它没有做任何事情.这是我的代码,我使用的面板是由设计创建的:
void GenerateControls() {
Label labelOne = new Label();
Button btnContinue = new Button();
panel.SuspendLayout();
SuspendLayout();
//btnContinue
btnContinue.BackColor = System.Drawing.Color.Black;
btnContinue.ForeColor = System.Drawing.SystemColors.Menu;
btnContinue.Location = new System.Drawing.Point(145, 272);
btnContinue.Name = "btnContinue";
btnContinue.Size = new System.Drawing.Size(95, 28);
btnContinue.TabIndex = 13;
btnContinue.Text = "Continue";
btnContinue.Visible = true;
Controls.Add(btnContinue);
btnContinue.Click += new System.EventHandler(btnContinue_Click);
//labelOne
labelOne.Location = new Point(0,65);
labelOne.Size = new System.Drawing.Size(100,20);
labelOne.Text = "labelOne";
labelOne.Name = "labelOne";
labelOne.Visible = true;
labelOne.TextChanged += new System.EventHandler(this.lbl_TextChanged);
labelOne.BackColor = …Run Code Online (Sandbox Code Playgroud) 我知道这个问题已被提出,但我的问题比我见过的其他问题更为普遍.
当我在我的程序中检查我使用控件Forms和命令DB(命令,读者等)时,我遇到了以下问题:
如果我有一个控制器,Dispose我使用后不应该使用它吗?
这样我将确保我的程序只使用所需的资源,如果我必须使用已经处理的控件,那么我将再次加载它.
也许有理由不总是处理所有事情,但这就是我问这个问题的原因.
谢谢你的回答,我希望我能说清楚.
我在移动设备和PC(服务器)之间进行客户端 - 服务器通信.在通信中我有四个插座:其中两个用于发送和接收数据,另外两个用于某种保持活动,因为我需要尽可能快地检测断开连接.
只要连接正常,数据就会毫无问题地传输.但我想建立一些优先级,以确保keep alive(记住:两个套接字)通道始终发送数据,除非服务器 - 客户端之间的连接已经死亡.
我怎样才能做到这一点?
谢谢你的帮助.
我需要使用Xamarin Forms PCL访问相机.我找不到任何可行的样本.
我尝试安装XLab并使用其示例代码,但它有例外.例如,使用XLabs示例我使用以下内容:
/// <summary>
/// Takes the picture.
/// </summary>
/// <returns>Take Picture Task.</returns>
internal async Task<MediaFile> TakePicture()
{
Setup();
ImageSource = null;
return await _mediaPicker.TakePhotoAsync(new CameraMediaStorageOptions { DefaultCamera = CameraDevice.Front, MaxPixelDimension = 400 }).ContinueWith(t =>
{
if (t.IsFaulted)
{
Status = t.Exception.InnerException.ToString();
}
else if (t.IsCanceled)
{
Status = "Canceled";
}
else
{
var mediaFile = t.Result;
ImageSource = ImageSource.FromStream(() => mediaFile.Source);
return mediaFile;
}
return null;
}, _scheduler);
}
/// <summary>
/// Setups this …Run Code Online (Sandbox Code Playgroud) 我有这个简单的例子,我无法编译:
三个文件:my.h,my.cpp和use.cpp:
//my.h
extern int foo;
void print_foo();
void print(int);
Run Code Online (Sandbox Code Playgroud)
//my.cpp
#include "my.h"
#include "../../stb_lib_facilities.h" //inlcudes cout, cin, etc
void print_foo(){
cout << foo << endl;
}
void print(int i){
cout << i << endl;
}
Run Code Online (Sandbox Code Playgroud)
//use.cpp
#include <iostream>
#include "my.h"
int main(){
foo = 7;
print_foo();
print(99);
return 0;
}
Run Code Online (Sandbox Code Playgroud)
当我尝试编译它时,我得到三个错误:LNK2001:extern"int foo".. LNK2019:extern"int foo".. LNK1120:
我究竟做错了什么?谢谢你的帮助