本文整理汇总了C#中Android.Graphics.Bitmap类的典型用法代码示例。如果您正苦于以下问题:C# Bitmap类的具体用法?C# Bitmap怎么用?C# Bitmap使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
Bitmap类属于Android.Graphics命名空间,在下文中一共展示了Bitmap类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: 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;
}
示例2: SaveFromMemory
private static void SaveFromMemory(PixelBuffer[] pixelBuffers, int count, ImageDescription description, Stream imageStream, Bitmap.CompressFormat imageFormat)
{
var colors = pixelBuffers[0].GetPixels<int>();
using (var bitmap = Bitmap.CreateBitmap(description.Width, description.Height, Bitmap.Config.Argb8888))
{
var pixelData = bitmap.LockPixels();
var sizeToCopy = colors.Length * sizeof(int);
unsafe
{
fixed (int* pSrc = colors)
{
// Copy the memory
if (description.Format == PixelFormat.R8G8B8A8_UNorm || description.Format == PixelFormat.R8G8B8A8_UNorm_SRgb)
{
CopyMemoryBGRA(pixelData, (IntPtr)pSrc, sizeToCopy);
}
else if (description.Format == PixelFormat.B8G8R8A8_UNorm || description.Format == PixelFormat.B8G8R8A8_UNorm_SRgb)
{
Utilities.CopyMemory(pixelData, (IntPtr)pSrc, sizeToCopy);
}
else
{
throw new NotSupportedException(string.Format("Pixel format [{0}] is not supported", description.Format));
}
}
}
bitmap.UnlockPixels();
bitmap.Compress(imageFormat, 100, imageStream);
}
}
示例3: ToRounded
public static Bitmap ToRounded(Bitmap source, float rad, double cropWidthRatio, double cropHeightRatio, double borderSize, string borderHexColor)
{
double sourceWidth = source.Width;
double sourceHeight = source.Height;
double desiredWidth = sourceWidth;
double desiredHeight = sourceHeight;
double desiredRatio = cropWidthRatio / cropHeightRatio;
double currentRatio = sourceWidth / sourceHeight;
if (currentRatio > desiredRatio)
desiredWidth = (cropWidthRatio * sourceHeight / cropHeightRatio);
else if (currentRatio < desiredRatio)
desiredHeight = (cropHeightRatio * sourceWidth / cropWidthRatio);
float cropX = (float)((sourceWidth - desiredWidth) / 2d);
float cropY = (float)((sourceHeight - desiredHeight) / 2d);
if (rad == 0)
rad = (float)(Math.Min(desiredWidth, desiredHeight) / 2d);
else
rad = (float)(rad * (desiredWidth + desiredHeight) / 2d / 500d);
Bitmap bitmap = Bitmap.CreateBitmap((int)desiredWidth, (int)desiredHeight, Bitmap.Config.Argb8888);
using (Canvas canvas = new Canvas(bitmap))
using (Paint paint = new Paint())
using (BitmapShader shader = new BitmapShader(source, Shader.TileMode.Clamp, Shader.TileMode.Clamp))
using (Matrix matrix = new Matrix())
{
if (cropX != 0 || cropY != 0)
{
matrix.SetTranslate(-cropX, -cropY);
shader.SetLocalMatrix(matrix);
}
paint.SetShader(shader);
paint.AntiAlias = true;
RectF rectF = new RectF(0f, 0f, (float)desiredWidth, (float)desiredHeight);
canvas.DrawRoundRect(rectF, rad, rad, paint);
if (borderSize > 0d)
{
borderSize = (borderSize * (desiredWidth + desiredHeight) / 2d / 500d);
paint.Color = borderHexColor.ToColor(); ;
paint.SetStyle(Paint.Style.Stroke);
paint.StrokeWidth = (float)borderSize;
paint.SetShader(null);
RectF borderRectF = new RectF((float)(0d + borderSize/2d), (float)(0d + borderSize/2d),
(float)(desiredWidth - borderSize/2d), (float)(desiredHeight - borderSize/2d));
canvas.DrawRoundRect(borderRectF, rad, rad, paint);
}
return bitmap;
}
}
示例4: AchievementElement
public AchievementElement(string caption = null, string description = null, int percentageComplete = 0, Bitmap achievementImage = null)
: base(caption, "dialog_achievements")
{
Description = description;
PercentageComplete = percentageComplete;
AchievementImage = achievementImage;
}
示例5: decodeByteArray
public static Bitmap decodeByteArray(byte[] buffer, int offset, int length)
{
JNIFind();
if (_jcBitmapFactory == IntPtr.Zero)
{
Debug.LogError("_jcBitmapFactory is not initialized");
return null;
}
if (_jmDecodeByteArray == IntPtr.Zero)
{
Debug.LogError("_jmDecodeByteArray is not initialized");
return null;
}
IntPtr arg1 = AndroidJNI.ToByteArray(buffer);
IntPtr retVal = AndroidJNI.CallStaticObjectMethod(_jcBitmapFactory, _jmDecodeByteArray, new jvalue[] { new jvalue() { l = arg1 }, new jvalue() { i = offset }, new jvalue() { i = length } });
AndroidJNI.DeleteLocalRef(arg1);
if (retVal == IntPtr.Zero)
{
Debug.LogError("decodeByteArray returned null bitmap");
return null;
}
IntPtr globalRef = AndroidJNI.NewGlobalRef(retVal);
AndroidJNI.DeleteLocalRef(retVal);
Bitmap result = new Bitmap(globalRef);
return result;
}
示例6: CreateTask
/// <exception cref="Couchbase.Lite.CouchbaseLiteException"></exception>
public static Couchbase.Lite.Document CreateTask(Database database, string title,
Bitmap image, string listId)
{
SimpleDateFormat dateFormatter = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'"
);
Calendar calendar = GregorianCalendar.GetInstance();
string currentTimeString = dateFormatter.Format(calendar.GetTime());
IDictionary<string, object> properties = new Dictionary<string, object>();
properties.Put("type", DocType);
properties.Put("title", title);
properties.Put("checked", false);
properties.Put("created_at", currentTimeString);
properties.Put("list_id", listId);
Couchbase.Lite.Document document = database.CreateDocument();
UnsavedRevision revision = document.CreateRevision();
revision.SetUserProperties(properties);
if (image != null)
{
ByteArrayOutputStream @out = new ByteArrayOutputStream();
image.Compress(Bitmap.CompressFormat.Jpeg, 50, @out);
ByteArrayInputStream @in = new ByteArrayInputStream(@out.ToByteArray());
revision.SetAttachment("image", "image/jpg", @in);
}
revision.Save();
return document;
}
示例7: BitmapToByteArray
public static byte[] BitmapToByteArray(Bitmap bitmap)
{
ByteBuffer byteBuffer = ByteBuffer.Allocate(bitmap.ByteCount);
bitmap.CopyPixelsToBuffer(byteBuffer);
byte[] bytes = byteBuffer.ToArray<byte>();
return bytes;
}
示例8: LoadFromResource
public void LoadFromResource(string assemblyName,MvxResourcePath resourcePath)
{
var resourceName = resourcePath.GetResourcePath (".",true);
var strm = Assembly.Load (new AssemblyName(assemblyName)).GetManifestResourceStream(resourceName);
bitmap = BitmapFactory.DecodeStream (strm);
}
示例9: putBitmap
public void putBitmap (string key, Bitmap bitmap)
{
Put (key, bitmap);
// An entry has been added, so invalidate the snapshot
mLastSnapshot = null;
}
示例10: DrawBackground
void DrawBackground()
{
if (background != null) {
background.Dispose ();
}
background = Bitmap.CreateBitmap(screen_size.Width, screen_size.Height, Bitmap.Config.Argb8888);
Canvas c = new Canvas (background);
//Paint black = new Paint();
//black.SetARGB(255, 0, 0, 0);
//black.SetStyle (Paint.Style.Stroke);
//Bitmap plaatje = blokken[2].DrawBlok (MainActivity.context);
//DrawBitmap werkt niet voor scaling bitmaps in xamarin
//c.DrawBitmap (plaatje, new Rect (0, 0, plaatje.Width, plaatje.Height), new RectF (blokken[2].X, blokken[2].Y, blokken[2].Width, blokken[2].Height), null);
//c.DrawBitmap(plaatje,96,0,null);
foreach (Blok b in blokken)
{
Bitmap plaatje = b.DrawBlok (MainActivity.context);
c.DrawBitmap (plaatje, b.X, b.Y, null);
plaatje.Dispose ();
}
c.Dispose ();
//black.Dispose ();
}
示例11: OnCreate
protected override void OnCreate(Bundle bundle)
{
//SetTheme(Resource.Style.Theme_Sherlock_Light);
SetTheme(Resource.Style.Theme_Example);
base.OnCreate(bundle);
RequestWindowFeature(WindowFeatures.IndeterminateProgress);
SetSupportProgressBarIndeterminateVisibility(false);
Sherlock.ActionBar.SetDisplayHomeAsUpEnabled(true);
SetContentView(Resource.Layout.Main);
// Show tabs
ActionBar.NavigationMode = ActionBarNavigationMode.Tabs;
// attach adapter to the viewpager
_pageAdapter = new ArtistPagerAdapter(SupportFragmentManager);
_viewPager = FindViewById<ViewPager>(Resource.Id.myViewPager);
_viewPager.Adapter = _pageAdapter;
_viewPager.SetOnPageChangeListener(this);
// startindex
_viewPager.SetCurrentItem(0, true);
var jsonArtist = Intent.GetStringExtra("Artist");
_artist = JsonConvert.DeserializeObject<Artist>(jsonArtist);
var jsonTopTracks = Intent.GetStringExtra("TopTracks");
_topTracks = JsonConvert.DeserializeObject<TopTracks>(jsonTopTracks);
var jsonTopAlbums = Intent.GetStringExtra("TopAlbums");
_topAlbums = JsonConvert.DeserializeObject<TopAlbums>(jsonTopAlbums);
_bitmapExtension = new BitmapExtension();
try
{
_imageBitmap = _bitmapExtension.GetImageBitmapFromUrl(_artist.GetImageUrlOfSize("large"));
}
catch (Exception ex)
{
Toast.MakeText(this, "Error: " + ex.Message, ToastLength.Short).Show();
}
//TABS
var tab1 = Sherlock.ActionBar.NewTab();
tab1.SetText("Artist");
tab1.SetTabListener(this);
var tab2 = Sherlock.ActionBar.NewTab();
tab2.SetText("Similar Artists");
tab2.SetTabListener(this);
var tab3 = Sherlock.ActionBar.NewTab();
tab3.SetText("Top 15 Tracks");
tab3.SetTabListener(this);
var tab4 = Sherlock.ActionBar.NewTab();
tab4.SetText("Top 5 Albums");
tab4.SetTabListener(this);
Sherlock.ActionBar.AddTab(tab1);
Sherlock.ActionBar.AddTab(tab2);
Sherlock.ActionBar.AddTab(tab3);
Sherlock.ActionBar.AddTab(tab4);
}
示例12: OnTouchEvent
public override bool OnTouchEvent(MotionEvent e)
{
_Paint = new Paint ();
_Paint.Color = new Android.Graphics.Color (255, 0, 0);
_Paint.StrokeWidth = 20;
_Paint.StrokeCap = Paint.Cap.Round;
var imageView = FindViewById<ImageView> (Resource.Id.myImageView);
Bitmap immutableBitmap = MediaStore.Images.Media.GetBitmap(this.ContentResolver, imageUri);
_Bmp = immutableBitmap.Copy(Bitmap.Config.Argb8888, true);
_Canvas = new Canvas(_Bmp);
imageView.SetImageBitmap (_Bmp);
switch (e.Action)
{
default:
{
_StartPt.X=e.RawX;
_StartPt.Y=e.RawY;
Console.WriteLine ("inside default:{0}","default");
DrawPoint (_Canvas);
break;
}
}
return true;
}
示例13: Transform
protected override Bitmap Transform(IBitmapPool bitmapPool, Bitmap source, int outWidth, int outHeight)
{
int size = Math.Min(source.Width, source.Height);
int width = (source.Width - size) / 2;
int height = (source.Height - size) / 2;
Bitmap squaredBitmap = Bitmap.CreateBitmap(source, width, height, size, size);
if (squaredBitmap != source)
{
source.Recycle();
}
Bitmap bitmap = Bitmap.CreateBitmap(size, size, Bitmap.Config.Argb8888);
Canvas canvas = new Canvas(bitmap);
Paint paint = new Paint();
BitmapShader shader = new BitmapShader(squaredBitmap, BitmapShader.TileMode.Clamp,
BitmapShader.TileMode.Clamp);
paint.SetShader(shader);
paint.AntiAlias = true;
float r = size / 2f;
canvas.DrawCircle(r, r, r, paint);
squaredBitmap.Recycle();
return BitmapResource.Obtain(bitmap, bitmapPool).Get();
}
示例14: getRoundedCroppedBitmap
public static Bitmap getRoundedCroppedBitmap(Bitmap bitmap, int radius) {
Bitmap finalBitmap;
if (bitmap.Width != radius || bitmap.Height!= radius)
finalBitmap = Bitmap.CreateScaledBitmap(bitmap, radius, radius,
false);
else
finalBitmap = bitmap;
Bitmap output = Bitmap.CreateBitmap(finalBitmap.Width,
finalBitmap.Height, Bitmap.Config.Argb8888);
Canvas canvas = new Canvas(output);
Paint paint = new Paint();
Rect rect = new Rect(0, 0, finalBitmap.Width,
finalBitmap.Height);
paint.AntiAlias=true;
paint.FilterBitmap=true;
paint.Dither=true;
canvas.DrawARGB(0, 0, 0, 0);
paint.Color=Color.ParseColor("#BAB399");
canvas.DrawCircle(finalBitmap.Width / 2 + 0.7f,
finalBitmap.Height / 2 + 0.7f,
finalBitmap.Width / 2 + 0.1f, paint);
paint.SetXfermode(new PorterDuffXfermode(PorterDuff.Mode.SrcIn));
canvas.DrawBitmap(finalBitmap, rect, rect, paint);
return output;
}
示例15: OnFrameAvailable
public Bitmap OnFrameAvailable(Bitmap bitmap)
{
if (shouldBlur)
return blur.BlurImage(bitmap);
return bitmap;
}