Go Top

2019年2月12日 星期二

[英文學習] 2019.02.12 Dialy English - 你想要牛排幾分熟?

[英文學習] 2019.02.12 Dialy English - 你想要牛排幾分熟?

This article is quoted from 中英物語

今日挑戰 - 請中翻英
你想要牛排幾分熟?
解答
How do you like your steak cooked?

閱讀更多 »

2019年2月11日 星期一

[C#] OpenFileDialog Filter 所有圖檔


OpenFileDialog ofd = new OpenFileDialog();
ofd.Filter = 
@"All Image Files|*.bmp;*.ico;*.gif;*.jpeg;*.jpg;*.png;*.tif;*.tiff|
Windows Bitmap(*.bmp)|*.bmp|Windows Icon(*.ico)|*.ico|
Graphics Interchange Format (*.gif)|(*.gif)|
JPEG File Interchange Format (*.jpg)|*.jpg;*.jpeg|
Portable Network Graphics (*.png)|*.png|
Tag Image File Format (*.tif)|*.tif;*.tiff";
if (ofd.ShowDialog() == DialogResult.OK)
{
    ...
}

閱讀更多 »

[C#] Validate image from file

This article is quoted from https://stackoverflow.com/questions/210650/validate-image-from-file-in-c-sharp/210677

public enum ImageFormat
{
    bmp,
    jpeg,
    gif,
    tiff,
    png,
    unknown
}

public static ImageFormat GetImageFormat(byte[] bytes)
{
    // see http://www.mikekunz.com/image_file_header.html  
    var bmp    = Encoding.ASCII.GetBytes("BM");     // BMP
    var gif    = Encoding.ASCII.GetBytes("GIF");    // GIF
    var png    = new byte[] { 137, 80, 78, 71 };    // PNG
    var tiff   = new byte[] { 73, 73, 42 };         // TIFF
    var tiff2  = new byte[] { 77, 77, 42 };         // TIFF
    var jpeg   = new byte[] { 255, 216, 255, 224 }; // jpeg
    var jpeg2  = new byte[] { 255, 216, 255, 225 }; // jpeg canon

    if (bmp.SequenceEqual(bytes.Take(bmp.Length)))
        return ImageFormat.bmp;

    if (gif.SequenceEqual(bytes.Take(gif.Length)))
        return ImageFormat.gif;

    if (png.SequenceEqual(bytes.Take(png.Length)))
        return ImageFormat.png;

    if (tiff.SequenceEqual(bytes.Take(tiff.Length)))
        return ImageFormat.tiff;

    if (tiff2.SequenceEqual(bytes.Take(tiff2.Length)))
        return ImageFormat.tiff;

    if (jpeg.SequenceEqual(bytes.Take(jpeg.Length)))
        return ImageFormat.jpeg;

    if (jpeg2.SequenceEqual(bytes.Take(jpeg2.Length)))
        return ImageFormat.jpeg;

    return ImageFormat.unknown;
}
閱讀更多 »
Copyright © BCL BLOG | Powered by Blogger