I am trying to use the ContrastAdjust filter by tying a WPF Slider control to an image.
In the snippet below, the Value property of the slider is bound to the Contrast property in the ViewModel.
In addition ImageSource is a BitmapSource that the Image control's Source property is bound to.
public double Contrast
{
get { return _contrast; }
set
{
if ( value != _contrast )
{
_contrast = value;
OnPropertyChanged( "Contrast" );
}
CreateConvertedImage();
}
}
protected override void CreateConvertedImage()
{
if ( OriginalImageSource != null )
{
WriteableBitmap writeable = new WriteableBitmap( OriginalImageSource );
ImageSource = writeable.AdjustContrast( Contrast );
}
}
When I grab and drag the slider I get the following exception:
System.Runtime.InteropServices.COMException was unhandled by user code
HResult=-2003304445
Message=Exception from HRESULT: 0x88980003
Source=PresentationCore
ErrorCode=-2003304445
StackTrace:
at System.Windows.Media.Imaging.WriteableBitmap..ctor(Int32 pixelWidth, Int32 pixelHeight, Double dpiX, Double dpiY, PixelFormat pixelFormat, BitmapPalette palette)
at System.Windows.Media.Imaging.BitmapFactory.New(Int32 pixelWidth, Int32 pixelHeight) in d:\My Projects\Visual Studio 2013\Projects\FilterPlay\FilterPlay\Extensions\BitmapFactory.cs:line 47
at System.Windows.Media.Imaging.WriteableBitmapExtensions.AdjustContrast(WriteableBitmap bmp, Double level) in d:\My Projects\Visual Studio 2013\Projects\FilterPlay\FilterPlay\Extensions\WriteableBitmapFilterExtensions.cs:line 290
at FilterPlay.ContrastFilterViewModel.CreateConvertedImage() in d:\My Projects\Visual Studio 2013\Projects\FilterPlay\FilterPlay\ContrastFilterViewModel.cs:line 49
at FilterPlay.ContrastFilterViewModel.set_Contrast(Double value) in d:\My Projects\Visual Studio 2013\Projects\FilterPlay\FilterPlay\ContrastFilterViewModel.cs:line 32
InnerException:
Any help would be appreciated!
Thanks,
Rick B
Comments: ** Comment from web user: teichgraf **
In the snippet below, the Value property of the slider is bound to the Contrast property in the ViewModel.
In addition ImageSource is a BitmapSource that the Image control's Source property is bound to.
public double Contrast
{
get { return _contrast; }
set
{
if ( value != _contrast )
{
_contrast = value;
OnPropertyChanged( "Contrast" );
}
CreateConvertedImage();
}
}
protected override void CreateConvertedImage()
{
if ( OriginalImageSource != null )
{
WriteableBitmap writeable = new WriteableBitmap( OriginalImageSource );
ImageSource = writeable.AdjustContrast( Contrast );
}
}
When I grab and drag the slider I get the following exception:
System.Runtime.InteropServices.COMException was unhandled by user code
HResult=-2003304445
Message=Exception from HRESULT: 0x88980003
Source=PresentationCore
ErrorCode=-2003304445
StackTrace:
at System.Windows.Media.Imaging.WriteableBitmap..ctor(Int32 pixelWidth, Int32 pixelHeight, Double dpiX, Double dpiY, PixelFormat pixelFormat, BitmapPalette palette)
at System.Windows.Media.Imaging.BitmapFactory.New(Int32 pixelWidth, Int32 pixelHeight) in d:\My Projects\Visual Studio 2013\Projects\FilterPlay\FilterPlay\Extensions\BitmapFactory.cs:line 47
at System.Windows.Media.Imaging.WriteableBitmapExtensions.AdjustContrast(WriteableBitmap bmp, Double level) in d:\My Projects\Visual Studio 2013\Projects\FilterPlay\FilterPlay\Extensions\WriteableBitmapFilterExtensions.cs:line 290
at FilterPlay.ContrastFilterViewModel.CreateConvertedImage() in d:\My Projects\Visual Studio 2013\Projects\FilterPlay\FilterPlay\ContrastFilterViewModel.cs:line 49
at FilterPlay.ContrastFilterViewModel.set_Contrast(Double value) in d:\My Projects\Visual Studio 2013\Projects\FilterPlay\FilterPlay\ContrastFilterViewModel.cs:line 32
InnerException:
Any help would be appreciated!
Thanks,
Rick B
Comments: ** Comment from web user: teichgraf **
This is not an issue with the lib. This is rather something for the discussion forums.
Anyway, make sure your OriginalImageSource instance is already initialized when you perform the operation. Check it's pixel width and height properties to make sure those are > 0.