Create video thumbnails from path - android-image

I'm trying for some time to create thumbnails from video without success. In fact I found several solutions on web but none work on all Android versions.
The only method that seems to work, works by using the id of the video. My problem is I need to use the video path but i don't find a way to do that. (no method works on all versions of Android.)
I need a solution that works on all versions greater than 2.0 would be sufficient.
Could you help me? Thank you in advance!

ThumbnailUtils.createVideoThumbnail (String filePath, int kind) could help?

Here is how i resolved it:
Bitmap thumbnail = ThumbnailUtils.createVideoThumbnail(mSeconFilePath,
MediaStore.Video.Thumbnails.MINI_KIND);
int sdk = android.os.Build.VERSION.SDK_INT;
if (sdk < android.os.Build.VERSION_CODES.JELLY_BEAN) {
mVideoView.setBackgroundDrawable(new BitmapDrawable(getResources(), thumbnail));
} else {
mVideoView.setBackground(new BitmapDrawable(getResources(), thumbnail));
}

Related

Firefox adding some data into simple storage

I am learning how to make firefox extensions and have gotten totally confused... so I thought I would start from the basics again.
Can you make me (or walk me through creating) a simple skeleton extension that saves "ryan" into sqlite storage, so that it is available even on the browser restart?
From there I think I can start modifying it to run all the different code that exists only in my head... and to answer my own questions :))
Thanks!
Ryan
This is even simpler if you use the Addon SDK.
var storage = require("simple-storage").storage;
if (storage.name) {
console.log (storage.name);
}
else {
console.log ("Storing!");
storage.name = "ryan";
}
This will output "Storing!" the first time it's run, and "ryan" subsequent times.

Qt: read video dimension without creating a video player

I need to read the dimensions of a given video file (its width and height), without constructing a video player, like Phonon, e.g. My question is which class I should use to get access to this data. I have already tried using QPixmap and QMovie, but niether of them supports *.mov.
Thank you!
Pavlo, you can try this:
QMediaContent media("myMovie.mov");
QSize resolution = media.canonicalResource().resolution();
The code uses QMediaResource class from Qt Mobility project. I haven't tried it yet and I suppose you need at least a correct backend (plugin that is capable of reading MOV format). I'm giving this answer only from API overview.
Hope this helps.
I finally solved my problem and I thought I'd share my solution with everybody else.
In the class constructor I initialize the following two variables:
media = new Phonon::MediaObject(this);
videoWidget = new Phonon::VideoWidget;
I connect a signal of media to a slot in my class:
connect(media,SIGNAL(stateChanged(Phonon::State,Phonon::State)),
this,SLOT(videoState(Phonon::State,Phonon::State)));
I let the user choose a video file:
QString filename = QFileDialog::getOpenFileName(this,tr("Choose video file"),QDir().homePath(),tr("Video files (*.mov *.mpg *.avi)"));
And apply this file to the media object:
media->setCurrentSource(filename);
Phonon::createPath(media,videoWidget);
Because media object is already connected to a slot, every change in media can be monitored with its help.
void VideoModuleDialog::videoState(Phonon::State newState, Phonon::State oldState)
{
if(newState == Phonon::PlayingState || newState == Phonon::StoppedState)
{
width->setText(QString().number(videoWidget->sizeHint().width()));
height->setText(QString().number(videoWidget->sizeHint().height()));
}
if(newState == Phonon::ErrorState)
{
QMessageBox::critical(this,tr("Video file error!"),
tr("Video file error: ") + media->errorString(),QMessageBox::Ok);
}
}
I must admit, however, that this code seems to me to be quite slow. Phonon library is used in my program only in one place, and this is here, in a dialog window where user can choose a video clip to embed, and i want the video dimensions to be read from file. It takes some time until this dialog window opens, so I guess, this solution is a bit too harsh for my problem. However, I was not able to find another solution. If there are different opinions as to the subject of this post, I'd be glad to hear them.

WatiN - getting past the certificate error page

Anyone know how to use CertificateWarningHandler in WatiN?
I've got as far as...
IE ie = new IE("https://mysite.aspx");
CertificateWarningHandler cwh = new CertificateWarningHandler(CertificateWarningHandler.ButtonsEnum.Yes);
cwh.HandleDialog(new Window(ie.hWnd));
... which does precisely nothing.
On a more general note, how on earth do you people manage to use this tool? The documentation is nearly useless, and there doesn't seem to be any decent resource online. I must be missing something because it's taken me about half an hour to write 3 lines of code that don't even work.
I'm using something similar to what Saar is using and it works fine (my tests are cross-browser).
//Override security warning in browser
{
if (Browser.Link(Find.ById("overridelink")).Exists)
{
Browser.Link(Find.ById("overridelink")).Click();
Browser.WaitForComplete();
}
else
{
Browser.WaitForComplete();
} //end else
}
I'm not a developer, and I've found that there's plenty of information out there on WatiN and others post code samples and the like that are really helpful. Google is one of my best friends when it comes to finding WatiN help. You'll get the hang of it.
have you tried following already?
ie.DialogWatcher.Add(cwh);
or just
ie.DialogWatcher.Add(new CertificateWarningHandler());
Update: After comment.
Actually this works for me.
further may be following will help
Browser browser = ie;
if (browser.Links.Exists("overridelink"))
{
browser.Link("overridelink").Click();
}

Is it possible to detect if Microsoft Excel is installed from a Web Application

I'm working on a web app (ASP.NET) that has some features that require Microsoft Excel installed on the client. I'd like to disable those features if Excel is not present.
Windows/IE/Excel only solutions are fine. This is not a multi-browser, multi-OS web app.
Any clever JavaScript out there to accomplish this?
No.
You're not allowed to dive into the client machine deep enough to figure out that part. The best you can do is to either assume it is installed, and ponder hard about what happens if it is not, or just ask the user.
You can do something like this, but you'll get all kinds of security warnings:
<script>
var excelInstalled;
try
{
var excel = new ActiveXObject("Excel.Application");
excelInstalled = true;
}
catch(e)
{
excelInstalled = false;
}
alert("excelInstalled: " + excelInstalled);
</script>
Why Excel? What if I have OpenOffice.org instead?
Just warn the user what you're going to send them, mark the link with "Excel file", and let him decide.
function hasOfficePlugin() {
var toCheckExt = ['', '12', '13', '14', '15'], i, n, mt;
for (i = 0, n = toCheckExt.length; i < n; i++) {
mt = navigator.mimeTypes['application/x-msoffice' + toCheckExt[i]];
if (mt && mt.enabledPlugin && mt.enabledPlugin.name) {
return true;
}
}
return false;
}
I've tested the above with Office 11 (2003), and Office 12 (2007), and it seems to work well in Firefox, Safari, Chrome, and Opera. Though it doesn't work in IE, because the navigator.mimeTypes objects in IE is always empty.
It's checking for the existence of an MS Office plugin. I don't know much about this plugin - quite possibly it's not always installed with office... But I think that, if the above returns true, it's a pretty strong signal that Excel is installed. Course it's probably of limited use since it doesn't work in IE, but maybe you can do something with it...
you can not access client information outside of the web browser context, using standard technologies. but I see one of answers is using some ActivX object to detect Excel. anyway these kinds of technologies work only on Internet Explorer on windows. what about Mac? what about other browsers like opera or firefox or chrome on windows?
I think it is better to let the user inform you about this. just ask the user if she has excel installed or not:
var isExcel = window.confirm('dear user if you have Microsoft Excel installed please click on ok, otherwise click on cancel. thank you.');
This is bad idea at start. What ever you are trying to do - reconsider.
If you still insist:
Try to crete ActiveXObject for Excel and then for OpenOffice.
If it fails, redirect to NoExcel.html or send XMLRequest to server.
Also, you can try to find out via JavaScritp if there is XLS file extension handler.
And last, you can install your ActiveX which checks if Excel is installed.
This is for windows. No idea for mac, linux, mobile...
You can bet that any way you make it work will stop working with next hotfix.

How to efficiently scale and crop images in an ASP.NET app?

We're having problems with an ASP.NET application which allows users to upload, and crop images. The images are all scaled to fixed sizes afterwards. We basically run out of memory when a large file is processed; it seems that the handling of JPEG is rather inefficient -- we're using System.Drawing.BitMap. Do you have any general advice, and perhaps some pointers to a more efficient image handling library? What experiences do you have?
I had the same problem, the solution was to use System.Drawing.Graphics to do the transformations and dispose every bitmap object as soon as I was finished with it. Here's a sample from my library (resizing) :
public Bitmap ApplyTo(Bitmap bitmap)
{
using (bitmap)
{
Bitmap newBitmap = new Bitmap(bitmap, CalculateNewSize(bitmap));
using (Graphics graphics = Graphics.FromImage(newBitmap))
{
graphics.SmoothingMode =
SmoothingMode.None;
graphics.InterpolationMode =
InterpolationMode.HighQualityBicubic;
graphics.CompositingQuality =
CompositingQuality.HighQuality;
graphics.DrawImage(
bitmap,
new Rectangle(0, 0, newBitmap.Width, newBitmap.Height));
}
return newBitmap;
}
}
I found imageresizer and its great. and good API. Works Great.
Downloaded from Visual studio 2010 Extension Manager: http://nuget.org/.
Easy Steps to download API in VS-2010:
1). Install Extension http://nuget.org/.
3). Find and Install ImageResizing
4).Then Code: (I m using here cropping. you can use any) Documentation on imageresizing.net
string uploadFolder = Server.MapPath(Request.ApplicationPath + "images/");
FileUpload1.SaveAs(uploadFolder + FileUpload1.FileName);
//The resizing settings can specify any of 30 commands.. See http://imageresizing.net for details.
ResizeSettings resizeCropSettings = new ResizeSettings("width=200&height=200&format=jpg&crop=auto");
//Generate a filename (GUIDs are safest).
string fileName = Path.Combine(uploadFolder, System.Guid.NewGuid().ToString());
//Let the image builder add the correct extension based on the output file type (which may differ).
fileName = ImageBuilder.Current.Build(uploadFolder + FileUpload1.FileName, fileName, resizeCropSettings, false, true);
Try!!! its very awsumm and easy to use. thanks.
A couple of thoughts spring to mind -
What size of images do you allow
your users to upload and can you
impose restrictions on this?
When you're using the
System.Drawing.Bitmap class, are you
remembering to dispose of it
correctly? We found one of the primary causes of System.OutOfMemoryException exceptions on our shared hosting platform was users not disposing of Bitmap objects correctly.
Kev
There was an older bug with .net that all images would default to 32 bits per pixel - at this size you can exhaust your memory pretty fast. Please use PixelFormat structure to make sure this is not the case for your problem.
This link might help: http://msdn.microsoft.com/en-us/library/aa479306.aspx
Do you perhaps have a stack trace to look at?
I have also done some image editing after a user has uploaded an image. The only problems that I ran into were restrictions on file upload size on the browsers and timeouts. But nothing related to .Net's libraries.
Something else to consider. If you are doing multiple images or have some dangerous looping somewhere then are you making sure to flush() and dispose() things.

Resources