2015-11-05 27 views
0

我製作了一個用於從多個圖像合成圖像的系統。比方說,我有兩個圖像,我想組成一個圖像像這樣的:從asp.net中的多個圖像撰寫一個圖像並對它們進行裁剪

enter image description here

粗邊框定義了我想要的完整的圖像。這是一個分辨率爲600X540的div,裏面有兩個div,每個div都包含一張我可以定位的不同圖像。在定位結束時,我得到每個圖像的左邊界和上邊界(對應於整個div)。

我無法在後面的代碼中創建圖像。我正在使用Bitmap.DrawImage方法。這裏是我的代碼:

oImgOut = New System.Drawing.Bitmap(600, 540) 

oGraph = System.Drawing.Graphics.FromImage(oImgOut) 
oGraph.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.HighQualityBicubic 
oGraph.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality 
oGraph.CompositingQuality = System.Drawing.Drawing2D.CompositingQuality.HighQuality 
oGraph.PixelOffsetMode = System.Drawing.Drawing2D.PixelOffsetMode.HighQuality 
oGraph.FillRectangle(Drawing.Brushes.White, 0, 0, 600, 540) 

//image 1 
oGraph.DrawImage(oImg1, CInt(left1), CInt(top1), CInt(width1), CInt(height1)) 
oImg1.Dispose() 

//image2 
oGraph.DrawImage(oImg2, CInt(left2), CInt(top2), CInt(width2), CInt(height2)) 
oImg2.Dispose() 

oImgOut.Save(strDirectory) 
oImgOut.Dispose() 

這是我這麼遠:

enter image description here

我試着給每個圖像的300像素和540px高度的寬度,但正如你看到的右側圖像看起來醜陋:

enter image description here

我想知道如果有一種方法可以裁剪圖像?我查看了大多數DrawImage原型,但我找不到任何我想要的工作。當然你會比我更清楚。

任何人都可以幫助我嗎?

回答

0

我找到了一個解決方案,與drawImage方法

oGraph.DrawImage(oImg2, CInt(left2), CInt(top2), _ 
          New Rectangle(0, 0, _ 
              If(CInt(width2) > 600, 600, CInt(width2)), _ 
              If(CInt(height2) > 270, 270, CInt(height2)) + CInt(top2) _ 
              ), GraphicsUnit.Pixel) 

裁剪圖片,但我不明白它是如何工作的,請傢伙,我需要你的幫助:(。