Esempio n. 1
0
        public void Draw(DrawArgs drawArg)
        {
            using (Surface doubleBuffer = GetDoubleBuffer(drawArg.ClipRectangle.Size))
            {
                using (var renderArgs = new RenderArgs(doubleBuffer))
                {
                    OnPainting(drawArg);

                    // Draw to buffer, use multiple thread, but will wait all thread completed and return.
                    DrawArea(renderArgs, drawArg.ClipRectangle.Location);

                    OnPainted(drawArg);

                    IntPtr bmpPtr;
                    Point  childOffset;
                    Size   parentSize;
                    doubleBuffer.GetDrawBitmapInfo(out bmpPtr, out childOffset, out parentSize);


                    //                    var img = new Bitmap(1024, 691, 32, PixelFormat.Format32bppArgb, bmpPtr);
                    //                    drawArg.Graphics.DrawImage(img, 0, 0);
                    // Draw to screen
                    PtnGraphics.DrawBitmap(drawArg.Graphics, drawArg.ClipRectangle, drawArg.Graphics.Transform,
                                           bmpPtr, childOffset.X, childOffset.Y);
                }
            }
        }
Esempio n. 2
0
        private void ReconstructExifInfoCache()
        {
            OnChanging();
            ++suppressChangeEvents;

            _exifIdToExifInfo.Clear();

            string[] exifKeys = GetKeys(ExifSectionName);
            string[] piBlobs  = new string[exifKeys.Length];

            for (int i = 0; i < exifKeys.Length; ++i)
            {
                piBlobs[i] = GetValue(ExifSectionName, exifKeys[i]);
                this.RemoveValue(ExifSectionName, exifKeys[i]);
            }

            foreach (string piBlob in piBlobs)
            {
                PropertyItem pi = PtnGraphics.DeserializePropertyItem(piBlob);
                AddExifValues(new PropertyItem[] { pi });
            }

            --suppressChangeEvents;
            OnChanged();
        }
Esempio n. 3
0
        public static Rectangle[] GetUpdateRegion(Control control)
        {
            SafeNativeMethods.GetUpdateRgn(control.Handle, UserInterface.HRgn, false);
            Rectangle[] scans;
            int         area;

            PtnGraphics.GetRegionScans(UserInterface.HRgn, out scans, out area);
            GC.KeepAlive(control);
            return(scans);
        }
Esempio n. 4
0
        public static PropertyItem CreatePropertyItem(short id, ExifTagType type, byte[] data)
        {
            PropertyItem pi = PtnGraphics.CreatePropertyItem();

            pi.Id    = id;
            pi.Type  = (short)type;
            pi.Len   = data.Length;
            pi.Value = (byte[])data.Clone();

            return(pi);
        }
Esempio n. 5
0
        protected override void OnPaint(PaintEventArgs e)
        {
            if (this._surface != null)
            {
                GeometryRegion clipRegion = null;
                Rectangle[]    rects      = this._realUpdateRects;

                if (rects == null)
                {
                    clipRegion = new GeometryRegion(e.Graphics.Clip, true);
                    clipRegion.Intersect(e.ClipRectangle);
                    rects = clipRegion.GetRegionScansReadOnlyInt();
                }

                if (this._justPaintWhite > 0)
                {
                    PtnGraphics.FillRectangles(e.Graphics, Color.White, rects);
                }
                else
                {
                    foreach (Rectangle rect in rects)
                    {
                        if (e.Graphics.IsVisible(rect))
                        {
                            var drawArg = new DrawArgs(e.Graphics, rect);
                            Draw(drawArg);
                        }
                    }
                }

                if (clipRegion != null)
                {
                    clipRegion.Dispose();
                }
            }

            if (this._justPaintWhite > 0)
            {
                --this._justPaintWhite;
            }

            base.OnPaint(e);
        }
Esempio n. 6
0
        public static void LoadProperties(Image dstImage, Document srcDoc)
        {
            var asBitmap = dstImage as Bitmap;

            if (asBitmap != null)
            {
                float dpiX;
                float dpiY;

                switch (srcDoc.DpuUnit)
                {
                case MeasurementUnit.Centimeter:
                    dpiX = (float)Document.DotsPerCmToDotsPerInch(srcDoc.DpuX);
                    dpiY = (float)Document.DotsPerCmToDotsPerInch(srcDoc.DpuY);
                    break;

                case MeasurementUnit.Inch:
                    dpiX = (float)srcDoc.DpuX;
                    dpiY = (float)srcDoc.DpuY;
                    break;

                default:
                    dpiX = 1.0f;
                    dpiY = 1.0f;
                    break;
                }

                asBitmap.SetResolution(dpiX, dpiY);
            }

            DocumentMetadata metaData = srcDoc.Metadata;

            foreach (string key in metaData.GetKeys(DocumentMetadata.ExifSectionName))
            {
                string       blob = metaData.GetValue(DocumentMetadata.ExifSectionName, key);
                PropertyItem pi   = PtnGraphics.DeserializePropertyItem(blob);

                dstImage.SetPropertyItem(pi);
            }
        }
Esempio n. 7
0
        public void AddExifValues(PropertyItem[] items)
        {
            if (items.Length == 0)
            {
                return;
            }

            short id = unchecked ((short)items[0].Id);

            for (int i = 1; i < items.Length; ++i)
            {
                if (unchecked ((short)items[i].Id) != id)
                {
                    throw new ArgumentException("all PropertyItem instances in items must have the same id");
                }
            }

            string[] names = new string[items.Length];

            OnChanging();
            ++suppressChangeEvents;

            for (int i = 0; i < items.Length; ++i)
            {
                names[i] = GetUniqueExifName();
                string blob = PtnGraphics.SerializePropertyItem(items[i]);
                SetValueConcrete(ExifSectionName, names[i], blob);
            }

            object   idObj = (object)id; // avoid boxing twice
            ExifInfo info  = (ExifInfo)this._exifIdToExifInfo[idObj];

            if (info == null)
            {
                PropertyItem[] newItems = new PropertyItem[items.Length];

                for (int i = 0; i < newItems.Length; ++i)
                {
                    newItems[i] = PtnGraphics.ClonePropertyItem(items[i]);
                }

                info = new ExifInfo(names, newItems);
            }
            else
            {
                string[]       names2 = new string[info.names.Length + names.Length];
                PropertyItem[] items2 = new PropertyItem[info.items.Length + items.Length];

                info.names.CopyTo(names2, 0);
                names.CopyTo(names2, info.names.Length);

                info.items.CopyTo(items2, 0);

                for (int i = 0; i < items.Length; ++i)
                {
                    items2[i + info.items.Length] = PtnGraphics.ClonePropertyItem(items[i]);
                }

                info = new ExifInfo(names2, items2);
            }

            this._exifIdToExifInfo[idObj] = info;

            --suppressChangeEvents;
            OnChanged();
        }