XTextureSet Method |
Namespace: Pixoneer.NXDL.NGR
public bool Set( byte[] dibits, int width, int height, int nWidthBytes )
// XAML <Window x:Class="MemXTexture.MainWindow" xmlns = "http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x = "http://schemas.microsoft.com/winfx/2006/xaml" xmlns : d = "http://schemas.microsoft.com/expression/blend/2008" xmlns : mc = "http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns : nxImage = "clr-namespace:Pixoneer.NXDL.NXImage;assembly=NXImage" xmlns : local = "clr-namespace:MemXTexture" mc : Ignorable = "d" Title = "MainWindow" Height = "600" Width = "900" Loaded = "Window_Loaded" Closed = "Window_Closed" > <Grid> <Grid.ColumnDefinitions> <ColumnDefinition Width = "*" / > <ColumnDefinition Width = "*" / > < / Grid.ColumnDefinitions> <WindowsFormsHost Grid.Column = "0" Margin = "2,0,2,2"> <nxImage:NXImageView x : Name = "nxImageView1" MouseDown = "nxImageView1_MouseDown"> <nxImage:NXImageView.Controls> <nxImage:NXImageLayerComposites x : Name = "nxImageLayerComposites1" / > < / nxImage:NXImageView.Controls> < / nxImage:NXImageView> < / WindowsFormsHost> <WindowsFormsHost Grid.Column = "1" Margin = "2,0,2,2"> <nxImage:NXImageView x : Name = "nxImageView2"> <nxImage:NXImageView.Controls> <nxImage:NXImageLayerComposites x : Name = "nxImageLayerComposites2" / > <nxImage:NXImageLayerGPU x : Name = "nxImageLayerGPU2" OnOrthoRender = "nxImageLayerGPU2_OnOrthoRender" / > < / nxImage:NXImageView.Controls> < / nxImage:NXImageView> < / WindowsFormsHost> < / Grid> < / Window> // C# using Pixoneer.NXDL; using Pixoneer.NXDL.NGR; using Pixoneer.NXDL.NIO; using Pixoneer.NXDL.NRS; using Pixoneer.NXDL.NXImage; using System; using System.Collections.Generic; using System.Drawing; using System.Drawing.Imaging; using System.IO; using System.Linq; using System.Text; using System.Windows; using System.Windows.Controls; using System.Windows.Data; using System.Windows.Documents; using System.Windows.Input; using System.Windows.Media; using System.Windows.Media.Imaging; using System.Windows.Navigation; using System.Windows.Shapes; namespace MemXTexture { public partial class MainWindow : Window { public XRasterIO RasterIO = new XRasterIO(); public XRSLoadFile LoadFile = null; public XTexture CompTexture = new XTexture(); public const int ImgWidth = 200; public const int ImgHeight = 200; public int BmpWidth = ImgWidth * 2; public int BmpHeight = ImgHeight * 2; public MainWindow() { InitializeComponent(); // IO initialize to load image file string strError = ""; if (RasterIO.Initialize(out strError) == false) { return; } } private void Window_Loaded(object sender, RoutedEventArgs e) { string strError = ""; // Image load string strFilePathLoad = @"E:\SampleImage\Test.xdm"; XRSLoadFile xrsFileInput = RasterIO.LoadFile(strFilePathLoad, out strError, false, eIOCreateXLDMode.All_NoMsg); SetComposite(xrsFileInput); if (LoadFile != null) LoadFile.Dispose(); LoadFile = xrsFileInput; } private void Window_Closed(object sender, EventArgs e) { if (LoadFile != null) LoadFile.Dispose(); Xfn.Close(); System.GC.Collect(); System.GC.WaitForPendingFinalizers(); } private bool nxImageLayerGPU2_OnOrthoRender(NXImageLayerGPU sender, NXImageViewDrawArgs DrawArgs) { XGraphics g = DrawArgs.Graphics; g.glDisable(XGraphics.GL_DEPTH_TEST); g.glEnable(XGraphics.GL_BLEND); g.glBlendFunc(XGraphics.GL_SRC_ALPHA, XGraphics.GL_ONE_MINUS_SRC_ALPHA); g.glEnable(XGraphics.GL_TEXTURE_2D); g.glColor4d(1.0f, 1.0f, 1.0f, 1.0f); if (CompTexture != null) { if (!CompTexture.InDevice) { CompTexture.SendTextureToDevice(); } g.glBindTexture(XGraphics.GL_TEXTURE_2D, (uint)CompTexture.GLTextureID); } double scrCx = nxImageView2.Width / 2.0; double scrCy = nxImageView2.Height / 2.0; g.glBegin(XGraphics.GL_QUADS); g.glTexCoord2f(0, 1); g.glVertex2d(scrCx - BmpWidth / 2.0, scrCy - BmpHeight / 2.0); g.glTexCoord2f(0, 0); g.glVertex2d(scrCx - BmpWidth / 2.0, scrCy + BmpHeight / 2.0); g.glTexCoord2f(1, 0); g.glVertex2d(scrCx + BmpWidth / 2.0, scrCy + BmpHeight / 2.0); g.glTexCoord2f(1, 1); g.glVertex2d(scrCx + BmpWidth / 2.0, scrCy - BmpHeight / 2.0); g.glEnd(); g.glDisable(XGraphics.GL_TEXTURE_2D); g.glDisable(XGraphics.GL_BLEND); g.glEnable(XGraphics.GL_DEPTH_TEST); return true; } private void nxImageView1_MouseDown(object sender, System.Windows.Forms.MouseEventArgs e) { if (e.Button == System.Windows.Forms.MouseButtons.Left) { XVertex2d vtScr = new XVertex2d(e.X, e.Y); XVertex2d vtWor = nxImageView1.ScreenToWorld(vtScr); int nWidthBytes = 0; byte[] compData = GetCompDIBits(vtWor.x, vtWor.y, ref nWidthBytes); bool bRes = CompTexture.Set(compData, BmpWidth, BmpHeight, nWidthBytes); nxImageLayerComposites2.Invalidate(); nxImageView2.RefreshScreen(); } } private byte[] GetCompDIBits(double cx, double cy, ref int nWidthBytes) { byte[] subComp = null; nxImageLayerComposites1.Lock(); XDMCompManager compMng = nxImageLayerComposites1.GetXDMCompManager(); if (compMng != null && compMng.NumComp > 0) { double wpx, wpy; wpx = wpy = 0; nxImageView1.GetWorldPerScreen(ref wpx, ref wpy); double minx = cx - wpx * (ImgWidth / 2.0); double maxx = cx + wpx * (ImgWidth / 2.0); double miny = cy - wpy * (ImgHeight / 2.0); double maxy = cy + wpy * (ImgHeight / 2.0); XDMComposite comp = compMng.GetXDMCompositeAt(0); subComp = comp.GetDIBits(minx, miny, maxx, maxy, BmpWidth, BmpHeight, ref nWidthBytes); } nxImageLayerComposites1.UnLock(); return subComp; } private void SetComposite(XRSLoadFile loadFile) { nxImageLayerComposites1.Lock(); XDMCompManager xdmCompManager = nxImageLayerComposites1.GetXDMCompManager(); for (int i = 0; i < xdmCompManager.NumComp; i++) { XDMComposite comp = xdmCompManager.GetXDMCompositeAt(i); comp.Dispose(); } xdmCompManager.RemoveXDMCompositeAll(); XDMComposite newComp = new XDMComposite(); int nNumBand = loadFile.NumBand; if (nNumBand < 3) { XDMBand band = loadFile.GetBandAt(0); newComp.Name = band.BandName; newComp.Mode = eCompMode.Gray; newComp.SetBand(ref band, 0); newComp.SetCutType(eCompCutType.Ct98, 0); newComp.SetStretchCoverage(eCompStretchCoverage.Band, 0); newComp.SetStretchType(eCompStretchType.Linear, 0); } else { XDMBand band1 = loadFile.GetBandAt(0); XDMBand band2 = loadFile.GetBandAt(1); XDMBand band3 = loadFile.GetBandAt(2); newComp.Name = loadFile.FileName; newComp.Mode = eCompMode.RGB; newComp.SetBand(ref band3, 0); newComp.SetBand(ref band2, 1); newComp.SetBand(ref band1, 2); for (int i = 0; i < 3; i++) { newComp.SetCutType(eCompCutType.Ct98, i); newComp.SetStretchCoverage(eCompStretchCoverage.Band, i); newComp.SetStretchType(eCompStretchType.Linear, i); } } xdmCompManager.AddXDMComposite(ref newComp); nxImageLayerComposites1.ZoomFit(); nxImageLayerComposites1.Invalidate(); nxImageLayerComposites1.UnLock(); } } }