2017-12-08 5 views
1

Oracleテーブルからイメージを読み込み、XMLイメージのソースとして使用して後でレポートの一部として印刷しようとしています。私はちょうど良いデータベースから画像を読むことができます。イメージのソースとして設定してからページを印刷しようとすると、そのページは空白になります。ここ ビジュアル基本コードビハインドのXMLイメージにOracle HugeBlobイメージをロードする

画像が読み取られた後VBコードです:
(HugeBlobは、DataReaderの(DR2)によって取得最初のアイテムであるので、(0)dr2.Itemとして参照される)

'Convert the HugeBlob to base64 string 
Dim MyImageString As String = Convert.ToBase64String(dr2.Item(0)) 

'Convert the base64 string to a byte array 
Dim b() As Byte = Convert.FromBase64String(MyImageString) 

'Create a memory stream 
Dim MS As System.IO.MemoryStream = New System.IO.MemoryStream 

'Load the memory stream from the byte array 
MS = New System.IO.MemoryStream(b) 

'Create a bitmap image 
Dim bmi As New BitmapImage 
bmi.BeginInit() 

'Load the memory stream into the bitmap image 
bmi.StreamSource = MS 

'Set the bitmap image as the source for the xml image 
PP7.Image.Stretch = Stretch.Fill 
PP7.Image.Source = bmi 

ここではXMLのページがあります:

<FlowDocument x:Class="PrintPreview7Image" 
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
    xmlns:sys="clr-namespace:System;assembly=mscorlib" 
    xmlns:local="clr-namespace:PrintAccidentXPSForms" 
    FontFamily="Arial" 
    RenderOptions.BitmapScalingMode="HighQuality" 
    PagePadding="0" PageWidth="816" PageHeight="1056" 
    Name="PrintPreview7Image"> 
    <BlockUIContainer Name="MainBlock" BreakPageBefore="True" Margin="5,0,0,0"> 
     <Grid Width="816"> 
      <Grid.RowDefinitions> 
       <RowDefinition Height="Auto" /> 
      </Grid.RowDefinitions> 
      <Grid.ColumnDefinitions> 
       <ColumnDefinition Width="Auto" /> 
      </Grid.ColumnDefinitions> 
       <Image Name="Image" Height="1056" Width="816"  Grid.Row="0"  Grid.Column="0"/> 
     </Grid> 
    </BlockUIContainer> 
</FlowDocument> 
+0

をインスタンス化した後

bmi.BeginInit() bmi.CacheOption = BitmapCacheOption.OnLoad bmi.StreamSource = MS bmi.EndInit() 

:(!闘争の週間後)私がしなければならなかったすべては、これらの行を追加しましたイメージへのパス。実際のイメージバイトはどこですか? – jdweng

+0

jdweng - PrintPreview7Imageは、コードビハインド内のクラスとして使用されます。これはPP7としてインスタンス化されます。私はデータバインディングを使ってイメージソースを設定することができたと思いますが、イメージを印刷する方法を見つけた後もまだそれを行うことができます。 – Jerry

+0

ストレッチがPrintPreview7Imageにどのように接続されていますか?データが空であるように見えます。 – jdweng

答えて

0

このコードはSQLServerのためですが、私はそれがあなたの問題に適応可能かもしれないと思いました。私はおそらくSOからこのコードを盗んだが、私は覚えていないので、適切な帰属を与えることができない。

Dim command As New SqlCommand("SELECT Picture FROM MyTable WHERE ID = 1", connection) 

connection.Open() 

Dim pictureData As Byte() = DirectCast(command.ExecuteScalar(), Byte()) 

connection.Close() 

Dim picture As Image = Nothing 

'Create a stream in memory containing the bytes that comprise the image. 
Using stream As New IO.MemoryStream(pictureData) 
    'Read the stream and create an Image object from the data. 
    picture = Image.FromStream(stream) 
End Using 
+0

動作しません。 IO.MemoryStreamにはFromStreamメソッドがありません。 – Jerry

+0

"FromStreamは 'System.Windows.Controls.Image'のメンバーではないというエラーメッセージが表示されます – Jerry

+0

ファイルの先頭にSystem.Drawingをインポートしてみてください。 – Mary

0

私は答えを見つけました!!!!!!! XMLは、プリンタのヘッダ情報であるが、私は任意の画像データが表示されないかのBitmapImage

関連する問題