2015-11-03 10 views
1

我有椅子的二維數組是這樣的:chairs[][]也在這裏是我的椅子類:從WCF web服務對象的數組創建的圖像陣列

public class Chair 
{ 
    public int State; 
    public int number; 
} 

類的每一個對象在劇場代表席位(狀態表示座位狀態; 0表示空,1表示保留,數字表示座位號)。

讓我們假設我有這些值:

0 0 0 1 
    1 1 1 0 
    0 1 0 1 

我想這樣創建圖像的數組:

enter image description here

,並最終將其轉換爲字節數組並返回它作爲Web服務輸出。 長話短說我想將chair[][]的數組轉換爲圖像。我的網絡服務輸入將爲chairs[][],輸出將爲byte[]

這可能嗎?

UPDATE

在這裏,我創建在Windows桌面應用程序的東西。我只需要在wcf中創建它。我現在想到如何在wcf中創建PictureboxLabal

{ 
    AutoScroll = true; 
    int x = 10, y = 10; 

    Chair[][] chairs = new Chair[3][]; 
    chairs[0] = new Chair[4] { new Chair { number = 1, State = 0 }, new Chair { number = 2, State = 0 }, new Chair { number = 3, State = 0 }, new Chair { number = 4, State = 1 } }; 
    chairs[1] = new Chair[4] { new Chair { number = 5, State = 1 }, new Chair { number = 6, State = 1 }, new Chair { number = 7, State = 1 }, new Chair { number = 8, State = 0 } }; 
    chairs[2] = new Chair[4] { new Chair { number = 9, State = 0 }, new Chair { number = 10, State = 1 }, new Chair { number = 11, State = 0 }, new Chair { number = 12, State = 1 } }; 

    Label[][] label = new Label[chairs.Length][]; 
    PictureBox[][] picturebox = new PictureBox[chairs.Length][]; 

    for (int i = 0; i < chairs.Length; i++) 
    { 
     label[i] = new Label[chairs[i].Length]; 
     picturebox[i] = new PictureBox[chairs[i].Length]; 


     for (int j = 0; j < chairs[i].Length; j++) 
     { 
      label[i][j] = new Label(); 
      picturebox[i][j] = new PictureBox(); 

      Controls.Add(label[i][j]); 
      Controls.Add(picturebox[i][j]); 

      label[i][j].Location = new Point(x, y + 50); 
      picturebox[i][j].Location = new Point(x, y); 

      label[i][j].Size = new Size(100, 20); 
      picturebox[i][j].Size = new Size(50, 50); 

      label[i][j].Text = i + "*" + j + "(" + chairs[i][j].number + ")"; 
      if (chairs[i][j].State == 0) picturebox[i][j].Image = Image.FromFile(@"C:\Users\Admin\Desktop\1\1.png"); 
      else picturebox[i][j].Image = Image.FromFile(@"C:\Users\Admin\Desktop\1\2.png"); 

      x = x + 100; 
     } 
     x = 10; 
     y = y + 100; 
    } 
+1

它是確定你,如果椅子是序列化在網絡上,被傳遞到Web服務或Web服務返回的? –

+0

親愛的@Emmanuel老實說,我沒有明白你的要求。但長話短說,我想將類的數組轉換爲圖像。我的Web服務輸入是椅子[] [],輸出是字節[]。我希望我能解釋它。 – David

+1

您可以編輯和刪除有關愚蠢問題的句子(它們不存在)。但是我們理解這一點很重要!你期望在字節[]中有什麼? ...一些PNG圖片...? –

回答

1
string firstText = "Hello"; 
string secondText = "World"; 

PointF firstLocation = new PointF(10f, 10f); 
PointF secondLocation = new PointF(10f, 50f); 

string imageFilePath = @"path\picture.bmp" 
Bitmap bitmap = (Bitmap)Image.FromFile(imageFilePath);//load the image file 

using(Graphics graphics = Graphics.FromImage(bitmap)) 
{ 
    using (Font arialFont = new Font("Arial", 10)) 
    { 
     graphics.DrawString(firstText, arialFont,Brushes.Blue,firstLocation); 
     graphics.DrawString(secondText,arialFont,Brushes.Red,secondLocation); 
    } 
} 

bitmap.Save(imageFilePath);//save the image 
+0

試試這個,你可以創建2個模板 - 以「R」結束空椅子,離開數字空的地方,並嘗試這個代碼 –

+0

謝謝。這是我的答案。但如何可以把這個圖像的數組放在一個圖像?像我的問題中的形象? – David

+0

你可以在一列中創建一個大的空白圖像/位圖,其高度=陣列圖像的高度總和(例如,3行,每個圖像高度= 200像素,所以大圖像高度= 3 * 200 = 600,並且寬度也一樣),然後使用Graphics類在您的圖像上繪製每個圖像 –

1

首先 - https://msdn.microsoft.com/en-us/library/vstudio/ms734712(v=vs.100).aspx

然後

// Service side 
[ServiceContract(Name = "chairs-image-generator")] 
public interface IChairsImageArrayGenerator 
{ 
    // insted byte[] paste desirable type of image 
    [OperationContract(Name = "generate-images")] 
    IEnumerable<byte[]> GenerateImage(IEnumerable<byte[][]> chairs); 
} 

// Client side 
[ServiceContract(Name = "chairs-image-generator")] 
public interface IChairsImageArrayGeneratorClient 
{ 
    [OperationContract(Name = "generate-images")] 
    IEnumerable<byte[]> GenerateImages(IEnumerable<byte[][]> chairs); 
} 

public class ChairsImageGenerator : IChairsImageArrayGenerator 
{ 
    public IEnumerable<byte[]> GenerateImages(IEnumerable<byte[][]> chairs) 
    { 
     // put here your realization 
    } 
} 
+0

謝謝dear @ android_dev_123。但它不是我想要的!我想我清楚地解釋了我到底想要什麼。 – David

+1

告訴我更具體的問題 - 1)創建一個WCF服務2)從Chair類創建一個圖像?或與其他smth? –

+0

非常感謝你,從椅子班創造形象是我的關注。 – David