コード例 #1
0
ファイル: bitmapimage.cpp プロジェクト: lewing/moon
void
BitmapImage::OnPropertyChanged (PropertyChangedEventArgs *args, MoonError *error)
{
	if (args->GetProperty ()->GetOwnerType () != Type::BITMAPIMAGE) {
		BitmapSource::OnPropertyChanged (args, error);
		return;
	}

	if (args->GetId () == BitmapImage::UriSourceProperty) {
		Uri *uri = args->GetNewValue () ? args->GetNewValue ()->AsUri () : NULL;

		Abort ();

		if (Uri::IsNullOrEmpty (uri)) {
			SetBitmapData (NULL, false);
		} else if (uri->IsInvalidPath ()) {
			if (IsBeingParsed ())
				MoonError::FillIn (error, MoonError::ARGUMENT_OUT_OF_RANGE, 0, "invalid path found in uri");
			SetBitmapData (NULL, false);
		} else {
			AddTickCall (uri_source_changed_callback);
		}
	} else if (args->GetId () == BitmapImage::ProgressProperty) {
		if (HasHandlers (DownloadProgressEvent))
			Emit (DownloadProgressEvent, new DownloadProgressEventArgs (GetProgress ()));
	}

	NotifyListenersOfPropertyChange (args, error);
}
コード例 #2
0
ファイル: bitmapimage.cpp プロジェクト: lewing/moon
void
BitmapImage::PixmapComplete ()
{
	MoonPixbuf *pixbuf;
	
	SetProgress (1.0);

	if (!loader) {
		if (!moon_error)
			moon_error = new MoonError (MoonError::EXCEPTION, 4001, "no loader");
		goto failed;
	}

	loader->Close (moon_error == NULL ? &moon_error : NULL);

	if (moon_error)
		goto failed;

	if (!(pixbuf = loader->GetPixbuf ())) {
		moon_error = new MoonError (MoonError::EXCEPTION, 4001, "failed to create image data");
		goto failed;
	}
	
	SetPixelWidth (pixbuf->GetWidth ());
	SetPixelHeight (pixbuf->GetHeight ());
	
	// PixelFormat has been dropped and only Pbgra32 is supported
	// http://blogs.msdn.com/silverlight_sdk/archive/2009/07/01/breaking-changes-document-errata-silverlight-3.aspx
	// not clear if '3' channel is still supported (converted to 4) in SL3
	if (pixbuf->GetNumChannels () == 4) {
		SetBitmapData (premultiply_rgba (pixbuf), true);
	} else {
		SetBitmapData (expand_rgb_to_argb (pixbuf), true);
	}
	
	Invalidate ();
	
	delete loader;
	loader = NULL;
	
	if (HasHandlers (ImageOpenedEvent))
		Emit (ImageOpenedEvent, new RoutedEventArgs ());
	
	return;
	
failed:
	ImageErrorEventArgs *args = NULL;

	if (HasHandlers (ImageFailedEvent))
		args = new ImageErrorEventArgs (*moon_error);
	CleanupLoader ();
	if (args)
		Emit (ImageFailedEvent, args);
}
コード例 #3
0
ファイル: bitmapimage.cpp プロジェクト: lewing/moon
void
BitmapImage::UriSourceChanged ()
{
	Surface *surface = Deployment::GetCurrent ()->GetSurface ();
	Application *app = Application::GetCurrent ();
	Uri *uri = GetUriSource ();
	
	if (surface == NULL) {
		SetBitmapData (NULL, false);
		return;
	}
	
	if (app && uri) {
		if (get_res_aborter)
			delete get_res_aborter;
		get_res_aborter = new Cancellable ();
		app->GetResource (GetResourceBase(), uri, resource_notify, pixbuf_write, policy,
				  HttpRequest::DisableFileStorage, get_res_aborter, this);
	}
}
コード例 #4
0
ファイル: writeablebitmap.cpp プロジェクト: 499940913/moon
gpointer
WriteableBitmap::InitializeFromBitmapSource (BitmapSource *source)
{
	cairo_t *cr;

	if (!source)
		return NULL;

	SetPixelHeight (source->GetPixelHeight ());
	SetPixelWidth (source->GetPixelWidth ());

	image_surface = cairo_image_surface_create (CAIRO_FORMAT_ARGB32, GetPixelWidth (), GetPixelHeight ());
	cr = cairo_create (image_surface);
	cairo_set_source_surface (cr, source->GetImageSurface (), 0, 0);
	cairo_paint (cr);
	cairo_destroy (cr);

	SetBitmapData (cairo_image_surface_get_data (image_surface), false);

	return GetBitmapData ();
}