WriteableBitmapEx Windows Phone dll's - c#

I am currently trying to overlay two bitmaps using WriteableBitmapEx using this method found in the documentation:
writeableBmp.Blit(new Point(10, 10), bitmap, sourceRect,
Colors.White,WriteableBitmapExtensions.BlendMode.Additive);
I installed the package via NuGet which adds ...WinPhone.dll and WinPhoneXnaDependant.dll which seems to cause the problem. Here's the code I'm currently writing:
WriteableBitmap result = new WriteableBitmap(results, null);
WriteableBitmap overlay = new WriteableBitmap(0, 0).FromResource("Images/VizageOverlay.png");
var cropped = result.Crop(96, 0, 480, 728);
cropped.Blit(new Point(0, 0), overlay, new Point(0,0),
WriteableBitmapExtensions.BlendMode.Additive);
However, an error states that the WriteableBitmapExtensions.BlendMode.Additive *exists in both* the aforementioned dlls. I've tried getting rid of both and keeping one but I need both it appears for the above code.
Any ideas?

Remove the reference to the WinPhoneXnaDependant if you're not creating a XNA project.
If the problem persists, ping the author, René Schulte on Twitter.

Never saw that. A rebuild might help and you can just remove the reference to the XNA project. The WriteableBitmapExWinPhoneXnaDependant.dll contains XNA-dependent code like write to MediaLibrary. It's separated so the WBX lib can be used in background agents which prohibits the usage of such XNA code.

Related

c# SharpDX ScaleEffect Interpolation question

i've been using this wonderful library for low impact screen recording software however im at a point where i need to use a DirectX Scale Effect to scale the image down with anisotropic filtering.
I can create the effect just fine and set up most of its parameters, however im not able to set the most important one for me scaleEffect.SetValue((int)ScaleProperties.InterpolationMode, (int)SharpDX.Direct2D1.ScaleInterpolationMode.Anisotropic);
As soon as the program runs it crashes at that line with an invalid parameter exception.
I've searched and couldnt find anything wrong with the code, but then again i have almost 0 experience with anything Direct2D.
Here is the full code for that specific effect for reference:
SharpDX.Direct2D1.Effect scaleEffect = new D2D.Effect(textureDc, D2D.Effect.Scale);
scaleEffect.Cached = true;
scaleEffect.SetInput(0, frameBitmap, false);
var centerPoint = new SharpDX.Vector2(0, 0);
var newSize = new SharpDX.Vector2(0.2f, 0.2f);
scaleEffect.SetValue((int)ScaleProperties.CenterPoint, centerPoint);
scaleEffect.SetValue((int)ScaleProperties.Scale, newSize);
//Crashes Here: scaleEffect.SetValue((int)ScaleProperties.InterpolationMode, (int)SharpDX.Direct2D1.ScaleInterpolationMode.Anisotropic);
Error Message: SharpDX.SharpDXException: 'HRESULT: [0x80070057], Module: [General], ApiCode: [E_INVALIDARG/Invalid Arguments], Message: The parameter is incorrect.'
textureDc.BeginDraw();
textureDc.DrawImage(scaleEffect, InterpolationMode.Anisotropic);
textureDc.EndDraw();
Thank you very much in advance for any help!
UPDATE:
As per #Simon Mourier comment, the solution to avoid this bug somewhere in the SharpDX API, is to use the SharpDX.Direct2D1.Effects.Scale instead.
This way, i can confirm the InterpolationMode does no longer crash and works as intended!
Here is the new, working code for anyone running into the same issue.
SharpDX.Direct2D1.Effects.Scale scaleClass = new D2D.Effects.Scale(textureDc);
scaleClass.SetInput(0, frameBitmap,false);
scaleClass.Cached = true;
var centerPoint = new SharpDX.Vector2(0, 0);
var newSize = new SharpDX.Vector2(0.2f, 0.2f);
scaleClass.CenterPoint = centerPoint;
scaleClass.ScaleAmount = newSize;
scaleClass.InterpolationMode = InterpolationMode.Anisotropic;
textureDc.BeginDraw();
textureDc.DrawImage(scaleClass);
textureDc.EndDraw();
PS: For anyone wondering about casting the value to uint instead using the first method, it returns the following error:
(Argument1 cannot convert from uint to int)
So it semms that there might be some underlying bug in this specific scenario.
One solution is to use the SharpDX.Direct2D1.Effects.Scale directly which is a wrapper over the Effect class and comes with an InterpolationMode property.

Issues loading different shapefiles in given sharpmap tutorial code

I am currently working on sharpmap project with the need to work on offline maps. As i am fresher in this field,I am following the sharpmap tutorial and facing a problem with loading new shape files in the given tutorial code.
For Example :\
SharpMap.Layers.VectorLayer("States");
vlay.DataSource = new SharpMap.Data.Providers.ShapeFile("path_to_data\\states_ugl.shp", true);
At this line of code, if i pass a different shapefile, code builds with a blank background or no display.
I have tried with different shape files with different sizes but the result is the same. It only works for the mentioned states_ugl.shp file given in the code. Please need help regarding this issue as I am a fresher in this field.
Thanks.
Try giving layer styling for your layer, something like below.
layer.DataSource = DBlayer;
layer.Style.Fill = new SolidBrush(Color.Transparent);
layer.Style.Outline = new Pen(Color.Black);
layer.Style.EnableOutline = true;
layer.MaxVisible = 13000;

C# Managed DirectX sprite2D locating bug?

I want to draw 2D sprite.
And here is strange thing: if i Sprite.Draw2D with first overload:
using (Sprite Spr = new Sprite(Gfx))
{
Spr.Begin(SpriteFlags.AlphaBlend);
int SprY = Gfx.PresentationParameters.BackBufferHeight/2;
int SprX = Gfx.PresentationParameters.BackBufferWidth/2;
Spr.Draw2D(Tex, new Point(0,0), 0.0f, new Point(SprX,SprY), Color.White);
Spr.End();
while (!Spr.Disposed)
Spr.Dispose();
}
It locating right in 128,128.
But I want to scale-down my image.
So i use 3rd overload of Sprite.Draw2D:
Spr.Draw2D(Tex, new Rectangle(0, 0, 1024, 1024), new Rectangle(0,0,256,256), new Point(SprX,SprY) , Color.White);
Then, it draws to weired position(but correct-sized).
I found-out that width of screen in case of 3rd overload = 1280.
And no matter of PresentationParameters or ViewPort sizes. Even on other machine it is 1280, and center will be 640.
I've tryed to debug Gfx(Device) object and see if any appereance of '1280' number, and it is appear in Gfx.DisplayMode. Unfortunatly, i cant set this parameter because "Device.SetDisplayMode is deprecated" as MSDN says. And DisplayMode.Width is differs between two computers i've test my 'game' on.
Probably i've missed something realy HUGE and stack on it.
By the way, im using DirectX libs from "C:\Windows\Microsoft.NET\DirectX for Managed Code\1.0.2902.0" if this matters.

While want to make an instance of SIFTDetector: Get an Attempted to read or write protected memory exception Error

I am trying to use sift algorithm to make the keypoints and descriptors in c# by using opencv library.
fileAddress = dlg.FileName;
cap = new Emgu.CV.Capture(dlg.FileName);
cap.SetCaptureProperty(Emgu.CV.CvEnum.CAP_PROP.CV_CAP_PROP_POS_FRAMES, 3945);
imGray = cap.QueryGrayFrame();
Emgu.CV.Features2D.SIFTDetector siftDet = new Emgu.CV.Features2D.SIFTDetector();
siftDet.DetectKeyPoints(imGray);
MessageBox.Show("test SIFT");
but when it go through the line Emgu.CV.Features2D.SIFTDetector siftDet = new Emgu.CV.Features2D.SIFTDetector(); I face the error:
and view detail is as following:
How could I solve this exception?
The openCv that I was using was version 2.1, then I upgraded the opencv*.* and *.dll files to version 2.4. The problem solved.
I couldn't find any explanation for that, that would be awesome if anybody could even give me an intuitive answer.
For now if you face such problem regarding working with SIFT, try the latest version.

Updating Application tile using TileUpdateManager

I'm developing metro app using Windows 8 release preview and C#(VS 2012),I'm using below code to update Application tile.
TileUpdateManager.CreateTileUpdaterForApplication().EnableNotificationQueue(true);
XmlDocument TileXML = TileUpdateManager.GetTemplateContent(TileTemplateType.TileWideImage);
XmlNodeList imageAttribute = TileXML.GetElementsByTagName("image");
((XmlElement)imageAttribute[0]).SetAttribute("src", "ms-appx:///Assets/Tile.png");
((XmlElement)imageAttribute[0]).SetAttribute("alt", "red graphic");
TileNotification notify = new TileNotification(TileXML);
notify.ExpirationTime = DateTimeOffset.UtcNow.AddSeconds(10);
TileUpdateManager.CreateTileUpdaterForApplication().Update(notify);
But my Application Tile is not updating, I don't know what I'm missing and where I'm doing wrong, please help me.
I got the answer, its about adding Extension file "NotificationExtensions.winmd" as my reference and also i have couple of questions
When i run above code by setting my target device as "Local
Machine" it works but when i set it to "Simulator" it doesn't, Can
any one explains me please why.
We have expiration time for tiles by using below line
notify.ExpirationTime = DateTimeOffset.UtcNow.AddSeconds(10);
what i have to do if want the live tile to be running continuously,
Please let me know if have any links or study material
Thanks in advance.
Thank you Guys,i got the answer, my image size is <200KB and < 1024x1024, mistake i did is i haven't added extension file "NotificationExtensions.winmd" as my reference. i did that and i got it.

Categories

Resources