Showing posts with label Homebrew. Show all posts
Showing posts with label Homebrew. Show all posts

Monday, January 31, 2011

PictureBox with transparent overlay picture (C#)

Working yesterday on my remote control application that takes screenshots from a machine running XBMC I wanted to provide a better experience for the user by providing a “loading, please wait” transparent overlay image on top of the old screenshot image until new one comes in. Swimming through a lot of either complicated (Graphics.DrawImage in onPaint) or useless suggestions, I found one close to what I had in mind but didn’t give much attention to initially - using two PictureBox controls on top of each other, one for the main image and one for the overlay.

The trick is to change the background colour for the overlay picturebox to transparent and also change its parent. On top of that, if the main PictureBox is not in the top left corner and you want the overlay image to be centered, you also need to change the location of the overlay PictureBox relative to the new parent, otherwise it keeps the originally design margins.

In my case:
  • pictureBoxMain – displays the main image, image size mode Zoom;
  • pictureBoxOverlay – displays the “wait” transparent image, same size and anchoring, image size mode Center;
private void Form1_Load(object sender, EventArgs e)
{
  // Transparent background...  
  pictureBoxOverlay.BackColor = Color.Transparent;

  // Change parent for overlay PictureBox...
  pictureBoxOverlay.Parent    = pictureBoxMain;

  // Change overlay PictureBox position in new parent...
  pictureBoxOverlay.Location  = new Point(0, 0);
}


Sunday, June 13, 2010

ImageShack.us image upload (C# code)

Spent a couple hours yesterday looking for some code to upload images to ImageShack.us (I need it for a XBMC for Xbox remote control app I’m writting) and thought I might share the code.

The image I have is already available in a PictureBox and this only concentrates on the upload itself, won’t go into parsing the XML reply, that should be fairly easy to implement it yourself…

More information about the ImageShack.us Upload API and how to apply for a key here:
http://code.google.com/p/imageshackapi/wiki/ImageshackAPI

Working example here:
https://code.google.com/p/dandar3-apps/source/browse/#svn/trunk/ImageShack Upload

/**
 * ImageShack Unified upload API
 * http://code.google.com/p/imageshackapi/wiki/ImageshackAPI
 */
private void buttonUpload_Click(object sender, EventArgs e)
{
  //
  Cursor.Current = Cursors.WaitCursor;

  //
  // Init
  //
  String      filename    = "fake_name";
  String      mimeType    = "image/jpeg";
  ImageFormat imageFormat = System.Drawing.Imaging.ImageFormat.Jpeg;

  //
  // Prepare POST contents...
  //
  MemoryStream memoryStream = new MemoryStream();

  // Parts boundary
  String boundary = "-------" + DateTime.Now.Ticks.ToString("x");
  String crlf     = "\r\n";
  
  // Image file...
  write(memoryStream, "--" + boundary + crlf);
  write(memoryStream, String.Format("Content-Disposition: form-data; name=\"fileupload\"; filename=\"{0}\"", filename) + crlf);
  write(memoryStream, String.Format("Content-Type: {0}", mimeType) + crlf);
  write(memoryStream, crlf);
  
  pictureBox.Image.Save(memoryStream, imageFormat);
  write(memoryStream, crlf);
  
  // Other parameters (Key, Username, Password etc)
  NameValueCollection parameters = new NameValueCollection();
  parameters.Add("key",        "your_key");
  parameters.Add("a_username", "your_username");
  parameters.Add("a_password", "your_password");
  parameters.Add("tags",       "your_tags");

  foreach (String param_name in parameters.Keys)
  {
    write(memoryStream, "--" + boundary + crlf);
    write(memoryStream, String.Format("Content-Disposition: form-data; name=\"{0}\"", param_name) + crlf);
    write(memoryStream, crlf);
    write(memoryStream, parameters.Get(param_name));
    write(memoryStream, crlf);
  }

  // End...
  write(memoryStream, "--" + boundary + crlf);
  
  //
  // Upload (POST)...
  //
  try
  {
    HttpWebRequest webRequest = (HttpWebRequest) HttpWebRequest.Create("http://www.imageshack.us/upload_api.php");
    webRequest.ContentType    = "multipart/form-data; boundary=" + boundary;
    webRequest.Method         = "POST";

    //
    // Request
    //
    webRequest.ContentLength = memoryStream.Length;
    using (Stream requestStream = webRequest.GetRequestStream())
    {
      memoryStream.Seek(0, SeekOrigin.Begin);
      memoryStream.WriteTo(requestStream);
    }

    //
    // Response
    //
    using (WebResponse  webResponse  = webRequest.GetResponse())
    using (StreamReader streamReader = new StreamReader(webResponse.GetResponseStream()))
    {
      String imageshackReply = streamReader.ReadToEnd().Trim();
      MessageBox.Show(imageshackReply, "HTTP POST Response", MessageBoxButtons.OK, MessageBoxIcon.Information);
    }
  }
  catch (Exception ex)
  {
    MessageBox.Show(ex.Message, "HTTP POST Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
  }

  //
  // Clean-up...
  //
  memoryStream.Close();
}

/**
 * 
 */
private void write(MemoryStream p_memoryStream, String p_data)
{
  byte[] bytes = Encoding.ASCII.GetBytes(p_data);
  p_memoryStream.Write(bytes, 0, bytes.Length);
}

Saturday, June 12, 2010

Network Monitor v0.8

Network Monitor, 0.8 - 12 June 2010

[download: binaries | sources]

  • remeber last used network device;
  • rewrite 4 GB "wrapping" logic;
  • embed readme.txt (display in About box);

imageimage

Sunday, November 29, 2009

XBMC SVN Installer v1.0 – XBMC program plugin

News and skins from XBMCSVN.com (aka SSHCS).

Notes:

  • This plugin does not download builds - Xbox users should continue using T3CH Upgrader script to get the builds.
  • Skins may not extract correctly on Xbox - maybe something about the RAR version not being supported on Xbox...

Download:

Screenshots:

XBMC SVN Installer 1 XBMC SVN Installer 2 XBMC SVN Installer 3 XBMC SVN Installer 4 XBMC SVN Installer 5 XBMC SVN Installer 6

Saturday, September 12, 2009

XBMC Xbox Trac Changelog v1.0 – XBMC plugin

XBMC plugin to browse the XBMC for Xbox Trac changes from http://xbmc.org/trac.

Big thumbs up to Team XBMC in general for their work, and especially to the guys maintaining the Xbox branch.

Download:

Screenshots:

xbmc xbox trac changelog 1 xbmc xbox trac changelog 2

xbmc xbox trac changelog 3

Friday, March 20, 2009

Network Monitor v0.7

Network Monitor, 0.7 - 19 March 2009

[download: binaries | sources]

  • various small visual changes: new menu (view log & about), new “Started at” field, program icon, about dialog etc;
  • show only connected wireless and Ethernet network adapters;

Network Monitor v7.0

Sunday, April 27, 2008

XBMC Remote

I wanted to do this for quite some time, a remote control application for XBMC. Although the original XBMC Control application was doing pretty much what I wanted, the screenshot image was too small to read. So I decided to write my own and learn a bit of C# in the process... It's not doing too much, I've implemented a minimum set of keys and it allows for a good quality screenshot - in fact the image is captured at the XBMC TV resolution and then it's resized by the .Net PictureBox control to fit in the client app window.

Planning to implement all commands on the remote control and the game controller, maybe even to execute a set of a batch of commands (as in Select all & Copy when in the File Manager), anyways we'll see how it goes.

Download from here. Let me know if you find it useful or if you have any suggestions.

Update Friday, 07 September 2012

Since writing the post, XBMC4Xbox split from the main XBMC project and the app continued to change, but I only tested it with XBMC4Xbox. Might just work with XBMC, the HTTP API shouldn’t be much different really.

Download from here.

Monday, June 4, 2007

Network Monitor

I used to have this problem where on my current Internet connection I have a daily download quota of 1 GB and every time I had to download something large, like say ISOs or legal torrents, I had to create a scheduler task to shutdown the computer after an estimated number of hours. That wasn't too great because it was either downloading too little or too much, so I decided to write this application (I called it "Network Monitor", but any other suggestions are welcome :-) and I thought I might share it with you.

Although I tested the application in the last couple of weeks, the new version 0.5 is almost a complete rewrite as I cleaned up the UI (for public release :-), added the shutdown option and the time limit. It's my first try at .Net C# and SharpDevelop, so obviously you will need the 2.0 .Net Framework installed to be able to run the application.

Just download the archive [see below], and extract it anywhere. The application needs write permissions in that folder to create a log file. It also needs registry permissions in the HKEY_CURRENT_USER to create a few registry keys to keep the settings, to be able to remember them for the next time you start the application.

One last note, obviously this is a tool to be used by those leaving their computers overnight to download, don't use it while you are working away as it will just turn off your computer without an actual notice.

Please feel free to report bugs and even enhancement requests and I'll try to put them in.

Network Monitor, 0.6 - 4 June 2007 [download]

- fix: using values over 2GB for download/upload limits was causing immediate hibernate/shutdown [I was using signed int(s) for MB to Bytes conversion, resulting in negative numbers];
- add: display download/upload speed in KB/s;



Future enhancements:
- display average upload / download when finished;
- shutdown/hibernate if the traffic in the last x minutes is below y MB, for when the Internet connection goes dead;
- (maybe) shutdown / hibernate if the speed in the last x minutes is below y KB/s, for when the Internet is very slow;