How to plot a point on mapwindowGIS - c#

i am using mapwingis and i have uploaded all the needed shape file..now i already have the data from the gps and i want to show it in my map. i had researched that i can use drawcircleex, but it does not give me the correct location and the circle is stucked in the center. heres my code:
MapWinGIS.Shapefile plane = new MapWinGIS.Shapefile();// shape 1
MapWinGIS.Shapefile roads = new MapWinGIS.Shapefile();// shape 2
MapWinGIS.Shapefile gensan = new MapWinGIS.Shapefile();// shape 3
MapWinGIS.Shapefile pois = new MapWinGIS.Shapefile();// shape 4
MapWinGIS.Shapefile pofw = new MapWinGIS.Shapefile();// shape 5
MapWinGIS.Shapefile places = new MapWinGIS.Shapefile();// shape 6
MapWinGIS.Shapefile roadsfin = new MapWinGIS.Shapefile();// shape 7
MapWinGIS.Shapefile circle = new MapWinGIS.Shapefile();// shape 8
int shape1, shape2, shape3, shape4, shape5, shape6, shape7, shape8;
public static string varname;
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
// layer of plane
plane.Open("C:/Users/User/Desktop/THESIS/New Folder (2)/phi/philippines/adminareasfinal.shp", null);
shape1 = axMap1.AddLayer(plane, true);
axMap1.set_ShapeLayerFillColor(shape1, (UInt32)(System.Drawing.ColorTranslator.ToOle
(System.Drawing.Color.Linen)));
axMap1.set_ShapeLayerLineColor(shape1, (UInt32)(System.Drawing.ColorTranslator.ToOle
(System.Drawing.Color.Linen)));
// layer of gensan
gensan.Open("C:/Users/User/Desktop/THESIS/New Folder (2)/gensan_southcotabato/gensan_southcotabato.shp", null);
shape2 = axMap1.AddLayer(gensan, true);
axMap1.set_ShapeLayerFillColor(shape2, (UInt32)(System.Drawing.ColorTranslator.ToOle
(System.Drawing.Color.OldLace)));
axMap1.set_ShapeLayerLineColor(shape2, (UInt32)(System.Drawing.ColorTranslator.ToOle
(System.Drawing.Color.Black)));
// layer of longitude and latitude
Single LineWidth1 = 1;
roadsfin.Open("C:/Users/User/Desktop/THESIS/New Folder (2)/phi/philippines/roadsfin.shp", null);
shape7 = axMap1.AddLayer(roadsfin, true);
axMap1.set_UDPointType(shape7, roadsfin);
axMap1.set_ShapeLayerPointSize(shape7, LineWidth1);
axMap1.set_ShapeLayerPointColor(shape7, (UInt32)(System.Drawing.ColorTranslator.ToOle
(System.Drawing.Color.Transparent)));
// layer of roads
Single LineWidth = 2;
roads.Open("C:/Users/User/Desktop/THESIS/New Folder (2)/phi/philippines/roads.shp", null);
shape3 = axMap1.AddLayer(roads, true);
axMap1.set_ShapeLayerLineWidth(shape3, LineWidth);
axMap1.set_ShapeLayerLineColor(shape3, (UInt32)(System.Drawing.ColorTranslator.ToOle
(System.Drawing.Color.White)));
//layer of pois and pofw bitmap image
Single pointsize = 1;
pois.Open("C:/Users/User/Desktop/THESIS/New Folder (2)/phi/philippines/pois.shp", null);
shape4 = axMap1.AddLayer(pois, true);
pofw.Open("C:/Users/User/Desktop/THESIS/New Folder (2)/phi/philippines/pofw.shp", null);
shape5 = axMap1.AddLayer(pofw, true);
places.Open("C:/Users/User/Desktop/THESIS/New Folder (2)/phi/philippines/places.shp", null);
shape6 = axMap1.AddLayer(places, true);
int LineWidth7 = 10;
circle.Open("C:/Users/User/Desktop/THESIS/New Folder (2)/phi/newshape/finalepoint.shp", null);
shape8 = axMap1.AddLayer(circle, true);
axMap1.set_ShapeLayerPointColor(shape8, (UInt32)(System.Drawing.ColorTranslator.ToOle
(System.Drawing.Color.Black)));
axMap1.set_ShapeLayerPointSize(shape8, LineWidth7);
string circlelabel;
double x12, y12;
for (int j = 0; j < circle.NumShapes - 1; j++)
{
circlelabel = System.Convert.ToString(roads.get_CellValue(1, j));
x12 = circle.get_Shape(j).Extents.xMin + (circle.get_Shape(j).Extents.xMax - circle.get_Shape(j).Extents.xMin) / 2;
y12 = circle.get_Shape(j).Extents.yMin + (circle.get_Shape(j).Extents.yMax - circle.get_Shape(j).Extents.yMin) / 2;
axMap1.AddLabel(shape8, circlelabel, (UInt32)(System.Drawing.ColorTranslator.ToOle
(System.Drawing.Color.Red)), x12, y12, MapWinGIS.tkHJustification.hjCenter);
}
MapWinGIS.Image poisimage = new MapWinGIS.Image();
MapWinGIS.Image pofwimage = new MapWinGIS.Image();
MapWinGIS.Image placesimage = new MapWinGIS.Image();
poisimage.Open("C:/Users/User/Desktop/bitmap/poisimage.bmp", MapWinGIS.ImageType.USE_FILE_EXTENSION, true, null);
{
this.axMap1.set_ShapeLayerPointSize(shape4, pointsize);
this.axMap1.set_ShapeLayerPointType(shape4, MapWinGIS.tkPointType.ptUserDefined);
this.axMap1.set_UDPointType(shape4, poisimage);
}
axMap1.set_LayerVisible(shape4, true);
pofwimage.Open("C:/Users/User/Desktop/bitmap/pofwimage.bmp", MapWinGIS.ImageType.USE_FILE_EXTENSION, true, null);
{
this.axMap1.set_ShapeLayerPointSize(shape5, pointsize);
this.axMap1.set_ShapeLayerPointType(shape5, MapWinGIS.tkPointType.ptUserDefined);
this.axMap1.set_UDPointType(shape5, pofwimage);
}
axMap1.set_LayerVisible(shape5, true);
placesimage.Open("C:/Users/User/Desktop/bitmap/placesimage.bmp", MapWinGIS.ImageType.USE_FILE_EXTENSION, true, null);
{
this.axMap1.set_ShapeLayerPointSize(shape6, pointsize);
this.axMap1.set_ShapeLayerPointType(shape6, MapWinGIS.tkPointType.ptUserDefined);
this.axMap1.set_UDPointType(shape6, placesimage);
}
axMap1.set_LayerVisible(shape6, true);
// the following are the codes to show the names of Roads
string myLabel;
double x, y;
for (int i = 0; i < roads.NumShapes - 1; i++)
{
myLabel = System.Convert.ToString(roads.get_CellValue(4, i));
x = roads.get_Shape(i).Extents.xMin + (roads.get_Shape(i).Extents.xMax - roads.get_Shape(i).Extents.xMin) / 2;
y = roads.get_Shape(i).Extents.yMin + (roads.get_Shape(i).Extents.yMax - roads.get_Shape(i).Extents.yMin) / 2;
axMap1.AddLabel(shape2, myLabel, (UInt32)(System.Drawing.ColorTranslator.ToOle
(System.Drawing.Color.Black)), x, y, MapWinGIS.tkHJustification.hjCenter);
}
// the following are the codes to show the names of pois
string poislabel;
double pois1, pois2;
int handle = axMap1.NewDrawing(MapWinGIS.tkDrawReferenceList.dlScreenReferencedList);
for (int ps = 0; ps < pois.NumShapes - 1; ps++)
{
poislabel = System.Convert.ToString(pois.get_CellValue(4, ps));
pois1 = pois.get_Shape(ps).Extents.xMin + (pois.get_Shape(ps).Extents.xMax - pois.get_Shape(ps).Extents.xMin) / 2;
pois2 = pois.get_Shape(ps).Extents.yMin + (pois.get_Shape(ps).Extents.yMax - pois.get_Shape(ps).Extents.yMin) / 2;
double width = pois.get_Shape(ps).Extents.xMin + (pois.get_Shape(ps).Extents.xMax - pois.get_Shape(ps).Extents.xMin) / 2;
double height = pois.get_Shape(ps).Extents.yMin + (pois.get_Shape(ps).Extents.yMax - pois.get_Shape(ps).Extents.yMin) / 2;
axMap1.DrawCircleEx(handle, width, height, 5.0, 255, true);
axMap1.AddLabel(shape4, poislabel, (UInt32)(System.Drawing.ColorTranslator.ToOle
(System.Drawing.Color.Black)), pois1, pois2, MapWinGIS.tkHJustification.hjCenter);
}
// the following is to display the latitude
string latitude;// longitude;
double latx1, latx2;
for (int counter = 0; counter < roadsfin.NumShapes - 1; counter++)
{
latitude = System.Convert.ToString(roadsfin.get_CellValue(1, counter));
latx1 = roadsfin.get_Shape(counter).Extents.xMin + (roadsfin.get_Shape(counter).Extents.xMax - roadsfin.get_Shape(counter).Extents.xMin) / 2;
latx2 = roadsfin.get_Shape(counter).Extents.yMin + (roadsfin.get_Shape(counter).Extents.yMax - roadsfin.get_Shape(counter).Extents.yMin) / 2;
axMap1.AddLabel(shape7, latitude, (UInt32)(System.Drawing.ColorTranslator.ToOle
(System.Drawing.Color.Black)), latx1, latx2, MapWinGIS.tkHJustification.hjCenter);
}
// sample displaying of location
// the following are the codes to show the names of pofw
string pofwlabel;
double pofw1, pofw2;
for (int pf = 0; pf < pofw.NumShapes - 1; pf++)
{
pofwlabel = System.Convert.ToString(pofw.get_CellValue(4, pf));
pofw1 = pofw.get_Shape(pf).Extents.xMin + (pofw.get_Shape(pf).Extents.xMax - pofw.get_Shape(pf).Extents.xMin) / 2;
pofw2 = pofw.get_Shape(pf).Extents.yMin + (pofw.get_Shape(pf).Extents.yMax - pofw.get_Shape(pf).Extents.yMin) / 2;
axMap1.AddLabel(shape5, pofwlabel, (UInt32)(System.Drawing.ColorTranslator.ToOle
(System.Drawing.Color.Black)), pofw1, pofw2, MapWinGIS.tkHJustification.hjCenter);
}
// the following are the codes to show the names of places
string placeslabel;
double places1, places2;
for (int pl = 0; pl < places.NumShapes - 1; pl++)
{
placeslabel = System.Convert.ToString(places.get_CellValue(4, pl));
places1 = places.get_Shape(pl).Extents.xMin + (places.get_Shape(pl).Extents.xMax - places.get_Shape(pl).Extents.xMin) / 2;
places2 = places.get_Shape(pl).Extents.yMin + (places.get_Shape(pl).Extents.yMax - places.get_Shape(pl).Extents.yMin) / 2;
axMap1.AddLabel(shape6, placeslabel, (UInt32)(System.Drawing.ColorTranslator.ToOle
(System.Drawing.Color.Black)), places1, places2, MapWinGIS.tkHJustification.hjCenter);
}
double x_etchos = 125.141;
double y_etchos = 6.117;
double x_leche = 125.141;
double y_leche = 6.117;
// MapWinGIS.Extents ext = axMap1.Extents as MapWinGIS.Extents;
double ewanko;
for (int test1 = 0; test1 < roadsfin.NumShapes; test1++)
{
ewanko = System.Convert.ToDouble(roads.get_CellValue(4, test1));
if (x_etchos > roadsfin.get_Shape(test1).Extents.xMin && x_etchos < roadsfin.get_Shape(test1).Extents.xMax && y_etchos > roadsfin.get_Shape(test1).Extents.yMin && y_etchos < roadsfin.get_Shape(test1).Extents.yMax)
{
double width = roadsfin.get_Shape(test1).Extents.xMin + (roadsfin.get_Shape(test1).Extents.xMax - roadsfin.get_Shape(test1).Extents.xMin) / 2;
double height = roadsfin.get_Shape(test1).Extents.yMin + (roadsfin.get_Shape(test1).Extents.yMax - roadsfin.get_Shape(test1).Extents.yMin) / 2;
MessageBox.Show("width and height: " + width + " " + height);
//MessageBox.Show("x and y: " + ext.xMax + " <<max_X-min_X>> " + ext.xMin + " " + ext.yMax + " <<max_Y-min_X>> " + ext.yMin);
ext.SetBounds(x_etchos - width, y_etchos - height, 0.0, x_etchos + width, y_etchos + height, 0.0);
Application.DoEvents();
axMap1.ProjToPixel(x_etchos, y_etchos, ref x_leche, ref y_leche);
axMap1.DrawCircleEx(handle, x_leche, y_leche, 5.0, 255, true);
}
}

The problem with this code is you are only calculating position and placement once. On load. You need to re-write the form class to handle zoom/pan events and re-calculate the shape positions and size.
Programs usually contain more than one function. the application.doEvents will process events in the queue but you aren't updating the shapes based on the events.
TIP
also things like
pofw1 = pofw.get_Shape(pf).Extents.xMin + (pofw.get_Shape(pf).Extents.xMax - pofw.get_Shape(pf).Extents.xMin) / 2;
pofw2 = pofw.get_Shape(pf).Extents.yMin + (pofw.get_Shape(pf).Extents.yMax - pofw.get_Shape(pf).Extents.yMin) / 2;
are easily put in a function since you call it multiple times in that function.
private Point getCenter( Extents ext ) {
Point p;
p.X = ext.xMin + (ext.xMax - ext.xMin)/2.0;
p.Y = ext.yMin + (ext.yMax - ext.yMin)/2.0;
return p;
}
called by
Point pofwPoint = getCenter(pofw.get_Shape(pf).Extents);

Related

C# UWP Render InkStrokes in InkCanvas Seperately

enter image description here
I have captured points data from bamboo slate,and converted them to Windows.UI.Input.Inking.InkStroke data.Then I put them in a InkPresenter.StrokeContainer rendered like this image above.Strokes sticked to each other,how can I seperate them?
This is my code below.
private void DataDisplay()
{
List<InkPoint> list = new List<InkPoint>();
List<InkStroke> strokes = new List<InkStroke>();
InkDrawingAttributes drawingAttributes1 = new InkDrawingAttributes();
drawingAttributes1.Color = Colors.Black;
drawingAttributes1.Size = new Size(1, 1);
InkStrokeBuilder builder = new InkStrokeBuilder();
builder.SetDefaultDrawingAttributes(drawingAttributes1);
inkCanvas.InkPresenter.UpdateDefaultDrawingAttributes(drawingAttributes1);
inkCanvas.InkPresenter.IsInputEnabled = true;
foreach (var item in data.Stroke)
{
string[] strArray = item.Split(',');
for (int i = 9; i <= strArray.Length - 5; i += 5)
{
float x = float.Parse(strArray[i]) / 30;
float y = float.Parse(strArray[i + 1]) / 30;
float pressure = float.Parse(strArray[i + 2]) / 1000;
Point point = new Point(x, y);
InkPoint ip = new InkPoint(point, pressure);
list.Add(ip);
}
Matrix3x2 matrix3X2 = new Matrix3x2(1, 0, 0, 1, 0, 0);
InkStroke newStroke = builder.CreateStrokeFromInkPoints(list, matrix3X2);
strokes.Add(newStroke);
}
inkCanvas.InkPresenter.StrokeContainer.AddStroke(strokes);
}

How to construct a graph of weights from an image

Project: intelligence scissors.
The first part of the project is to load an image (in the form of RGBPixel 2d array) then to construct a graph of weights to use it later to determine the shortest path between 2 points on the image (the 2 points will be determined by an anchor and a free point..In short i will have the source and the destination points).
I have a function that open the image and return a RGBPixel 2d array already made.Now image is loaded i want to construct the graph to do the i should use a function called CalculatePixelEnergies here is the code
public static Vector2D CalculatePixelEnergies(int x, int y, RGBPixel[,] ImageMatrix)
{
if (ImageMatrix == null) throw new Exception("image is not set!");
Vector2D gradient = CalculateGradientAtPixel(x, y, ImageMatrix);
double gradientMagnitude = Math.Sqrt(gradient.X * gradient.X + gradient.Y * gradient.Y);
double edgeAngle = Math.Atan2(gradient.Y, gradient.X);
double rotatedEdgeAngle = edgeAngle + Math.PI / 2.0;
Vector2D energy = new Vector2D();
energy.X = Math.Abs(gradientMagnitude * Math.Cos(rotatedEdgeAngle));
energy.Y = Math.Abs(gradientMagnitude * Math.Sin(rotatedEdgeAngle));
return energy;
}
This function use CalculateGradientAtPixel, Here is the code in case you want it.
private static Vector2D CalculateGradientAtPixel(int x, int y, RGBPixel[,] ImageMatrix)
{
Vector2D gradient = new Vector2D();
RGBPixel mainPixel = ImageMatrix[y, x];
double pixelGrayVal = 0.21 * mainPixel.red + 0.72 * mainPixel.green + 0.07 * mainPixel.blue;
if (y == GetHeight(ImageMatrix) - 1)
{
//boundary pixel.
for (int i = 0; i < 3; i++)
{
gradient.Y = 0;
}
}
else
{
RGBPixel downPixel = ImageMatrix[y + 1, x];
double downPixelGrayVal = 0.21 * downPixel.red + 0.72 * downPixel.green + 0.07 * downPixel.blue;
gradient.Y = pixelGrayVal - downPixelGrayVal;
}
if (x == GetWidth(ImageMatrix) - 1)
{
//boundary pixel.
gradient.X = 0;
}
else
{
RGBPixel rightPixel = ImageMatrix[y, x + 1];
double rightPixelGrayVal = 0.21 * rightPixel.red + 0.72 * rightPixel.green + 0.07 * rightPixel.blue;
gradient.X = pixelGrayVal - rightPixelGrayVal;
}
return gradient;
}
In my code of graph construction i decided to make a 2d double array to hold the weights, here what i do but it seems to be a wrong construction
public static double [,] calculateWeights(RGBPixel[,] ImageMatrix)
{
double[,] weights = new double[1000, 1000];
int height = ImageOperations.GetHeight(ImageMatrix);
int width = ImageOperations.GetWidth(ImageMatrix);
for (int y = 0; y < height - 1; y++)
{
for (int x = 0; x < width - 1; x++)
{
Vector2D e;
e = ImageOperations.CalculatePixelEnergies(x, y, ImageMatrix);
weights[y + 1, x] = 1 / e.X;
weights[y, x + 1] = 1 / e.Y;
}
}
return weights;
}
an example for an image
an other example for an image

OxyPlot heatmap rectangle comments

Lately I've been working with OxyPlot library doing some charts. I was wondering if I can have a heatmap with comments for each one of the rectangles. looking forward to an answer.
I finally found that I needed to make a new class and extend the heatmap series and override the RenderLabels method in order to change its functionality.
protected override void RenderLabels(IRenderContext rc, OxyRect rect)
{
var clip = this.GetClippingRect();
int m = this.Data.GetLength(0);
int n = this.Data.GetLength(1);
double fontSize = (rect.Height / n) * this.LabelFontSize;
double left = this.X0;
double right = this.X1;
double bottom = this.Y0;
double top = this.Y1;
var s00 = this.Orientate(this.Transform(left, bottom)); // disorientate
var s11 = this.Orientate(this.Transform(right, top)); // disorientate
double sdx = (s11.X - s00.X) / (m - 1);
double sdy = (s11.Y - s00.Y) / (n - 1);
for (int i = 0; i < m; i++)
{
for (int j = 0; j < n; j++)
{
var point = this.Orientate(new ScreenPoint(s00.X + (i * sdx), s00.Y + (j * sdy))); // re-orientate
var v = GetValue(this.Data, i, j);
var color = this.ColorAxis.GetColor(v);
var hsv = color.ToHsv();
var textColor = hsv[2] > 0.6 ? OxyColors.Black : OxyColors.White;
var label = this.Labels[i, j];
rc.DrawClippedText(
clip,
point,
label,
textColor,
this.ActualFont,
fontSize,
500,
0,
HorizontalAlignment.Center,
VerticalAlignment.Middle);
}
}
}

image problems with webcamtexture

I have a little problem in my Unity work, I'm trying to get the images from a Webcam texture, and I'll keep it in a byte []. the problem comes when I show the image, which is not seen correctly, it looks like some type of grid mesh. I think the problem is in the for I use to pass the pixels. I hope you can help me.
void Update()
{
//texto.text = texto.text + width +" / "+ height + " / " + ini.ToString()+ " mal: "+ testo().ToString()+ " SizeIMG: "+ imgData.Length + " NUEVO: "+ nuevo +"\n";
imgData = null;
imgData = new byte[width * height * 3];
resultado = null;
resultado = new byte[width * height * 3];
color = webcam.GetPixels32();
for (int i = 0; i < color.Length; i += 3)
{
imgData[(i * 3)] = color[i].r;
imgData[(i * 3) + 1] = color[i].g;
imgData[(i * 3) + 2] = color[i].b;
}
color = null;
//video(imgData, resultado);
//ProcessFrame(imgData, resultado, 0, 0, 0,0, nuevo);
nuevo = false;
textura2 = new Texture2D(width, height, TextureFormat.RGB24, false);
textura2.LoadRawTextureData(imgData);
textura2.Apply();
//Left IMAGE
renderer.material.mainTexture = textura2;
textura2 = null;
RightImage.GetComponent<Renderer>().material.mainTexture = webcam;
if (kont == 30)
{
texto.text = "";
kont = 0;
}
kont++;
Resources.UnloadUnusedAssets();
}
I think the issue is how your indexing into your imgData array. You're incrementing i by three in addition to multiplying by 3.
int bytesPerPixel = 3;
const int indexR = 0;
const int indexG = 1;
const int indexB = 2;
for(var i = 0; i < color.Length; i++)
{
imgData[(i * bytesPerPixel) + indexR] = color[i].r;
imgData[(i * bytesPerPixel) + indexG] = color[i].g;
imgData[(i * bytesPerPixel) + indexB] = color[i].b;
}

Index out of bounds when calculating pixel index

I have my image cropping app based on:
http://www.c-sharpcorner.com/UploadFile/55275a/windowsphone-image-crop-with-rectangle/
I modified it a little bit so I can resize rectangle instead of creating new
so my whole method look like:
private async void Accept_Click(object sender, EventArgs e)
{
WriteableBitmap wb = new WriteableBitmap(image);
double originalImageWidth = wb.PixelWidth;
double originalImageHeight = wb.PixelHeight;
double displayedWidth = image1.ActualWidth;
double displayedHeight = image1.ActualHeight;
double widthRatio = originalImageWidth / displayedWidth;
double heightRatio = originalImageHeight / displayedHeight;
r = (Rectangle) (from c in LayoutRoot.Children
where c.Opacity == .5 select c).First();
GeneralTransform gt = r.TransformToVisual(LayoutRoot);
Point p = gt.Transform(new Point(0, 0));
Point1 = (r.TransformToVisual(this)).Transform(new Point(0, 0));
Point2 = new Point(Point1.X + r.Width, Point1.Y + r.Height);
WriteableBitmap newImage = new WriteableBitmap(
(int) (widthRatio * Math.Abs(Point2.X - Point1.X)),
(int) (heightRatio * Math.Abs(Point2.Y - Point1.Y)));
int xoffset = (int) (((Point1.X < Point2.X) ? Point1.X : Point2.X) * widthRatio);
int yoffset = (int) (((Point1.Y < Point2.Y) ? Point1.Y : Point2.X) * heightRatio);
if (newImage.Pixels.Length > 0)
{
for (int i = 0; i < newImage.Pixels.Length; i++)
{
int x = (int) ((i % newImage.PixelWidth) + xoffset);
int y = (int) ((i / newImage.PixelWidth) + yoffset);
newImage.Pixels[i] = wb.Pixels[y * wb.PixelWidth + x];
}
using (MemoryStream ms = new MemoryStream())
{
newImage.SaveJpeg(ms, (int) newImage.PixelWidth,
(int) newImage.PixelHeight, 0, 100);
image.SetSource(ms);
}
}
else
{
}
ProgressBar pb = new ProgressBar();
pb.IsEnabled = true;
LayoutRoot.Children.Add(pb);
int idReceipt = (int) PhoneApplicationService.Current.State["paragon"];
await ReceiptsHelper.addPhotosToReceipt(image, idReceipt);
NavigationService.Navigate(new Uri("/7.0/StronaParagonu.xaml", UriKind.Relative));
}
When my image is vertical everything works fine, but when my image is horizontal I get Array Index Out Of Bounds Exception at:
newImage.Pixels[i] = wb.Pixels[y * wb.PixelWidth + x];
I don't know exactly what am I doing wrong.
Anybody can help?
EDIT:
I changed my code to:
if (wb.PixelWidth > wb.PixelHeight)
{
for (int i = 0; i < newImage.Pixels.Length; i++)
{
int x = (int)((i % newImage.PixelWidth) + xoffset);
int y = (int)((i / newImage.PixelWidth) + yoffset);
newImage.Pixels[i] = wb.Pixels[x * wb.PixelHeight + y];
}
}
else
{
for (int i = 0; i < newImage.Pixels.Length; i++)
{
int x = (int)((i % newImage.PixelWidth) + xoffset);
int y = (int)((i / newImage.PixelWidth) + yoffset);
newImage.Pixels[i] = wb.Pixels[y * wb.PixelWidth + x];
}
}
In result I've got something like this
Maybe there is some workaround in which I can flip image 90 degree?
I tried WriteableBitmapEx but it doesnt work.
First thing I see is:
int yoffset = (int) (((Point1.Y < Point2.Y) ? Point1.Y : Point2.X) * heightRatio);
I guess there should be Point2.Y?
Second thing is what #Rashed mentioned in comment:
When you want get horizontal image, you must change X and Y place: newImage.Pixels[i] = wb.Pixels[x * wb.PixelHeight + y];
But please take a note I'm really guessing here since it's late and I don't see sharp ;-)

Categories

Resources