1

私は Teensy 3.2 を所有しており、それにバッチ ファイルを保存したいと考えています。Teensyには2kbのEEPROMがあり、そこに保存できることがわかりました。

バッチ ファイルは.exe、コンパイル済みの C# を内部に含むファイルを生成しています。

しかし今、私は2つの問題を抱えています:

  1. バッチファイルが大きすぎます (3.37kb)。小さくする方法はありますか?
  2. そのファイルを Teensy に転送し (適切なサイズがある場合)、必要に応じてコンピューターに再転送するにはどうすればよいですか? メソッドとしてしか見つけることができませんEEPROM.write()が、単一バイトだけでなくファイルを転送したいので、これはうまくいかないようですか?

バッチのコードは次のとおりです。

// 2>nul||@goto :batch
/*
:batch
@echo off
setlocal
set "csc="
for /r "%SystemRoot%\Microsoft.NET\Framework\" %%# in ("*csc.exe") do  set "csc=%%#"
if not exist "%~n0.exe" (
   call %csc% /nologo /r:"Microsoft.VisualBasic.dll" /out:"%~n0.exe" "%~dpsfnx0" || (
      exit /b %errorlevel% 
   )
)
%~n0.exe %*
endlocal & exit /b %errorlevel%
*/
using System;
using System.Runtime.InteropServices;
using System.Drawing;
using System.Drawing.Imaging;
using System.Collections.Generic;
public class ScreenCapture
{
    private Image CaptureWindow()
    {
        IntPtr handle = User32.GetDesktopWindow();
        IntPtr hdcSrc = User32.GetWindowDC(handle);
        User32.RECT windowRect = new User32.RECT();
        User32.GetWindowRect(handle, ref windowRect);
        int width = windowRect.right - windowRect.left;
        int height = windowRect.bottom - windowRect.top;
        IntPtr hdcDest = GDI32.CreateCompatibleDC(hdcSrc);
        IntPtr hBitmap = GDI32.CreateCompatibleBitmap(hdcSrc, width, height);
        IntPtr hOld = GDI32.SelectObject(hdcDest, hBitmap);
        GDI32.BitBlt(hdcDest, 0, 0, width, height, hdcSrc, 0, 0, GDI32.SRCCOPY);
        GDI32.SelectObject(hdcDest, hOld);
        GDI32.DeleteDC(hdcDest);
        User32.ReleaseDC(handle, hdcSrc);
        Image img = Image.FromHbitmap(hBitmap);
        GDI32.DeleteObject(hBitmap);
        return img;
    }
    public void CaptureScreenToFile(string filename)
    {
        Image img = CaptureWindow();
        img.Save(filename, System.Drawing.Imaging.ImageFormat.Jpeg);
    }
    public static void Main()
    {
        String[] arguments = Environment.GetCommandLineArgs();
        if (arguments.Length == 1)
            Environment.Exit(0);
        String file = arguments[1];
        ScreenCapture sc = new ScreenCapture();
        sc.CaptureScreenToFile(file);
    }
    private class GDI32
    {
        public const int SRCCOPY = 0x00CC0020;
        [DllImport("gdi32.dll")]
        public static extern bool BitBlt(IntPtr hObject, int nXDest, int nYDest,
          int nWidth, int nHeight, IntPtr hObjectSource,
          int nXSrc, int nYSrc, int dwRop);
        [DllImport("gdi32.dll")]
        public static extern IntPtr CreateCompatibleBitmap(IntPtr hDC, int nWidth,
          int nHeight);
        [DllImport("gdi32.dll")]
        public static extern IntPtr CreateCompatibleDC(IntPtr hDC);
        [DllImport("gdi32.dll")]
        public static extern bool DeleteDC(IntPtr hDC);
        [DllImport("gdi32.dll")]
        public static extern bool DeleteObject(IntPtr hObject);
        [DllImport("gdi32.dll")]
        public static extern IntPtr SelectObject(IntPtr hDC, IntPtr hObject);
    }
    private class User32
    {
        [StructLayout(LayoutKind.Sequential)]
        public struct RECT
        {
            public int left;
            public int top;
            public int right;
            public int bottom;
        }
        [DllImport("user32.dll")]
        public static extern IntPtr GetDesktopWindow();
        [DllImport("user32.dll")]
        public static extern IntPtr GetWindowDC(IntPtr hWnd);
        [DllImport("user32.dll")]
        public static extern IntPtr ReleaseDC(IntPtr hWnd, IntPtr hDC);
        [DllImport("user32.dll")]
        public static extern IntPtr GetWindowRect(IntPtr hWnd, ref RECT rect);
    }
}

編集: コードは十分に小さくなりました (約 1.73kb) が、Teensy に転送する方法がまだわかりません。助けてください。

4

1 に答える 1