utilization of bitmap protocol

I am curious about utilization calculation in the bitmap protocol. especially if there’s a difference between if only station 0 wants to broadcast(and the others doesn’t) or only some other station want to broadcast(but the others doesn’t)

an example of a problem regarding this: in a bit map protocol with 10 station(numbered 0-9). knowing that the contending time is t and the length of each broadcasting frame is 20t.

a)what is the utilization of the network if all of the stations want to transmit in every time slot?

b)what is the utilization of the network if only station 0 wants to broadcast and the others doesn’t?

c)what is the utilization of the network if only station 2 wants to broadcast and the other doesn’t?

this is what i tried

a)in the beginning of the contending time, 10 stations want to broadcast so: $ \frac{20*10p}{20*10p+1}$

b)$ \frac{20*10p(1-p)^9}{20*10p(1-p)^9+1}$

c)$ \frac{20*10p((1-p)^9)^3}{20*10p((1-p)^9)^3+1}$

explanation for b and c: only one station wants to broadcast, and in c there are 3 additional points in time we can not broadcast(0,1,2)

i tried looking on this site and on other sites for this topic, but with no luck sadly. there’s not much information regarding calculation of utilization of the bitmap protocol, especially single stations in the network.

DirectX vs winapi BitBlt – перформанс вывода Bitmap

Есть ли приемущества по скорости вывода/нагрузке на пооцессор при выводе Bitmap (HBITMAP) используя нечто отличное от winapi (BitBlt), например DirectX.

Bitmap’ы статичные, но могут часто меняться в определенном режиме, примерно 2-5 раз в секунду, зависит от внешних факторов. Усреднённые параметры изображений примерно 1200х800, 24bpp, размер 3-4Мб в не сжатом виде.

Интересуют практические наблюдения, если смысл связываться для увеличения скорости реендеринга?

Возможно оптимальней будет использовать что-то отличное от DirectX?

theoretical question about difference between transmitting stations in Bit-Map Protocol

i am wondering about the difference between the transmitting station in a bit map protocol.

for instance, if we have 8 broadcasting stations numbered 0-7, and the racing (contenting) time is $ t_0$ and the length of each broadcasting frame is $ 20t_0$

then, will there be a difference, if for instance, only station 0 wants to broadcast in each time slot and all of the other stations doesn’t want to broadcast at all(at any time slot), or the exact same thing if the only station that wants to broadcast in each time slot is station 2?

is there any difference except of the station number(both seem to be low numbers)?

curious about that

WPF Bitmap / BitmapFrame to multi-page / multi-frame TIFF with JPEG encoding

I was searching for a long time how to write multi-page TIFFs with the JPEG encoding. TIFFs support JPEG encoded frames but the built-in encoder in .NET Framework does not have JPEG as a compression option.

The code is based on the answer to this question: https://stackoverflow.com/questions/14811496/tiff-with-jpeg-compression-much-larger-than-original-jpeg but does not rely on the FreeImage library.

First up, a class to convert BitmapFrame or Bitmap to a JPEG image:

using System.Drawing; using System.Drawing.Imaging; using System.IO; using System.Windows.Media.Imaging;  namespace TIFF {     public class Jpeg     {         public byte[] Data;         public uint Width;         public uint Height;         public uint HorizontalResolution;         public uint VerticalResolution;          public Jpeg(byte[] data, uint width, uint height, uint horizontalResolution, uint verticalResolution)         {             this.Data = data;             this.Width = width;             this.Height = height;             this.HorizontalResolution = horizontalResolution;             this.VerticalResolution = verticalResolution;         }          public static Jpeg FromBitmapFrame(BitmapFrame bitmap, long quality)         {             Jpeg jpeg;              using (var stream = new MemoryStream())             {                 JpegBitmapEncoder encoder = new JpegBitmapEncoder();                 encoder.QualityLevel = 90;                 encoder.Frames.Add(bitmap);                 encoder.Save(stream);                  jpeg = new Jpeg(stream.ToArray(), (uint)bitmap.Width, (uint)bitmap.Height, (uint)bitmap.DpiX, (uint)bitmap.DpiY);             }              return jpeg;         }          public static Jpeg FromBitmap(Bitmap bitmap, long quality)         {             Jpeg jpeg;             using (var stream = new MemoryStream())             {                 ImageCodecInfo jpgEncoder = GetEncoder(ImageFormat.Jpeg);                 Encoder encoder = Encoder.Quality;                 EncoderParameters parameters = new EncoderParameters(1);                 parameters.Param[0] = new EncoderParameter(encoder, quality);                 bitmap.Save(stream, jpgEncoder, parameters);                  jpeg = new Jpeg(stream.ToArray(), (uint) bitmap.Width, (uint) bitmap.Height, (uint) bitmap.HorizontalResolution, (uint) bitmap.VerticalResolution);             }              return jpeg;         }          private static ImageCodecInfo GetEncoder(ImageFormat format)         {             ImageCodecInfo[] codecs = ImageCodecInfo.GetImageDecoders();             foreach (ImageCodecInfo codec in codecs)             {                 if (codec.FormatID == format.Guid)                 {                     return codec;                 }             }             return null;         }     } } 

Next, a class to create the TIFF image

using System; using System.Collections.Generic; using System.Drawing; using System.IO; using System.Windows.Media.Imaging;  namespace TIFF {     public static class JpegTiff     {         public static byte[] Create(List<BitmapFrame> frames, long quality)         {             List<Jpeg> jpegs = new List<Jpeg>();              foreach (var frame in frames)             {                 jpegs.Add(Jpeg.FromBitmapFrame(frame, quality));             }              return WrapJpegs(jpegs);         }              public static byte[] Create(List<Bitmap> bitmaps, string filename, long quality)         {             List<Jpeg> jpegs = new List<Jpeg>();              foreach (var bitmap in bitmaps)             {                 jpegs.Add(Jpeg.FromBitmap(bitmap, quality));             }              return WrapJpegs(jpegs);         }          private static byte[] WrapJpegs(List<Jpeg> jpegs)         {             if (jpegs == null || jpegs.Count == 0 || jpegs.FindIndex(b => b.Data.Length == 0) > -1)                 throw new ArgumentNullException("Image Data must not be null or empty");              MemoryStream tiffData = new MemoryStream();             BinaryWriter writer = new BinaryWriter(tiffData);             uint offset = 8; // size of header, offset to IFD             ushort entryCount = 14; // entries per IFD              #region IFH - Image file header              // magic number             if (BitConverter.IsLittleEndian)                 writer.Write(0x002A4949);             else                 writer.Write(0x4D4D002A);              // offset to (first) IFD             writer.Write(offset);              #endregion IFH              #region IFD Image file directory              // write image file directories for each jpeg             for (int i = 0; offset > 0; i++)             {                 var jpeg = jpegs[i];                 uint width = jpeg.Width;                 uint length = jpeg.Height;                 uint xres = jpeg.HorizontalResolution;                 uint yres = jpeg.VerticalResolution;                  // count of entries:                 writer.Write(entryCount);                  offset += 6 + 12 * (uint)entryCount; // add lengths of entries, entry-count and next-ifd-offset                  // TIFF-fields / IFD-entrys:                 // {TAG, TYPE (3 = short, 4 = long, 5 = rational), COUNT, VALUE/OFFSET}                 uint[,] fields = new uint[,] {                     {254, 4, 1, 0}, // NewSubfileType                     {256, 4, 1, width}, // ImageWidth                     {257, 4, 1, length}, // ImageLength                     {258, 3, 3, offset}, // BitsPerSample                     {259, 3, 1, 7}, // Compression (new JPEG)                     {262, 3, 1, 6}, //PhotometricInterpretation (YCbCr)                     {273, 4, 1, offset + 22}, // StripOffsets (offset IFH + entries + values of BitsPerSample & YResolution & XResolution)                     {277, 3, 1, 3}, // SamplesPerPixel                     {278, 4, 1, length}, // RowsPerStrip                     {279, 4, 1, (uint)jpegs[i].Data.LongLength}, // StripByteCounts                     {282, 5, 1, offset + 6}, // XResolution (offset IFH + entries + values of BitsPerSample)                     {283, 5, 1, offset + 14}, // YResolution (offset IFH + entries + values of BitsPerSample & YResolution)                     {284, 3, 1, 1}, // PlanarConfiguration (chunky)                     {296, 3, 1, 2} // ResolutionUnit                 };                  // write fields                 for (int f = 0; f < fields.GetLength(0); f++)                 {                     writer.Write((ushort)fields[f, 0]);                     writer.Write((ushort)fields[f, 1]);                     writer.Write(fields[f, 2]);                     writer.Write(fields[f, 3]);                 }                  // offset of next IFD                 if (i == jpegs.Count - 1)                     offset = 0;                 else                     offset += 22 + (uint)jpegs[i].Data.LongLength; // add values (of fields) length and jpeg length                 writer.Write(offset);                  #region values of fields                  // BitsPerSample                 writer.Write((ushort)8);                 writer.Write((ushort)8);                 writer.Write((ushort)8);                  // XResolution                 writer.Write(xres);                 writer.Write(1);                  // YResolution                 writer.Write(yres);                 writer.Write(1);                  #endregion values of fields                  // actual image Data                 writer.Write(jpegs[i].Data);             }             #endregion IFD              writer.Close();             return tiffData.ToArray();         }     } } 

It could probably be improved by passing in the stream to write to instead of returning a byte array.

¿Como obtener un bitmap de un ImageView cargado con Glide? Glide 4.9.0

Necesito obtener el bitmap de un ImageView para luego guardarlo de manera local mediante un FileOutputStream y luego retomarlo cuando desee. El problema viene cuando trato de obtener el bitmap de dicha imagen pero me arroja un NullPointerExcepcion:

java.lang.NullPointerException: Attempt to invoke virtual method ‘boolean android.graphics.Bitmap.compress(android.graphics.Bitmap$ CompressFormat, int, java.io.OutputStream)’ on a null object reference

Estoy utilizando la ultima actualización Glide 4.9.0.

Este es el código:

String url = getPreferences("URL");                 loadImagen(url);  private void loadImagen(String url) {     Glide.with(getApplicationContext()).load(url)             .into(ImagenPerfil);  }  ImagenPerfil.setDrawingCacheEnabled(true);                 ImagenPerfil.buildDrawingCache();                 Bitmap bitmap = ImagenPerfil.getDrawingCache();                 ByteArrayOutputStream baos = new ByteArrayOutputStream();                 bitmap.compress(Bitmap.CompressFormat.JPEG, 100, baos);                 final byte[] data = baos.toByteArray();                 try {                     FileOutputStream outputStream = getApplicationContext().openFileOutput("perfil.jpg", Context.MODE_PRIVATE);                     outputStream.write(data);                     outputStream.close();                 } catch (FileNotFoundException e) {                     e.printStackTrace();                 } catch (IOException e2) {                     e2.printStackTrace();                 } 

Antes me funcionaba por que obviamente le pasaba la imagen directamente obtenida de un Intent al escoger una de la galería del teléfono, pero ahora le estoy pasando una imagen a través de Glide con la URL de la imagen obtenida desde otra actividad y no se como hacerlo cuando es con una imagen cargada mediante una URL.

I want to overlay two bitmaps on a canvas and produce a single bitmap. But the second image is much smaller than its original size

I want to overlay two bitmaps on a canvas and produce a single bitmap in android. but second image is much small as its original size. But second image or small image is looking more small on canvas as compare to original bitmap image. I have implemented following code to overlay image and give the left and top align to second image.

public Bitmap overlay(Bitmap bmp1, final Bitmap bmp2, int x, int y) { final Bitmap bmOverlay = Bitmap.createBitmap(bmp1.getWidth(), bmp1.getHeight(), bmp1.getConfig()); Canvas canvas = new Canvas(bmOverlay); canvas.drawBitmap(bmp1, 0f, 0f, null); float density = PdfActivity.this.getResources().getDisplayMetrics().density; canvas.drawBitmap(bmp2, x * density, y * density, null); return bmOverlay;} 

In above code bmp2 is used to draw the second image or small image ,while bmp1 is big image draw on canvas. Please have a look at both screens:- Below is showing image after drawing on canvas.

enter image description here

Please help me to find out what is the issue so image is drawing in small format.

Below is showing original image inside the rectangle after drawing on image view.

enter image description here

Converter URI para Bitmap

Boa tarde,

Estou como uma duvida, como posso converter uma URI para Bitmap e em seguida converter para Base64 assim poder enviar ao Banco de Dados.

private void abrirCamera() {     fileUri = getOutputPictureUri("GRP");      if (fileUri != null) {          // Cria o intent para chamar a câmara         Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);         // seta o caminho do arquivo para guardar a foto         intent.putExtra(MediaStore.EXTRA_OUTPUT, fileUri);          // inicia a captura da foto         startActivityForResult(intent, CAM_REQUEST);     } }  @Override protected void onActivityResult(int requestCode, int resultCode, Intent data) {     if (requestCode == CAM_REQUEST) {         if (resultCode == RESULT_OK) {            Foto1.setImageURI(fileUri);             }         }     }