本文整理汇总了C#中Android.Graphics.BitmapFactory.Options类的典型用法代码示例。如果您正苦于以下问题:C# BitmapFactory.Options类的具体用法?C# BitmapFactory.Options怎么用?C# BitmapFactory.Options使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
BitmapFactory.Options类属于Android.Graphics命名空间,在下文中一共展示了BitmapFactory.Options类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: DecodeBitmap
public static Bitmap DecodeBitmap(string path, int desiredSize)
{
var options = new BitmapFactory.Options { InJustDecodeBounds = true };
BitmapFactory.DecodeFile(path, options);
options = new BitmapFactory.Options { InSampleSize = desiredSize };
return BitmapFactory.DecodeFile(path, options);
}
示例2: DecodeSampleBitmapFromFile
public static Bitmap DecodeSampleBitmapFromFile(string path, int reqWidth, int reqHeight)
{
try
{
//______________________________________________________________
// First decode with inJustDecodeBounds=true to check dimensions
BitmapFactory.Options options = new BitmapFactory.Options();
options.InJustDecodeBounds = true;
BitmapFactory.DecodeFile(path, options);
//BitmapFactory.DecodeStream(url.OpenConnection().InputStream, null, options);
//______________________
// Calculate inSampleSize
options.InSampleSize = CalculateInSampleSize(options, reqWidth, reqHeight);
//____________________________________
// Decode bitmap with inSampleSize set
options.InJustDecodeBounds = false;
return BitmapFactory.DecodeFile(path, options);
}
catch (System.Exception ex)
{
Log.Debug("DecodeBitmapFromFile: ", ex.Message);
return null;
}
finally
{
//
}
}
示例3: OnElementPropertyChanged
protected override void OnElementPropertyChanged(object sender, PropertyChangedEventArgs e)
{
base.OnElementPropertyChanged(sender, e);
var largeImage = (CustomImage)Element;
if ((Element.Width > 0 && Element.Height > 0 && !isDecoded) || (e.PropertyName == "ImageSource" && largeImage.ImageSource != null))
{
BitmapFactory.Options options = new BitmapFactory.Options();
options.InJustDecodeBounds = true;
//Get the resource id for the image
if (largeImage.ImageSource != null)
{
var field = typeof(Resource.Drawable).GetField(largeImage.ImageSource.Split('.').First());
var value = (int)field.GetRawConstantValue();
BitmapFactory.DecodeResource(Context.Resources, value, options);
var width = (int)Element.Width;
var height = (int)Element.Height;
options.InSampleSize = CalculateInSampleSize(options, width, height);
options.InJustDecodeBounds = false;
var bitmap = BitmapFactory.DecodeResource(Context.Resources, value, options);
Control.SetImageBitmap(bitmap);
isDecoded = true;
}
}
}
示例4: SimulationView
public SimulationView (Context context, SensorManager sensorManager, IWindowManager window)
: base (context)
{
Bounds = new PointF ();
// Get an accelorometer sensor
sensor_manager = sensorManager;
accel_sensor = sensor_manager.GetDefaultSensor (SensorType.Accelerometer);
// Calculate screen size and dpi
var metrics = new DisplayMetrics ();
window.DefaultDisplay.GetMetrics (metrics);
meters_to_pixels_x = metrics.Xdpi / 0.0254f;
meters_to_pixels_y = metrics.Ydpi / 0.0254f;
// Rescale the ball so it's about 0.5 cm on screen
var ball = BitmapFactory.DecodeResource (Resources, Resource.Drawable.Ball);
var dest_w = (int)(BALL_DIAMETER * meters_to_pixels_x + 0.5f);
var dest_h = (int)(BALL_DIAMETER * meters_to_pixels_y + 0.5f);
ball_bitmap = Bitmap.CreateScaledBitmap (ball, dest_w, dest_h, true);
// Load the wood background texture
var opts = new BitmapFactory.Options ();
opts.InDither = true;
opts.InPreferredConfig = Bitmap.Config.Rgb565;
wood_bitmap = BitmapFactory.DecodeResource (Resources, Resource.Drawable.Wood, opts);
wood_bitmap2 = BitmapFactory.DecodeResource (Resources, Resource.Drawable.Wood, opts);
display = window.DefaultDisplay;
particles = new ParticleSystem (this);
}
示例5: GetResizedBitmapAsync
public async Task<Bitmap> GetResizedBitmapAsync(string path, int width, int height)
{
if (_originalBitmap != null)
{
return _originalBitmap;
}
#region Get some some information about the bitmap so we can resize it
BitmapFactory.Options options = new BitmapFactory.Options
{
InJustDecodeBounds = true
};
using (Stream stream = _context.Assets.Open(path))
{
await BitmapFactory.DecodeStreamAsync(stream);
}
await BitmapFactory.DecodeFileAsync(path, options);
#endregion
// Calculate the factor by which we should reduce the image by
options.InSampleSize = CalculateInSampleSize(options, width, height);
#region Go and load the image and resize it at the same time.
options.InJustDecodeBounds = false;
using (Stream inputSteam = _context.Assets.Open(path))
{
_originalBitmap = await BitmapFactory.DecodeStreamAsync(inputSteam);
}
#endregion
return _originalBitmap;
}
示例6: GetScaledDrawable
// Get a bitmap drawable from a local file that is scaled down
// to fit the current window size
public static BitmapDrawable GetScaledDrawable(Activity a, string path)
{
Display display = a.WindowManager.DefaultDisplay;
float destWidth = display.Width;
float destHeight = display.Height;
// Read in the dimensions of the image on disk
BitmapFactory.Options options = new BitmapFactory.Options();
options.InJustDecodeBounds = true;
BitmapFactory.DecodeFile(path, options);
float srcWidth = options.OutWidth;
float srcHeight = options.OutHeight;
double inSampleSize = 1.0;
if (srcHeight > destHeight || srcWidth > destWidth) {
if (srcWidth > srcHeight) {
inSampleSize = Math.Round(srcHeight / destHeight);
}
else {
inSampleSize = Math.Round(srcWidth / destWidth);
}
}
options = new BitmapFactory.Options();
options.InSampleSize = (int)inSampleSize;
Bitmap bitmap = BitmapFactory.DecodeFile(path, options);
var bDrawable= new BitmapDrawable(a.Resources, bitmap);
bitmap = null;
return bDrawable;
}
示例7: Scale
public static Bitmap Scale (int scaleFactor, Stream iStream)
{
var bmOptions = new BitmapFactory.Options ();
bmOptions.InJustDecodeBounds = false;
bmOptions.InSampleSize = scaleFactor;
return BitmapFactory.DecodeStream (iStream, null, bmOptions);
}
示例8: OnElementPropertyChanged
protected override void OnElementPropertyChanged(object sender, PropertyChangedEventArgs e)
{
base.OnElementPropertyChanged(sender, e);
var largeImage = (XLargeImage.SourceCode.Controls.XLargeImage)Element;
if ((!(Element.Width > 0) || !(Element.Height > 0) || _isDecoded) &&
(e.PropertyName != "ImageSource" || largeImage.ImageSource == null)) return;
var options = new BitmapFactory.Options {InJustDecodeBounds = true};
//Get the resource id for the image
var field = typeof(Resource.Drawable).GetField(largeImage.ImageSource.Split('.').First());
if(field == null) return;
var value = (int)field.GetRawConstantValue();
BitmapFactory.DecodeResource(Context.Resources, value, options);
//The with and height of the elements (XLargeImage) will be used to decode the image
var width = (int)Element.Width;
var height = (int)Element.Height;
options.InSampleSize = CalculateInSampleSize(options, width, height);
options.InJustDecodeBounds = false;
var bitmap = BitmapFactory.DecodeResource(Context.Resources, value, options);
//Set the bitmap to the native control
Control.SetImageBitmap(bitmap);
_isDecoded = true;
}
示例9: SetValue
public override void SetValue(object value)
{
var imageView = ImageView;
if (imageView == null)
{
// weak reference is garbage collected - so just return
return;
}
try
{
var assetStream = GetStream(value);
if (assetStream == null)
return;
var options = new BitmapFactory.Options {InPurgeable = true};
var bitmap = BitmapFactory.DecodeStream(assetStream, null, options);
var drawable = new BitmapDrawable(Resources.System, bitmap);
imageView.SetImageDrawable(drawable);
}
catch (Exception ex)
{
MvxTrace.Error(ex.ToLongString());
throw;
}
}
示例10: LoadAndResizeBitmap
public static Bitmap LoadAndResizeBitmap(this string fileName, int width, int height)
{
// First we get the the dimensions of the file on disk
BitmapFactory.Options options = new BitmapFactory.Options { InJustDecodeBounds = true };
BitmapFactory.DecodeFile(fileName, options);
// Next we calculate the ratio that we need to resize the image by
// in order to fit the requested dimensions.
int outHeight = options.OutHeight;
int outWidth = options.OutWidth;
int inSampleSize = 1;
if (outHeight > height || outWidth > width)
{
inSampleSize = outWidth > outHeight
? outHeight / height
: outWidth / width;
}
// Now we will load the image and have BitmapFactory resize it for us.
options.InSampleSize = inSampleSize;
options.InJustDecodeBounds = false;
Bitmap resizedBitmap = BitmapFactory.DecodeFile(fileName, options);
return resizedBitmap;
}
示例11: GetImageSize
public static AccidentMediaViewModel GetImageSize(string fileName)
{
var options = new BitmapFactory.Options
{
InJustDecodeBounds = true
};
File file = new File(fileName);
long lengthMB = file.Length() / 1024;
BitmapFactory.DecodeFile(fileName, options);
int width = options.OutWidth;
int height = options.OutHeight;
string type = options.OutMimeType;
file.Dispose();
return new AccidentMediaViewModel
{
Height = height,
MimeType = type,
Filename = fileName,
SizeKb = lengthMB,
Width = width
};
}
示例12: DecodeSampledBitmapFromResource
public static Bitmap DecodeSampledBitmapFromResource(Resources res, int resId, int reqWidth, int reqHeight)
{
BitmapFactory.Options options = new BitmapFactory.Options { InJustDecodeBounds = true };
BitmapFactory.DecodeResource(res, resId, options);
options.InSampleSize = CalculateInSampleSize(options, reqWidth, reqHeight);
options.InJustDecodeBounds = false;
return BitmapFactory.DecodeResource(res, resId, options);
}
示例13: DragObject
private Bitmap img; // The object bitmap
#endregion Fields
#region Constructors
public DragObject(Resources res, int drawableIntID)
{
BitmapFactory.Options options = new BitmapFactory.Options();
options.InJustDecodeBounds = true;
img = BitmapFactory.DecodeResource(res, drawableIntID);
id = count;
count++;
}
示例14: DecodeFromByteArray
public static Bitmap DecodeFromByteArray(byte[] bytes, int reqWidth, int reqHeight)
{
BitmapFactory.Options options = new BitmapFactory.Options { InJustDecodeBounds = true };
BitmapFactory.DecodeByteArray(bytes, 0, bytes.Length, options);
options.InSampleSize = CalculateInSampleSize(options, reqWidth, reqHeight);
options.InJustDecodeBounds = false;
return BitmapFactory.DecodeByteArray(bytes, 0, bytes.Length, options);
}
示例15: ToSampleSize
/// <summary>
/// Helper method to get the sample size of the image for resampling.
/// </summary>
public static int ToSampleSize (this byte [] bytes)
{
var sampleSize = 0;
BitmapFactory.Options options = new BitmapFactory.Options ();
options.InJustDecodeBounds = true;
BitmapFactory.DecodeByteArray (bytes, 0, bytes.Length, options);
sampleSize = (int)Math.Ceiling ((double)Math.Max (options.OutWidth / Constants.MaxWidth, options.OutHeight / Constants.MaxHeight));
return sampleSize;
}