try
{
Bitmap bm = new Bitmap(pics[ip]);
BitmapToBytes(bm).Reverse().Take(2);
}
catch (Exception ex)
{
string imgName = Path.GetFileName(pics[ip]);
File.Move(pics[ip], txtImgDir.Text + "\\badimg\\" + imgName);
}
public
static
byte
[] BitmapToBytes(Bitmap Bitmap)
{
try
{
using
(MemoryStream ms =
new
MemoryStream())
{
Bitmap.Save(ms, Bitmap.RawFormat);
byte
[] byteImage =
new
Byte[ms.Length];
byteImage = ms.ToArray();
return
byteImage;
}
}
finally
{
}
}
BitmapToBytes(img).Reverse().Take(2);
//然后判斷是不是217,255
|
以二進制文件打開文件. 讀取最后2個字節判斷一下.
或者讀取全部,從結尾處開始查找ffd9,找到了就表示OK.
有時候用相機網服務器傳圖片的時候,突然斷網,造成圖片不完整,都是上半部分是圖片,線板部分,不能預覽。怎樣用C#判斷圖片(jpg)是否完整
C#中Bitmap類實現對圖像操作的一些方法
導入以下兩個包:
System.Drawing;
System.Drawing.Imaging;
建產對象:
Bitmap bm = new Bitmap("c:/1.bmp");
縮放:
Bitmap bm1 = new Bitmap(bm,width,height);
格式轉換:
bm.save("c:/1.jpg",ImageFromat.Jpeg);
bm1.Save("c:/1.gif", ImageFormat.Gif);
剪切一個區域:
//剪切大小
int cutwidth;
int cutheight;
Graphics g;
//以大小為剪切大小,像素格式為32位RGB創建一個位圖對像
Bitmap bm1 = new Bitmap(width,height,PixelFormat.Format32bppRgb) ;
//定義一個區域
Rectangle rg = new Rectangle(0,0,cutwidth,cutheight);
//要繪制到的位圖
g = Graphics.FromImage(bm1);
//將bm內rg所指定的區域繪制到bm1
g.DrawImage(bm,rg)
============================================
C#Bitmap代替另一個Bitmap的某部分
Bitmap bm = new Bitmap(寬度, 高度);// 新建一個 Bitmap 位圖
System.Drawing.Graphics g = System.Drawing.Graphics.FromImage(bm); // 根據新建的 Bitmap 位圖,創建畫布
g.Clear(System.Drawing.Color.Black);// 使用黑色重置畫布
g.DrawImage(源位圖, ......); // 繪制“源位圖”,后面有若干參數控制大小、坐標等等功能。
Bitmap bm = new Bitmap(寬度, 高度);// 新建一個 Bitmap 位圖
System.Drawing.Graphics g = System.Drawing.Graphics.FromImage(bm); // 根據新建的 Bitmap 位圖,創建畫布
g.Clear(System.Drawing.Color.Black);// 使用黑色重置畫布
g.DrawImage(源位圖, ......); // 繪制“源位圖”,后面有若干參數控制大小、坐標等等功能。
==================================================
C# 圖片處理之:旋轉圖片任意角度
C# 圖片處理之:旋轉圖片任意角度



















































