cureos / aforge

PCL version of AForge.NET Framework, https://code.google.com/p/aforge/
Other
125 stars 96 forks source link

I can't change WriteableBitmap to Bitmap in Windows 8.1 store app #4

Closed kaki104 closed 10 years ago

kaki104 commented 10 years ago

Hi Search today and yesterday, try it but, it is all that failed to work.

This is store app defind class public sealed class WriteableBitmap : BitmapSource { // Summary: // Initializes a new instance of the WriteableBitmap class. // // Parameters: // pixelWidth: // The width of the bitmap in pixels. // // pixelHeight: // The height of the bitmap in pixels. public WriteableBitmap(int pixelWidth, int pixelHeight);

    // Summary:
    //     Gets an access for the direct buffer where each pixel of the WriteableBitmap
    //     is written to.
    //
    // Returns:
    //     A reference to the pixel buffer.
    public IBuffer PixelBuffer { get; }

    // Summary:
    //     Requests a draw or redraw of the entire bitmap.
    public void Invalidate();
}

I can't find this method public WriteableBitmap(BitmapSource source);

How can i convert WriteableBitmap to Bitmp? Thank you

anders9ustafsson commented 10 years ago

The implicit conversion back and forth between Bitmap and WriteableBitmap is incorporated in the target specific versions of the Shim.System.Drawing assembly. For Windows Store you can see the source code here. In your Windows Store application you should thus replace the PCL version of Shim.System.Drawing with the Windows Store specific version. You can find all binaries that you need here.

kaki104 commented 10 years ago
  1. Refreance change

Add reference in PCL folder AForge AForge.Imaging AForge.Math

Add reference in Store folder Shim.System Shim.System.Drawing

  1. File select FileOpenPicker fop = new FileOpenPicker(); fop.FileTypeFilter.Add(".jpg"); var file = await fop.PickSingleFileAsync();
  2. Make WriteableBitmap object var property = await file.Properties.GetImagePropertiesAsync(); WriteableBitmap wb = new WriteableBitmap((int)property.Width, (int)property.Height); using (IRandomAccessStream fileStream = await file.OpenAsync(Windows.Storage.FileAccessMode.Read)) { await wb.SetSourceAsync(fileStream); }
  3. WriteableBitmap convert Bitmap Bitmap orignalImage = wb;

Thank you very much, this project is great!

anders9ustafsson commented 10 years ago

You are welcome. Glad to hear it works.

Best regards, Anders @ Cureos