コード例 #1
0
ファイル: ProFXCore.cs プロジェクト: powerytg/indulged-flickr
        // Sample the original image
        private void SampleOriginalImage()
        {
            originalBitmap = new WriteableBitmap(originalImage);
            double ratio = (double)originalBitmap.PixelWidth / (double)originalBitmap.PixelHeight;
            double w = Application.Current.RootVisual.RenderSize.Width;
            double h = Application.Current.RootVisual.RenderSize.Height;
            double previewWidth;
            double previewHeight;

            if (w / ratio > h)
            {
                previewHeight = h;
                previewWidth = h * ratio;
            }
            else
            {
                previewWidth = w;
                previewHeight = w / ratio;
            }

            originalPreviewBitmap = originalBitmap.Resize((int)previewWidth, (int)previewHeight, System.Windows.Media.Imaging.WriteableBitmapExtensions.Interpolation.Bilinear);
            currentPreviewBitmap = originalBitmap.Resize((int)previewWidth, (int)previewHeight, System.Windows.Media.Imaging.WriteableBitmapExtensions.Interpolation.Bilinear);

            // Create buffer
            previewStream = new MemoryStream();
            currentPreviewBitmap.SaveJpeg(previewStream, originalPreviewBitmap.PixelWidth, originalPreviewBitmap.PixelHeight, 0, 75);
            previewBuffer = previewStream.GetWindowsRuntimeBuffer();
        }
コード例 #2
0
        private void OnPhotoChooserTaskCompleted(object sender, PhotoResult e)
        {
            UploadButton.IsEnabled = false;
            // Make sure the PhotoChooserTask is resurning OK

            if (e.TaskResult == TaskResult.OK)
            {
                // initialize the result photo stream

                photoStream = new MemoryStream();
                sendPhotoStream = new MemoryStream();

                // Save the stream result (copying the resulting stream)

                e.ChosenPhoto.CopyTo(photoStream);

                // save the original file name

                fileName = e.OriginalFileName;

                BitmapImage setImage = new BitmapImage();
                setImage.SetSource(photoStream);

                WriteableBitmap wb = new WriteableBitmap(setImage);
                var resizeHeight=((double)setImage.PixelHeight / (double)setImage.PixelWidth * 640d);
                wb=wb.Resize(640, (int)resizeHeight, WriteableBitmapExtensions.Interpolation.Bilinear);
                wb.SaveJpeg(sendPhotoStream, wb.PixelWidth, wb.PixelHeight, 0, 100);

                setImage.SetSource(sendPhotoStream);

                
                SelectedImage.Source = setImage;

                // display the chosen picture
                UploadFile();

            }

            else
            {
                MessageBox.Show("Error picking picture");


            }

            UploadButton.IsEnabled = true;
        }
コード例 #3
0
        private void ResizeJpegStream(int maxPixelDimension, int percentQuality, Stream input, Action<Stream> success)
        {
            var bitmap = new BitmapImage();
            bitmap.SetSource(input);
            var writeable = new WriteableBitmap(bitmap);
            var ratio = 1.0;
            if (writeable.PixelWidth > writeable.PixelHeight)
                ratio = ((double)maxPixelDimension) / ((double)writeable.PixelWidth);
            else
                ratio = ((double)maxPixelDimension) / ((double)writeable.PixelHeight);
            writeable.Resize((int)Math.Round(ratio * writeable.PixelWidth), (int)Math.Round(ratio * writeable.PixelHeight), WriteableBitmapExtensions.Interpolation.Bilinear);

            // not - important - we do *not* use using here - disposing of memoryStream is someone else's problem
            var memoryStream = new MemoryStream();
            writeable.SaveJpeg(memoryStream, writeable.PixelWidth, writeable.PixelHeight, 0, percentQuality);
            memoryStream.Seek(0L, SeekOrigin.Begin);
            success(memoryStream);
        }
コード例 #4
0
		/// <summary>
		/// Generates the guild emblem image.
		/// </summary>
		/// <param name="guildEmblemData">The guild emblem data.</param>
		/// <param name="guildSide">The guild side.</param>
		/// <param name="width">The width.</param>
		/// <param name="height">The height.</param>
		/// <returns></returns>
		public static BitmapSource GenerateGuildEmblemImage(GuildEmblem guildEmblemData, GuildSide guildSide, int width = 216, int height = 240)
		{
			WriteableBitmap guildEmblemImage;

			try
			{
				guildEmblemImage = new WriteableBitmap(216, 240);

				var factionBackgroundImage = new WriteableBitmap(216, 216).FromResource(String.Format("Images/GuildDetails/Emblem_Background_{0}.png", guildSide));
				guildEmblemImage.Blit(new Rect(0, 0, 216, 216), factionBackgroundImage, new Rect(0, 0, 216, 216), WriteableBitmapExtensions.BlendMode.Alpha);

				var shadowImage = new WriteableBitmap(179, 210).FromResource("Images/GuildDetails/Emblem_Shadow.png");
				guildEmblemImage.Blit(new Rect(18, 27, 179, 210), shadowImage, new Rect(0, 0, 179, 210), WriteableBitmapExtensions.BlendMode.Alpha);

				var backgroundColor = GetColorFromHexString(guildEmblemData.BackgroundColor);
				var emblemBackgroundImage = new WriteableBitmap(179, 210).FromResource("Images/GuildDetails/Emblem_Background.png");
				guildEmblemImage.Blit(new Rect(18, 27, 179, 210), emblemBackgroundImage, new Rect(0, 0, 179, 210), backgroundColor, WriteableBitmapExtensions.BlendMode.Alpha);

				var borderColor = GetColorFromHexString(guildEmblemData.BorderColor);
				var borderImage = new WriteableBitmap(147, 159).FromResource(String.Format("Images/GuildDetails/Emblem_Border_{0}.png", guildEmblemData.Border));
				guildEmblemImage.Blit(new Rect(31, 40, 147, 159), borderImage, new Rect(0, 0, 147, 159), borderColor, WriteableBitmapExtensions.BlendMode.Alpha);

				var iconColor = GetColorFromHexString(guildEmblemData.IconColor);
				var iconImage = new WriteableBitmap(125, 125).FromResource(String.Format("Images/GuildDetails/Emblems/Emblem_{0}.png", guildEmblemData.Icon.ToString().PadLeft(3, '0')));
				guildEmblemImage.Blit(new Rect(33, 57, 125, 125), iconImage, new Rect(0, 0, 125, 125), iconColor, WriteableBitmapExtensions.BlendMode.Alpha);

				var hooksImage = new WriteableBitmap(179, 32).FromResource("Images/GuildDetails/Emblem_Hooks.png");
				guildEmblemImage.Blit(new Rect(18, 27, 179, 32), hooksImage, new Rect(0, 0, 179, 32), WriteableBitmapExtensions.BlendMode.Alpha);
			}
			catch (Exception ex)
			{
				guildEmblemImage = new WriteableBitmap(216, 240).FromResource(String.Format("Images/GuildDetails/Emblem_Default_{0}.png", guildSide));
			}

			var resized = guildEmblemImage.Resize(width, height, WriteableBitmapExtensions.Interpolation.Bilinear);
			return resized;
		}
コード例 #5
0
 /// <summary>
 /// Scale image
 /// </summary>
 /// <param name="srouce"></param>
 /// <param name="scale"></param>
 /// <returns></returns>
 private WriteableBitmap Scale(WriteableBitmap srouce, float scale)
 {
     WriteableBitmap wb = new WriteableBitmap(srouce);
     int w = (int)(wb.PixelWidth * _lastScale);
     int h = (int)(wb.PixelHeight * _lastScale);
     return wb.Resize(w, h, WriteableBitmapExtensions.Interpolation.Bilinear);
 }
コード例 #6
0
ファイル: MainPage.xaml.cs プロジェクト: rafal366/CameraGuard
        private void TimerOnTick(object sender, EventArgs eventArgs)
        {
            lastCount = count;
            count = 0;
            int[] pixelData = new int[(int)(camera.PreviewResolution.Width * camera.PreviewResolution.Height)];  //640x480

            camera.GetPreviewBufferArgb32(pixelData);

            WriteableBitmap freezeWriteableBitmap = new WriteableBitmap((int)camera.PreviewResolution.Width, (int)camera.PreviewResolution.Height);

            pixelData.CopyTo(freezeWriteableBitmap.Pixels, 0);

            freezeWriteableBitmap.Invalidate();
             //   timer.Stop();
            int[] buffer1 = buffer;

            try
            {
                camera.GetPreviewBufferArgb32(buffer);
               // camera.GetPreviewBufferY(bufferr);
            }
            catch (Exception e)
            {

            }
            //int t = 128;
               freezeWriteableBitmap = freezeWriteableBitmap.Resize(t, t,
                                                                 WriteableBitmapExtensions.Interpolation.Bilinear);
            /*
            for (int i = 0; i < bufferr.Length; i++)
            {
                if (bufferLast[i] != bufferr[i])
                {
                    count++;
                }
            }*/
            /*
              for (int i = 0; i < t; i++)
               {
               for (int j = 0; j < t; j++)
               {
                   var a = freezeWriteableBitmap.GetPixel(i, j);
                  byte d = (byte)((a.R + a.G + a.B)/3);

                    freezeWriteableBitmap.SetPixel(i,j, d,d,d);
               }
               }*/
            int srednia = 0;
            for (int i = 0; i < t; i++)
            {
                for (int j = 0; j <t; j++)
                {
                    var d = freezeWriteableBitmap.GetPixel(i, j);

                    srednia += (d.R + d.G + d.B)/ 3;
                }
            }
            srednia = srednia/(128*128);
            for (int i = 0; i < t; i++)
            {
                for (int j = 0; j <t; j++)
                {
                    var a = freezeWriteableBitmap.GetPixel(i, j);
                    if ((a.R + a.G + a.B)/3 <srednia)
                    {
                        freezeWriteableBitmap.SetPixel(i,j,0,0,0);
                    }
                    else
                    {
                        freezeWriteableBitmap.SetPixel(i,j,255,255,255);
                    }
                }
            }

               /*          int ApetureMin = -(10 / 2);
               int ApetureMax = (2 / 2);
            for (int x = 0; x < t; ++x)
            {
                for (int y = 0; y < t; ++y)
                {
                    int RValue = 0;
                    int GValue = 0;
                    int BValue = 0;
                    for (int x2 = ApetureMin; x2 < ApetureMax; ++x2)
                    {
                        int TempX = x + x2;
                        if (TempX >= 0 && TempX < t)
                        {
                            for (int y2 = ApetureMin; y2 < ApetureMax; ++y2)
                            {
                                int TempY = y + y2;
                                if (TempY >= 0 && TempY < t)
                                {
                                    Color TempColor = freezeWriteableBitmap.GetPixel(TempX, TempY);
                                    if (TempColor.R > RValue)
                                        RValue = TempColor.R;
                                    if (TempColor.G > GValue)
                                        GValue = TempColor.G;
                                    if (TempColor.B > BValue)
                                        BValue = TempColor.B;
                                }
                            }
                        }
                    }
                    //Color TempPixel = Color.FromArgb(0, (byte) RValue, (byte) GValue, (byte) BValue);
                    freezeWriteableBitmap.SetPixel(x, y, (byte)RValue, (byte)GValue, (byte)BValue);
                }
            }*/

            kopia.Source = freezeWriteableBitmap;

            for (int i = 0; i < t; i++)
            {
                for (int j = 0; j < t; j++)
                {

                    if (zapisany.GetPixel(i, j) != freezeWriteableBitmap.GetPixel(i, j))
                    {
                        count++;

                    }
                }
            }
            if ((count - lastCount) > 100)
            {
                startButton.Content = "Ruch";
            }
            else
            {
                startButton.Content = "Brak ruchu";
            }

            if (count < 200)
            {
                setFrame();
            }
        }
コード例 #7
0
ファイル: MainPage.xaml.cs プロジェクト: rafal366/CameraGuard
        void setFrame()
        {
            camera.GetPreviewBufferYCbCr(bufferLast);
            int[] pixelData = new int[(int)(camera.PreviewResolution.Width * camera.PreviewResolution.Height)];  //640x480

            camera.GetPreviewBufferArgb32(pixelData);
            zapisany = new WriteableBitmap((int)camera.PreviewResolution.Width, (int)camera.PreviewResolution.Height);

            pixelData.CopyTo(zapisany.Pixels, 0);

            zapisany.Invalidate();

            zapisany = zapisany.Resize(t, t,
                                                                 WriteableBitmapExtensions.Interpolation.Bilinear);

            /*            int ApetureMin = -(2 / 2);
            int ApetureMax = (2 / 2);
            for (int x = 0; x < t; ++x)
            {
                for (int y = 0; y < t; ++y)
                {
                    int RValue = 0;
                    int GValue = 0;
                    int BValue = 0;
                    for (int x2 = ApetureMin; x2 < ApetureMax; ++x2)
                    {
                        int TempX = x + x2;
                        if (TempX >= 0 && TempX < t)
                        {
                            for (int y2 = ApetureMin; y2 < ApetureMax; ++y2)
                            {
                                int TempY = y + y2;
                                if (TempY >= 0 && TempY < t)
                                {
                                    Color TempColor = zapisany.GetPixel(TempX, TempY);
                                    if (TempColor.R > RValue)
                                        RValue = TempColor.R;
                                    if (TempColor.G > GValue)
                                        GValue = TempColor.G;
                                    if (TempColor.B > BValue)
                                        BValue = TempColor.B;
                                }
                            }
                        }
                    }
                    //Color TempPixel = Color.FromArgb(0, (byte) RValue, (byte) GValue, (byte) BValue);
                    zapisany.SetPixel(x, y, (byte)RValue, (byte)GValue, (byte)BValue);
                }
            }*/

            /*        for (int i = 0; i < 128; i++)
                    {
                        for (int j = 0; j < 128; j++)
                        {
                            var a = zapisany.GetPixel(i, j);
                            byte d = (byte)((a.R + a.G + a.B) / 3);

                           zapisany.SetPixel(i, j, d, d, d);
                        }
                    }*/
            /*            for (int i = 0; i < t; i++)
            {
                for (int j = 0; j < t; j++)
                {
                    var a = zapisany.GetPixel(i, j);
                    byte d = (byte)((a.R + a.G + a.B) / 3);

                    zapisany.SetPixel(i, j, d, d, d);
                }
            }*/

            for (int i = 0; i < t; i++)
            {
                for (int j = 0; j < t; j++)
                {
                    var a = zapisany.GetPixel(i, j);
                    if ((a.R + a.G + a.B) / 3 < 128)
                    {
                        zapisany.SetPixel(i, j, 0, 0, 0);
                    }
                    else
                    {
                        zapisany.SetPixel(i, j, 255, 255, 255);
                    }
                }
            }
        }
コード例 #8
0
        public static WriteableBitmap Scale(WriteableBitmap image, double scale)
        {
            if (scale == 1)
                return image;

            if (!_resizes.ContainsKey(image))
                _resizes[image] = new Dictionary<double, WriteableBitmap>();

            if (!_resizes[image].ContainsKey(scale))
                _resizes[image][scale] = image.Resize((int)(image.PixelWidth * scale), (int)(image.PixelHeight * scale), WriteableBitmapExtensions.Interpolation.NearestNeighbor);

            return _resizes[image][scale];
        }
コード例 #9
0
ファイル: NpDbContext.cs プロジェクト: Sliverb/NoraPic
        private WriteableBitmap GeneratePreview(WriteableBitmap WBImage, double maxWidth, double maxHeight)
        {
            double scaleX = 1;
            double scaleY = 1;

            if (WBImage.PixelHeight > maxHeight)
                scaleY = Math.Min(maxHeight / WBImage.PixelHeight, 1);
            if (WBImage.PixelWidth > maxWidth)
                scaleX = Math.Min(maxWidth / WBImage.PixelWidth, 1);

            // maintain aspect ratio by picking the most severe scale
            double scale = Math.Min(scaleY, scaleX);

            WriteableBitmap retImage = WBImage.Resize((int)(scale * WBImage.PixelWidth), (int)(scale * WBImage.PixelHeight), WriteableBitmapExtensions.Interpolation.Bilinear);
            MessageBox.Show("Dim: " + PreviewImage.PixelHeight + "x" + PreviewImage.PixelWidth);
            return retImage;
        }
コード例 #10
0
ファイル: MainPage.xaml.cs プロジェクト: Nesszors/PaintApp
        private void photoChooserTask_Completed(object sender, PhotoResult e)
        {
            if (e.TaskResult == TaskResult.OK)
            {
                updateUndoList();

                bm = new WriteableBitmap(canvas1, null);

                double width = bm.PixelWidth;
                double height = bm.PixelHeight;

                bm.SetSource(e.ChosenPhoto);

                double scaleX = bm.PixelWidth / width;
                double scaleY = bm.PixelHeight / height;

                //For debugging
                //System.Diagnostics.Debug.WriteLine(width + " - " + height);
                //System.Diagnostics.Debug.WriteLine(bm.PixelWidth + " :: " + bm.PixelHeight);
                //System.Diagnostics.Debug.WriteLine(scaleX + " = " + scaleY);

                bm = bm.Resize((int)(bm.PixelWidth / scaleX),
                               (int)(bm.PixelHeight / scaleY),
                               WriteableBitmapExtensions.Interpolation.Bilinear);

                updateCanvasFromWBM(bm);
                makeToast("", "Load Successful");

                //Frank: Look into cleaning up this Imagesource mess later with the following trick
                //Code to display the photo on the page in an image control named myImage.
                //System.Windows.Media.Imaging.BitmapImage bmp = new System.Windows.Media.Imaging.BitmapImage();
                //bmp.SetSource(e.ChosenPhoto);
                //myImage.Source = bmp;
            }
            else
            {
                makeToast("Uh oh!", "Load Failed");
            }
        }
コード例 #11
0
        public static string GenereateMosaicPicture(IList<BitmapImage> images, string filename)
        {
            string key = string.Empty;

            try
            {
                // Generate avatar in bitmap.
                var bmp = new WriteableBitmap(PICTURE_DIMENSION, PICTURE_DIMENSION);
                bmp.Clear();
                int x = 0;
                int y = 0;

                int w = 0;
                int h = 0;
                if (images.Count == 1)
                {
                    w = PICTURE_DIMENSION;
                    h = PICTURE_DIMENSION;
                }
                else if (images.Count == 2)
                {
                    w = PART_DIMENSION;
                    h = PICTURE_DIMENSION;
                }
                else
                {
                    w = PART_DIMENSION;
                    h = PART_DIMENSION;
                }

                for (int i = 0; i < images.Count && i < 4; )
                {
                    if (images[i] == null)
                        continue;

                    var wb = new WriteableBitmap(images[i]);

                    if (wb.PixelHeight < h || wb.PixelWidth < w)
                    {
                        wb = wb.Resize(PICTURE_DIMENSION, PICTURE_DIMENSION, WriteableBitmapExtensions.Interpolation.Bilinear);
                    }

                    i++;

                    bmp.Blit(new Rect(x, y, w, h), wb,
                        new Rect(0, 0, w, h));

                    if (w == PART_DIMENSION)
                        x += w + 2; // Handle empty space between photos
                    else
                        x += w;

                    if (x >= PICTURE_DIMENSION)
                    {
                        x = 0;

                        if (h == PART_DIMENSION)
                            y += h + 2; // Handle empty space between photos
                        else
                            y += h;
                    }

                    if (y >= PICTURE_DIMENSION)
                        break;
                }

                if (_SaveJpeg(bmp, filename))
                    key = filename;
            }
            catch (Exception ex)
            {
                Debug.WriteLine("GenereateMosaicPicture failed." + ex.Message);
            }

            return key;
        }
コード例 #12
0
        public static WriteableBitmap NormalizeBitmapSize(WriteableBitmap bitmap)
        {
            float pixelWidth = bitmap.PixelWidth;

               int height = Convert.ToInt32((bitmap.PixelHeight / pixelWidth) * 400);

               return bitmap.Resize(400, height, WriteableBitmapExtensions.Interpolation.NearestNeighbor);
        }
コード例 #13
0
        // Image finished loading
        private void OnImageLoaded(object sender, EventArgs e)
        {
            BitmapImage sourceImage = (BitmapImage)sender;

            WriteableBitmap scaledImage = new WriteableBitmap(sourceImage);
            scaledImage.Resize((int)Width, (int)Height, WriteableBitmapExtensions.Interpolation.Bilinear);

            double w = Width;
            double h = Height;
            double cellWidth = w;
            double cellHeight = h / NumBlinds;

            for (int i = 0; i < NumBlinds; i++)
            {
                // Create the target cell
                Image cell = new Image();
                Rect rect = new Rect(0, i * cellHeight, cellWidth, cellHeight);

                cell.SetValue(Canvas.TopProperty, rect.Y);
                cell.SetValue(Canvas.LeftProperty, rect.X);
                cell.Width = cellWidth;
                cell.Height = cellHeight;
                cell.Visibility = Visibility.Collapsed;

                contentView.Children.Add(cell);
                nextGrid.Add(cell);

                WriteableBitmap slice = scaledImage.Crop(rect);
                cell.Source = slice;
            }

            for(int i = 0; i < NumBlinds; i++)
            {
                animatedCellIndex.Add(i);
            }

            // Do animation
            int firstCellIndex = animatedCellIndex[0];
            PerformFlipAnimation(grid[firstCellIndex], nextGrid[firstCellIndex]);
        }
コード例 #14
0
 static WriteableBitmap ScaleBitmap(WriteableBitmap bmp, int width, int height)
 {
     int W = bmp.PixelWidth;
     int H = bmp.PixelHeight;
     if (W <= width && H <= height)
     {
         return bmp;
     }
     int w = width;
     int h = height;
     if (((double)W) / ((double)H) >= (((double)width) / (double)height))
     {
         h = (int)Math.Min(H * w / (double)W, height);
     }
     else
     {
         w = (int)Math.Min(W * h / (double)H, width);
     }
     return bmp.Resize(w, h, WriteableBitmapExtensions.Interpolation.Bilinear);
 }
コード例 #15
0
        private void appBtnPaylas_Click(object sender, EventArgs e)
        {
            if (txtUrunFiyat.Text != string.Empty && txtUrunIsim.Text != string.Empty)
            {
                ucret = Convert.ToDecimal(txtUrunFiyat.Text);
                path = "/Assets/sepet.png";

                if (fotoDegistimi)
                {
                    path = txtUrunIsim.Text + tbBarkodData.Text + uzanti;
                    using (MemoryStream ms = new MemoryStream())
                    {
                        WriteableBitmap btmMap = new WriteableBitmap(imgUrunResim.Source as BitmapSource);
                        btmMap = btmMap.Resize(Convert.ToInt32(200), Convert.ToInt32(222), WriteableBitmapExtensions.Interpolation.Bilinear);
                        btmMap.SaveJpeg(ms, btmMap.PixelWidth, btmMap.PixelHeight, 0, 50);
                        fotoDizisi = ms.ToArray();
                    }
                    al.UploadImageAsync(fotoDizisi, txtUrunIsim.Text + tbBarkodData.Text + uzanti, "urunresimleri");
                    al.UploadImageCompleted += Al_UploadImageCompleted;
                }


                if (!BarkodKontrol) // eğer ürün daha önceden eklenmemişse
                {
                    Urunler urun = new Urunler    // ürünler veritabanına veri kaydı..
                    {
                        Barkod = barkodDatasi,
                        UrunAd = txtUrunIsim.Text,
                        UrunIlkEkleyen = KullaniciId,
                        EnUcuzFiyat = ucret,
                        MarketId = 1,
                        UrunResim = path,
                        BarkodTur = BarkodTur
                    };

                    al.UrunlerKayitAsync(urun);
                    al.UrunlerKayitCompleted += new EventHandler<UrunlerKayitCompletedEventArgs>(al_UrunlerKayitCompleted);
                }


                if (BarkodKontrol)
                {
                    al.PaylasimUrunTakipKayitAsync(barkodId, ucret, 1, KullaniciId);
                    al.PaylasimUrunTakipKayitCompleted += Al_PaylasimUrunTakipKayitCompleted;
                }

                NavigationService.GoBack();
            }
        }
コード例 #16
0
ファイル: Server.cs プロジェクト: kartikeyadubey/share
        public void sendData(WriteableBitmap b, bool playerFound, int xStart, int xEnd, int yStart, int yEnd)
        {
            if (!clientConnected)
            {
                return;
            }
            else
            {
                //Background has been sent and there is a player
                //in the image send a message to the client
                //with the size of the bounding box and the image
                //Send every sixth frame that we receive
                if (backgroundSent && playerFound && imageSendCounter%3 == 0)
                {
                    //Send the client a flag
                    ASCIIEncoding encoder = new ASCIIEncoding();
                    byte[] buffer = encoder.GetBytes("playerimage");

                    byte[] readyToReceive = encoder.GetBytes("rcomplete");
                    clientStream.Write(readyToReceive, 0, readyToReceive.Length);
                    clientStream.Flush();
                    byte[] completeMessage = new byte[65536];

                    int k = s.Receive(completeMessage);
                    while (k == 0)
                    {
                        k = s.Receive(completeMessage);
                    }
                    //Get the string from the first 9 bytes since
                    //rcomplete may have been appended to ensure there is no deadlock
                    string tempMessage = encoder.GetString(completeMessage, 0, 9);
                    if (!tempMessage.Equals("rcomplete"))
                    {
                        Console.WriteLine("Message received: " + encoder.GetString(completeMessage, 0, k));
                        return;
                    }

                    clientImage = b.Resize(320, 240, RewritableBitmap.Interpolation.Bilinear);
                    double tmpXStart = (xStart / 2);
                    double tmpYStart = (yStart / 2);
                    double tmpXEnd = (xEnd / 2);
                    double tmpYEnd = (yEnd / 2);

                    xStart = Convert.ToInt32(Math.Floor(tmpXStart));
                    xEnd = Convert.ToInt32(Math.Floor(tmpXEnd));
                    yStart = Convert.ToInt32(Math.Floor(tmpYStart));
                    yEnd = Convert.ToInt32(Math.Floor(tmpYEnd));

                    int smallWidth = (xEnd - xStart);
                    int smallHeight = (yEnd - yStart);

                    int imgSize = smallWidth * smallHeight * 4;
                    //Console.WriteLine("Image size: " + imgSize);
                    byte[] transmitPlayerImage = new byte[imgSize];

                    clientImage.CopyPixels(new Int32Rect(xStart, yStart, smallWidth, smallHeight), transmitPlayerImage, (smallWidth * 4), 0);
                    //b.CopyPixels(new Int32Rect(xStart, yStart, (xEnd - xStart), (yEnd - yStart)), playerImage, ((xEnd - xStart) * 4), 0);

                    //Send the actual size of the bounding box
                    byte[] xS = BitConverter.GetBytes(xStart);
                    byte[] xE = BitConverter.GetBytes(xEnd);
                    byte[] yS = BitConverter.GetBytes(yStart);
                    byte[] yE = BitConverter.GetBytes(yEnd);
                    byte[] playerImageSize = BitConverter.GetBytes(transmitPlayerImage.Length);

                    s.Send(buffer);

                    s.Send(xS);

                    s.Send(xE);

                    s.Send(yS);

                    s.Send(yE);

                    s.Send(playerImageSize);
                    imageSendCounter = 1;
                    s.Send(transmitPlayerImage);
                    //Console.WriteLine("Image sent, size of image: " + transmitPlayerImage.Length + "," + xStart + ", " + xEnd + ", " + yStart + ", " + yEnd);
                }
                else if (!backgroundSent)
                {
                    clientImage = b.Resize(320, 240, RewritableBitmap.Interpolation.Bilinear);
                    byte[] smallBackgroundImage = new byte[TRANSMIT_IMAGE_SIZE];
                    clientImage.CopyPixels(new Int32Rect(0, 0, 320, 240), smallBackgroundImage, 320 * 4, 0);
                    s.Send(smallBackgroundImage);
                    backgroundSent = true;
                    Console.WriteLine("Background sent");
                }
                else
                {
                    imageSendCounter++;
                }

            }
        }
コード例 #17
0
ファイル: Webcam.cs プロジェクト: BI-LedTable/LedTable
        public void Webcam_execute()
        {
            if (bitmap != null)
            {
                using (memory = new MemoryStream())
                {

                    bitmap.Save(memory, ImageFormat.Bmp);
                    memory.Position = 0;
                    bitmapImage = new BitmapImage();
                    bitmapImage.BeginInit();
                    bitmapImage.StreamSource = memory;
                    bitmapImage.CacheOption = BitmapCacheOption.OnLoad;
                    bitmapImage.EndInit();

                }

            }

               if (bitmapImage != null)
               {
               origin = BitmapFactory.ConvertToPbgra32Format(bitmapImage);
               origin = origin.Resize(68, 42, WriteableBitmapExtensions.Interpolation.NearestNeighbor);
               origin.CopyPixels(new Int32Rect(0, 0, origin.PixelWidth, origin.PixelHeight), monitor.BackBuffer,
                                  monitor.BackBufferStride * monitor.PixelHeight, monitor.BackBufferStride);
               }
        }