In a mobile web application I am developing, users are allowed to take a picture with their camera and the camera image is uploaded to a server. The issue I am having is that on iOS devices, images get an EXIF Orientation tag associated with them such as "ROTATE 90 CW". This orientation tag causes the image to be displayed in an incorrect orientation when it is displayed. For example, if the user takes a picture of something with their iPhone in portrait orientation, the image appears to be rotated to landscape when viewed on the server. I want to correct this issue on the server-side using VB.Net so that I automatically detect the EXIF Orientation tag and if it is "ROTATE 90 CW" (or any other value that will make the image appear to be displayed incorrectly), then I want to automatically rotate the image to the correct orientation. In summary, I want the image on the server to appear exactly as it appeared when the user took the picture with their camera.
Can someone post the code that will do this? Thanks in advance.
For anyone who needs this, I basically resolved the issue using this code in VB.Net. I found this to be just what I needed:
Public Function TestRotate(sImageFilePath As String) As Boolean
Dim rft As RotateFlipType = RotateFlipType.RotateNoneFlipNone
Dim img As Bitmap = Image.FromFile(sImageFilePath)
Dim properties As PropertyItem() = img.PropertyItems
Dim bReturn As Boolean = False
For Each p As PropertyItem In properties
If p.Id = 274 Then
Dim orientation As Short = BitConverter.ToInt16(p.Value, 0)
Select Case orientation
Case 1
rft = RotateFlipType.RotateNoneFlipNone
Case 3
rft = RotateFlipType.Rotate180FlipNone
Case 6
rft = RotateFlipType.Rotate90FlipNone
Case 8
rft = RotateFlipType.Rotate270FlipNone
End Select
End If
Next
If rft <> RotateFlipType.RotateNoneFlipNone Then
img.RotateFlip(rft)
System.IO.File.Delete(sImageFilePath)
img.Save(sImageFilePath, System.Drawing.Imaging.ImageFormat.Jpeg)
bReturn = True
End If
Return bReturn
End Function
For anyone interested... C# version.
public static bool TestRotate(string filePath)
{
var rft = RotateFlipType.RotateNoneFlipNone;
var img = Image.FromFile(filePath);
var properties = img.PropertyItems;
var value = false;
foreach (var prop in properties.Where(i => i.Id == 274))
{
var orientation = BitConverter.ToInt16(prop.Value, 0);
rft = orientation == 1 ? RotateFlipType.RotateNoneFlipNone :
orientation == 3 ? RotateFlipType.Rotate180FlipNone :
orientation == 6 ? RotateFlipType.Rotate90FlipNone :
orientation == 8 ? RotateFlipType.Rotate270FlipNone :
RotateFlipType.RotateNoneFlipNone;
}
if (rft != RotateFlipType.RotateNoneFlipNone)
{
img.RotateFlip(rft);
File.Delete(filePath);
img.Save(filePath, ImageFormat.Jpeg);
value = true;
}
return value;
}
Related
I am using DotNetBrowser Control in my c# desktop application. I am not able to get captcha image using this.
It is easy in Webbrowser control but in DotNetBrowser I don't know how to do so in c#
https://dotnetbrowser.support.teamdev.com/support/solutions/9000111998
This code is working if I am using Webbrowser control
private Image getCaptcha()
{
HtmlElement ement = webBrowser1.Document.GetElementById("imgCaptcha");
if (ement == null)
{
return null;
}
mshtml.HTMLWindow2 w2 = (mshtml.HTMLWindow2)webBrowser1.Document.Window.DomWindow;
w2.execScript("var ctrlRange = document.body.createControlRange();
ctrlRange.add(document.getElementById('imgCaptcha'));
ctrlRange.execCommand('Copy');", "javascript");
return Clipboard.GetImage();
}
I need similar code in DotNetBrowser control
You can use the 'Browser.ImageProvider.GetImage' method to get the screenshot of the page and then crop this image to the bounds of the captcha image.
The only restriction is that the Browser should use the lightweight rendering mode as getting an image is unavailable in the heavyweight mode.
The described approach may look like the following source code:
browserView = new WinFormsBrowserView(BrowserFactory.Create(BrowserType.LIGHTWEIGHT));
//...
browserView.Browser.SetSize(1024, 768);
Bitmap screenshot = browserView.Browser.ImageProvider.GetImage() as Bitmap;
DOMElement captchaElement = browserView.Browser.GetDocument().GetElementById("imgCaptcha");
pictureBox1.Image = screenshot?.Clone(captchaElement.BoundingClientRect, screenshot.PixelFormat);
I am new in ArcGis. I came across a requirement that I need a command on the ArcGis Toolbar. On click the command, a Windows Form will open and there one region selector button is there. upon clicking on the button, the current Form UI must be minimized and the user will be allowed to draw a polygon. Can you please help on how to do that. Here is the code. I took normal windows button and wrote the below code in the click event.
_application = ((IApplication)_hookHelper.Hook);
IMxDocument pMxDoc = (IMxDocument)_application.Document;
IMap pMap = (IMap)pMxDoc.FocusMap;
IActiveView pActiveView = (IActiveView)pMap;
if (pActiveView == null)
{
return;
}
//// Changing the state of the Window.
if (this.WindowState == FormWindowState.Normal || this.WindowState == FormWindowState.Maximized)
{
this.WindowState = FormWindowState.Minimized;
// this.Hide();
}
ESRI.ArcGIS.Display.IScreenDisplay screenDisplay = pActiveView.ScreenDisplay;
// Constant
screenDisplay.StartDrawing(screenDisplay.hDC, (System.Int16)ESRI.ArcGIS.Display.esriScreenCache.esriNoScreenCache); // Explicit Cast
ESRI.ArcGIS.Display.IRgbColor rgbColor = new ESRI.ArcGIS.Display.RgbColorClass();
rgbColor.Blue = 111;
ESRI.ArcGIS.Display.IColor color = rgbColor; // Implicit Cast
ESRI.ArcGIS.Display.ISimpleFillSymbol simpleFillSymbol = new ESRI.ArcGIS.Display.SimpleFillSymbolClass();
simpleFillSymbol.Color = color;
ESRI.ArcGIS.Display.ISymbol symbol = simpleFillSymbol as ESRI.ArcGIS.Display.ISymbol; // Dynamic Cast
ESRI.ArcGIS.Display.IRubberBand rubberBand = new ESRI.ArcGIS.Display.RubberRectangularPolygonClass();
// ESRI.ArcGIS.Display.IRubberBand rubberBand = new ESRI.ArcGIS.Display.RubberPolygonClass();
ESRI.ArcGIS.Geometry.IGeometry geometry = rubberBand.TrackNew(screenDisplay, symbol);
screenDisplay.SetSymbol(symbol);
screenDisplay.DrawPolygon(geometry);
screenDisplay.FinishDrawing();
I am also not getting any mouse event and the UI is not minimized while starting drawing the polygon. Can anyone please help.
Have we check the white paper for ArcGIS runtime SDK for .Net?
http://resources.arcgis.com/en/help/runtime-wpf/concepts/index.html#/Essential_vocabulary/01700000004z000000/
I am programmatically drawing a flowchart using Java UNO Runtime Reference in which I want to display grid Lines permanently.Using following code I was able to display the Grid Lines but they are toggled ON and OFF alternately when the code executes.
XModel xModel = (XModel) UnoRuntime.queryInterface(XModel.class, xDrawDoc);
XController xController = xModel.getCurrentController();
XDispatchProvider xDisp = UnoRuntime.queryInterface(XDispatchProvider.class, xController);
XMultiComponentFactory xMCF = xContext.getServiceManager();
Object dispatchHelper = xMCF.createInstanceWithContext("com.sun.star.frame.DispatchHelper", xContext);
XDispatchHelper xDispatchHelper = UnoRuntime.queryInterface(XDispatchHelper.class, dispatchHelper);
PropertyValue[] navigatorDesc = new PropertyValue[1];
navigatorDesc[0] = new PropertyValue();
navigatorDesc[0].Name = "GridVisible";
navigatorDesc[0].Value = true;
xDispatchHelper.executeDispatch(xDisp, ".uno:GridVisible" , "", 0, navigatorDesc);
I want to permanently show Grid Lines.How can I achieve this using Java.Pls suggest. If there is any way of checking whether the Grid Lines are ON(any method which could return a boolean value), this could also be a useful approach.
I'm writing a Photoshop script in extendscript/javascript and I'm trying to verify that the document is using just one color (plus transparency). What I would like to do is change the document mode to Indexed Color and then get the values in the color table.
I have successfully changed the document mode to Indexed Color but can't figure out how to access the color table or the color values inside of it.
My working alternative is to use a colorSampler to compare the values of each pixel, but that can take a couple of minutes to run on larger documents and speed is an issue for this project.
Please let me know if there is a way to access the color table or if you see a way to reduce the time it takes to run this function.
function sample_color(doc, sample_rate) {
var status = 'PASS'
var color_sampler = doc.colorSamplers.add([0,0])
var color_val = false //first (and hopefully only) color value in the document
var broke = false
for (x=1; x < doc.width; x+=sample_rate){
if (broke){
break
}
for (y=1; y < doc.height; y+=sample_rate){
color_sampler.move([UnitValue(x, 'px'), UnitValue(y, 'px')])
try{
var color = color_sampler.color //color of the current pixel
} catch(e) {
var color = false //color_sampler.color fails if the pixel is transparent
}
if (color != false){
if (color_val != false){
if (!color.isEqual(color_val)){
status = 'FAIL'
broke = true
break
}
} else {
color_val = color
}
}
}
}
color_sampler.remove()
return status
}
xbytor has written a couple of scripts for accessing colour tables. This link may be of use to you.
I'm trying to elaborate if the complete form is visible on screen. To clarify this: I don't care if the form is partially or fully hidden by another form, I just want to know, if the form is completely on the screen.
In Windows it is possible to move forms around, such that they are hidden half way. That is because you can move them past the actual bounds of any monitor. (Further to the left, right or bottom.) How can I check if that is the case in an easy way?
What I figured I could do is to check if the form is in bounds of SystemInformation.VirtualScreen. The problem here is, that not every pixel of the virtual screen is actually visible. Of course this would work if SystemInformation.MonitorCount = 1
Still I'm not really happy with this.
Public Function IsOnScreen(ByVal form As Form) As Boolean
Dim screens() As Screen = Screen.AllScreens
For Each scrn As Screen In screens
Dim formRectangle As Rectangle = New Rectangle(form.Left, form.Top, form.Width, form.Height)
If scrn.WorkingArea.Contains(formRectangle) Then
Return True
End If
Next
Return False
End Function
Best way I can think of is that you check that all four corners of the form are on a screen. Like this:
public bool FormOnScreen(Form frm) {
if (frm.IsHandleCreated) throw new InvalidOperationException();
if (!frm.Visible || frm.WindowState == FormWindowState.Minimized) return false;
return PointVisible(new Point(frm.Left, frm.Top)) &&
PointVisible(new Point(frm.Right, frm.Top)) &&
PointVisible(new Point(frm.Right, frm.Bottom)) &&
PointVisible(new Point(frm.Left, frm.Bottom));
}
private static bool PointVisible(Point p) {
var scr = Screen.FromPoint(p);
return scr.Bounds.Contains(p);
}